aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module
Commit message (Collapse)AuthorAgeFilesLines
* Use Thread.pass instead of Kernel.sleep to trigger race conditionGuilherme Mansur2019-08-051-7/+5
|
* Able to initalize default value for thread_mattr_*Guilherme Mansur2019-08-051-5/+11
| | | | | | | | | | | | | | | | | Added the ability to initialize `thread_mattr_*` methods with default values like so: ``` ruby class MyClass thread_attr_reader :foo, default: :foo thread_attr_writer :bar, default: :bar thread_attr_accessor: baz do "baz" end end ``` This is consistent with the api exposed by `mattr_accessor`.
* Omit marshal_dump & _dump from delegate_missing_toAaron Lipman2019-07-171-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Exclude missing marshal_dump and _dump methods from being delegated to an object's delegation target via the delegate_missing_to extension. This avoids unintentionally adding instance variables to an object during marshallization, should the delegation target be a method which would otherwise add them. In current versions of Ruby, a bug exists in the way objects are marshalled, allowing for instance variables to be added or removed during marshallization (see https://bugs.ruby-lang.org/issues/15968). This results in a corrupted serialized byte stream, causing an object's instance variables to "leak" into subsequent serialized objects during demarshallization. In Rails, this behavior may be triggered when marshalling an object that uses the delegate_missing_to extension, if the delegation target is a method which adds or removes instance variables to an object being marshalled - when calling Marshal.dump(object), Ruby's built in behavior will check whether the object responds to :marshal_dump or :_dump, which in turn triggers the delegation target method in the responds_to_missing? function defined in activesupport/lib/active_support/core_ext/module/delegation.rb While future versions of Ruby will resolve this bug by raising a RuntimeError, the underlying cause of this error may not be readily apparent when encountered by Rails developers. By excluding marshal_dump and _dump from being delegated to an object's target, this commit eliminates a potential cause of unexpected behavior and/or RuntimeErrors. Fixes #36522
* Indentation >>Akira Matsuda2019-06-221-6/+6
|
* Address 639d7be. Readd changelog line; remove needless explicit return.Kasper Timm Hansen2019-05-241-1/+1
|
* Add :allow_nil option to delegate_missing_to; use in ActiveStorageMatt Tanous2019-05-231-3/+8
| | | | attachment
* Improve error message of ActiveSupport delegateokuramasafumi2019-04-291-1/+1
| | | | | | | | | ActiveSupport `delegate` has `to` option, but it's not a option hash anymore and now it's a keyword argument. When `to` argument is not given, it raises an ArgumentError but the message suggests supplying "options hash", which is now wrong. Now it's fixed to provide correct suggestion to supply a keyword argument.
* Change wording of some instances of 'opt out' [ci skip]Sharang Dashputre2019-03-122-10/+10
|
* Remove deprecated `Module#reachable?` methodRafael Mendonça França2019-01-171-6/+1
|
* Clarify `delegate_missing_to` [ci skip]bogdanvlviv2019-01-041-1/+1
| | | | | | | | Since #34864 removed explicit receiver to clarify the purpose of `delegate_missing_to`, I think it will be better to do the same a few lines above to easier figure out that `delegate_missing_to` defines `method_missing`, `respond_to_missing?` when comparing these examples.
* Clarify benefit of `delegate_missing_to`Michael Gee2019-01-041-1/+1
| | | Removing the explicit receiver clarifies the purpose of `delegate_missing_to`.
* Clarify the :to parameter of delegateEddie Lebow2018-12-201-1/+1
|
* Consistently use kwargs for `instance_{reader,writer,accessor}` optionsRyuta Kamizono2018-10-201-12/+7
| | | | | | | | Since #29294, `mattr_acessor` uses kwargs for `instance_reader`, `instance_writer`, and `instance_accessor` options. `thread_mattr_accessor` and `config_accessor` also take the same options, so let's maintain these options handles the same.
* attribute_accessors no longer uses extract_options since ↵Akira Matsuda2018-10-201-2/+0
| | | | a5b0c60714e1e8d8c182af830a26e1c7c884271d
* Prefix Module#parent, Module#parents, and Module#parent_name with moduleGannon McGibbon2018-10-021-13/+37
|
* Fix example in thread_mattr_accessor documentationFabian Mersch2018-07-311-1/+1
|
* Remove unused `require "active_support/core_ext/regexp"`Ryuta Kamizono2018-07-293-3/+0
| | | | | | | | Ruby 2.4 has native `Regexp#match?`. https://ruby-doc.org/core-2.4.0/Regexp.html#method-i-match-3F Related #32034.
* Inclusive Language in Documentation Examples [ci skip]Cassidy Kobewka2018-04-151-2/+2
|
* [ci skip] Add :private option to delegation docYoshiyuki Hirano2018-04-051-1/+2
|
* [ci skip] Fix grammar in delegate, private: true docs.Kasper Timm Hansen2018-03-041-5/+4
| | | | | | | | | Convert the user to atheism by ditching the extra example that demonstrates the same thing as date_of_birth. Demonstrate the NoMethodError on date_of_birth first, then call age that uses date_of_birth internally. Thus showing that accessing it publicly fails, but using it internally succeeds.
* Add separate test to ensure that `delegate` with `:private` option returns ↵bogdanvlviv2018-02-281-5/+5
| | | | | | | | correct value Remove extra comments `# Asking for private method` in activesupport/test/core_ext/module_test.rb Improve docs of using `delegate` with `:private` Update changelog of #31944
* add private: true option for ActiveSupport delegateTomas Valent2018-02-261-2/+23
|
* Rails 6 requires Ruby 2.3+Jeremy Daer2018-02-171-17/+8
|
* Remove undefined `track_deletion` callback [ci skip]Ryuta Kamizono2018-01-031-3/+0
|
* Clarify docs for delegate :allow_nil optionJay Hayes2017-12-151-5/+2
|
* [ci skip] Make Todo classes inherit ApplicationRecordYoshiyuki Hirano2017-12-071-5/+5
| | | | | Example codes that use `has_many` or `before_create` in `Module::Concerning` look like active record models. So I've made them inherit `ApplicationRecord`.
* [Active Support] require_relative => requireAkira Matsuda2017-10-217-10/+10
| | | | This basically reverts 8da30ad6be34339124ba4cb4e36aea260dda12bc
* Deprecate `Module#reachable?` methodbogdanvlviv2017-09-171-0/+1
|
* Self-alias doesn't suppress the warning on Ruby 2.2Matthew Draper2017-09-011-8/+17
|
* Clarify intentions around method redefinitionsMatthew Draper2017-09-012-23/+43
| | | | | | | | | Don't use remove_method or remove_possible_method just before a new definition: at best the purpose is unclear, and at worst it creates a race condition. Instead, prefer redefine_method when practical, and silence_redefinition_of_method otherwise.
* Test for the new exception of delegate_missing_to (#30191)Anton Khamets2017-08-121-3/+9
| | | | | | | | | | | | | | | * Add test for the new exception of delegate_missing_to * Add a changelog entry * Only check for nil if NoMethodError was raised * Make method private * Have to pass both target name and value * Inline the re-raise [Rafael Mendonça França + Anton Khamets]
* Extend image_tag to accept ActiveStorage Attachments and Variants (#30084)Anton Khamets2017-08-071-0/+2
| | | | | | | | | | | | | | | | | | * Extend image_tag to accept ActiveStorage's Attachments and Variants * Flip resolve_image_source around * Add tests for the new use-cases of image_tag * Remove the higher-level test * Update image_tag documentation * Add error states into the test suite * Re-raise polymorhic_url's NoMethodError as ArgumentError * delegate_missing_to will raise DelegationError instead of NoMethodError
* [Active Support] `rubocop -a --only Layout/EmptyLineAfterMagicComment`Koichi ITO2017-07-1111-0/+11
|
* Merge pull request #29728 from kirs/frozen-activesupportMatthew Draper2017-07-0911-0/+11
|\ | | | | Use frozen-string-literal in ActiveSupport
| * Use frozen-string-literal in ActiveSupportKir Shatrov2017-07-0911-0/+11
| |
* | Use `map` in `delegate` so that actual prefixed method names are returned, ↵Krzysztof Zych2017-07-051-1/+1
|/ | | | if using prefix version.
* [Active Support] require => require_relativeAkira Matsuda2017-07-016-9/+9
|
* Implement mattr_acessor :default optionGenadi Samokovarov2017-06-031-24/+19
|
* Assorted delegate_missing_to doc fixesT.J. Schuck2017-05-041-22/+17
| | | | | | | | | | | | * Fix rdoc code formatting — `tt`, not backticks * Fix/simplify sentence grammar — should at least just be “and the like”, not “likes”, but this is just general tightening up. * Add note that delegated methods must be public. Tested here: https://github.com/rails/rails/blob/7ff5ccae94ce2aff76b5f8a31a28e305a047d642/activesupport/test/core_ext/module_test.rb#L359-L365 * Simplify example code for delegate_missing_to. The example had complexity that wasn’t necessary for demonstrating `delegate_missing_to`. This gets rid of a bunch of cruft so the example is more obvious about what’s going on regarding the feature itself. [ci skip]
* delegate_missing_to should fall back to superMatthew Draper2017-04-091-1/+1
|
* delegate_to_missing doesn't delegate private methodsMatthew Draper2017-04-091-1/+4
| | | | So we shouldn't claim they're there, even when asked explicitly.
* Not ants were harmed! 🐜Mario Uher2017-02-141-1/+1
|
* Docs: Correction: Module::DelegationErrorJared Beck2017-02-031-7/+9
| | | | | | | | | | | | | | | | When the delegation target is nil and the allow_nil option is not in use, a Module::DelegationError is raised. class C delegate :a, to: :b def b nil end end C.new.a # => Module::DelegationError: C#a delegated to b.a, but b is nil [ci skip]
* Adjust `Module.parent_name` to work when frozen; fixes #27637Corey Ward2017-01-171-2/+4
|
* Merge pull request #26480 from tbrisker/fix-26461Rafael França2017-01-041-2/+7
|\ | | | | Clarify that mattr_* creates public methods
| * Reword according to feedbackTomer Brisker2016-09-151-8/+7
| |
| * Clarify that mattr_* creates public methodsTomer Brisker2016-09-131-0/+6
| |
* | split DELEGATION_RESERVED_METHOD_NAMES in halfToshimaru2016-12-091-4/+5
| |
* | Remove deprecated method alias_method_chainAndrew White2016-11-141-48/+0
| |
* | Remove deprecated Module.qualified_const_get/set/defined?Andrew White2016-11-141-70/+0
| |