Repository navigation
Move Rails-compatible methods to lib/rails; date deprecations - #326
Merged
Merged
Conversation
Facets carries a number of methods borrowed from ActiveSupport that it doesn't endorse as its own. They now live in a separate lib/rails tree (lib/rails/facets/...), with their tests and demos under test/rails and demo/rails: hash/symbolize_keys, hash/stringify_keys, hash/to_options, hash/slice, array/extract_options, module/mattr, module/cattr, class/cattr, cattr, file/atomic_write, and the standard facets/date extensions. lib/rails is added to the gem's require_paths, so require paths are unchanged. The core loaders (facets/hash, facets/array, facets/essentials) still require the moved files, so `require 'facets'` loads the same methods as before. Also fixes hash/to_options, which only loaded symbolize_keys and never defined Hash#to_options or #to_options!. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW
Give every deprecated method a removal date, both in its @deprecated note and in its warning: Kernel#returning, Module#alias_method_chain, Array#uniq_by!, Enumerable#uniq_by, Kernel#silence_stream, and Facets' fallback Time#to_time (only defined when 'date' isn't loaded). Rails removed silence_stream in 5.0 because reopening STDOUT/STDERR isn't thread-safe. Its logic now lives in Kernel#silence, which silently, silence_stderr and silence_stdout call, so those keep working without a warning. silence_stream warns and delegates to silence. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW
Member
Author
|
CI status: all required jobs pass (Ruby 3.1–3.4, head, TruffleRuby). The only red check is the experimental Ruby jruby on ubuntu job, and it isn't caused by this PR.
Generated by Claude Code |
`require 'facets'` still provides the lib/rails methods (Hash#slice!, #symbolize_keys, #stringify_keys, #to_options, Array#extract_options!), but will stop after 2027-09-30. Instead of loading them outright, the core loaders now define stubs via Facets.rails_bridge. The first call warns and names the file to require, loads the real file (replacing the stub), and retries the call. Requiring the file directly skips the stub and the warning, and methods that are already defined, e.g. by ActiveSupport, are left alone. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First step of separating the methods Facets borrowed from ActiveSupport from the ones Facets endorses as its own. The per-file decisions came from a triage of all 40 Facets files that overlap with ActiveSupport 8.1.
1. New
lib/railstree (f9f1fa6)These files move to
lib/rails/facets/, with their tests and demos undertest/railsanddemo/rails:hash/symbolize_keys,hash/stringify_keys,hash/to_options,hash/slicearray/extract_optionsmodule/mattr,module/cattr,class/cattr,cattrfile/atomic_writedate(previously inlib/standard)lib/railsis added to the gem'srequire_paths, sorequire 'facets/hash/slice'and friends still work.Also in this commit:
lib/railsis added to.index,Indexfile,etc/test.rband the Rakefile, which gainstest:railsandqed:railstasks.MANIFESThas the moved paths relocated. It was already out of date before this PR andmastwasn't available to regenerate it, so only the moved entries were edited.hash/to_optionsonly loadedsymbolize_keysand never definedHash#to_options. It now aliasesto_optionsandto_options!as Rails does, and has a new test.2. Deprecations get a removal date (
aa011ae)Each of these now names 2027-09-30 in its
@deprecatednote and in its warning:Kernel#returningModule#alias_method_chainArray#uniq_by!Enumerable#uniq_byKernel#silence_streamTime#to_time, which is only defined whendateisn't loadedThe first four already warned; they only gain the date.
silence_stream: Rails removed it in 5.0 because reopening STDOUT/STDERR affects every thread in the process. Its logic now lives inKernel#silence, andsilently,silence_stderrandsilence_stdoutcallsilence, so they keep working without a warning.silence_streamwarns and then delegates tosilence. The docs forsilencenow say it affects the whole process.3. Warning for Rails methods loaded by
require 'facets'(65d5b5f)require 'facets'(andfacets/essentials) still providesHash#slice!,#symbolize_keys,#stringify_keys,#to_optionsandArray#extract_options!, but will stop after 2027-09-30. Instead of loading those files outright, the loaders now callFacets.rails_bridge, which defines a small stub for each method. The first call to a stub:require 'facets'runs, for example by ActiveSupport, it is left alone and not stubbed.require 'facets'defines is unchanged, apart from the newFacets.rails_bridgeand theto_optionsfix.Testing
rake test: 1,252 tests, all passing: the previous 1,248, 2 newto_optionstests and 2 newrails_bridgetests.rake qed: 153 demos with 8 failures and 2 errors. Those same failures were already there before these changes, so nothing new.silence,silently,silence_stderrandsilence_stream: the output is hidden inside the block and comes back afterwards, and onlysilence_streamwarns.mainbecauseURI.hash_to_querycomes out private on JRuby 10.1 (see the comment on Simplify block default passing in cattr and mattr #325).🤖 Generated with Claude Code
https://claude.ai/code/session_01E2Njj4j1r9twkVcXsMySLW