aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module
Commit message (Collapse)AuthorAgeFilesLines
* [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
| |
* | Remove deprecated module method_transplanting fileAndrew White2016-11-131-3/+0
| |
* | Remove deprecated local_constantsAndrew White2016-11-131-8/+0
| |
* | Add more rubocop rules about whitespacesRafael Mendonça França2016-10-291-1/+1
| |
* | doc, hide non-public methods form the api docs. [ci skip]Yves Senn2016-10-201-2/+2
|/ | | | | | | | | This is a follow up to #25681, specifically this comment: https://github.com/rails/rails/pull/25681#issuecomment-238294002 The way the thread local variable is stored is an implementation detail and subject to change. It makes no sense to only generate a reader or writer as you'd have to know where to read from or where it writes to.
* Fix typo in Delegation#delegate_missing_to doc [skip ci]Anton Davydov2016-08-271-1/+1
|
* Add three new rubocop rulesRafael Mendonça França2016-08-161-2/+2
| | | | | | | | Style/SpaceBeforeBlockBraces Style/SpaceInsideBlockBraces Style/SpaceInsideHashLiteralBraces Fix all violations in the repository.
* Merge pull request #25570 from y-yagi/remove_useless_parameterEileen M. Uchitelle2016-08-151-3/+3
|\ | | | | remove useless parameter
| * remove useless parameteryuuji.yaginuma2016-06-291-4/+4
| |
* | let instance thread_mattr_* methods delegate to the class-level onesXavier Noria2016-08-081-4/+10
| | | | | | | | | | | | | | This code has too much duplication and the rationale for the concatenation may not be obvious to the reader. You define the ones at class-level, explain why does the code concatenates there, and then the convenience ones at instance-level just delegate.
* | Merge pull request #25681 from willnet/fix-thread_mattr_accessorYves Senn2016-08-081-4/+4
|\ \ | | | | | | | | | Fix `thread_mattr_accessor` share variable superclass with subclass
| * | Fix `thread_mattr_accessor` share variable superclass with subclasswillnet2016-08-041-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current implementation of `thread_mattr_accessor` set variable sharing superclass with subclass. So the method doesn't work as documented. Precondition class Account thread_mattr_accessor :user end class Customer < Account end Account.user = "DHH" Account.user #=> "DHH" Customer.user = "Rafael" Customer.user # => "Rafael" Documented behavior Account.user # => "DHH" Actual behavior Account.user # => "Rafael" Current implementation set variable statically likes `Thread[:attr_Account_user]`, and customer also use it. Make variable name dynamic to use own thread-local variable.
* | | damn typos [ci skip]Xavier Noria2016-08-081-1/+1
| | |
* | | explain why aliasing uses explicit selfs [ci skip]Xavier Noria2016-08-081-0/+3
| | |
* | | applies new string literal convention in activesupport/libXavier Noria2016-08-0610-24/+24
|/ / | | | | | | | | The current code base is not uniform. After some discussion, we have chosen to go with double quotes by default.
* / systematic revision of =~ usage in ASXavier Noria2016-07-223-7/+10
|/ | | | | Where appropriate prefer the more concise Regexp#match?, String#include?, String#start_with?, and String#end_with?
* Replace Kernel#caller by the faster Kernel#caller_locationsJean Boussier2016-06-101-2/+2
|
* [skip ci] Fix grammarAbhishek Jain2016-06-031-2/+2
|
* Don't delegate to private methods of the targerRafael Mendonça França2016-05-241-1/+5
| | | | And make sure that it doesn't even try to call the method in the target.
* Merge pull request #23930 from gsamokovarov/module-delegate-missing-toRafael Mendonça França2016-05-241-1/+60
|\ | | | | | | Introduce Module#delegate_missing_to
| * Introduce Module#delegate_missing_toGenadi Samokovarov2016-02-271-1/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When building decorators, a common pattern may emerge: class Partition def initialize(first_event) @events = [ first_event ] end def people if @events.first.detail.people.any? @events.collect { |e| Array(e.detail.people) }.flatten.uniq else @events.collect(&:creator).uniq end end private def respond_to_missing?(name, include_private = false) @events.respond_to?(name, include_private) end def method_missing(method, *args, &block) @events.send(method, *args, &block) end end With `Module#delegate_missing_to`, the above is condensed to: class Partition delegate_missing_to :@events def initialize(first_event) @events = [ first_event ] end def people if @events.first.detail.people.any? @events.collect { |e| Array(e.detail.people) }.flatten.uniq else @events.collect(&:creator).uniq end end end David suggested it in #23824.
* | Update delegate to use newer Ruby syntaxTodd Lynam2016-04-201-5/+2
| | | | | | This commit updates `delegate` to use the keyword argument syntax added in Ruby 2. I left the `ArgumentError` when `to` is missing, because it better explains how to correctly use `delegate`. We could instead rely on the default `ArgumentError` that would be raised if `to` were a required keyword argument.
* | fixed spelling in the attribute_accessors docuTorsten Braun2016-03-231-1/+1
| | | | | | mattr_writer to mattr_reader
* | fixed spellin in the mattr_reader documentationTorsten Braun2016-03-231-1/+1
| | | | | | renamed cattr_reader to mattr_reader
* | Fix `thread_mattr_accessor` thread-local variable namingMichael Ryan2016-03-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current implentation of `thread_mattr_accessor` is setting differently-named thread variables when defining class and instance writer methods, so the method isn't working as documented: Account.user = "DHH" Account.user # => "DHH" Account.new.user # => nil a = Account.new a.user = "ABC" # => "ABC" a.class.user # => "DHH" At this point `:attr_Account_user` and `:attr_Class_user` thread-local variables have been created. Modify the reader and writer methods to use the class name instead of 'Class'.
* | Deprecate `Module.local_constants`yui-knk2016-03-011-0/+4
|/ | | | | After Ruby 1.9, we can easily get the constants that have been defined locally by `Module.constants(false)`.
* :arrow_left: indentationAkira Matsuda2016-01-281-2/+2
| | | | [ci-skip]
* Fix documentation for mattr_accessor methodsJan Habermann2015-12-201-6/+6
|
* [ci skip] Revert most of ff851017Kasper Timm Hansen2015-12-181-2/+2
| | | We went back to `Thread.current[]` in 33e11e59.
* Revert "Use Thread.current.thread_variable_set/get insetad of the direct ↵David Heinemeier Hansson2015-12-181-4/+4
| | | | | | accessors" This reverts commit 301f43820562c6a70dffe30f4227ff0751f47d4f per @matthewd on https://github.com/rails/rails/pull/22630/files#r47997074
* [ci skip] Add `Thread.current` to match internalsKasper Timm Hansen2015-12-171-2/+2
| | | | | | | | We call the thread variable accessors on `Thread.current`, which matches Ruby's documentation: http://ruby-doc.org/core-2.2.0/Thread.html#method-i-thread_variable_get Fix these to stay `current` ( ͡° ͜ʖ ͡°)
* Clarify thread_mattr_accessor subclass behavior documentationNate Berkopec2015-12-171-8/+9
| | | | [ci skip]
* Copy-edit the Per Thread attribute accessor documentationRafael Mendonça França2015-12-171-3/+3
| | | | [ci skip]