aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/module
Commit message (Collapse)AuthorAgeFilesLines
...
* | 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]
* Use Thread.current.thread_variable_set/get insetad of the direct accessorsDavid Heinemeier Hansson2015-12-171-4/+4
|
* Fix typo in thread_mattr_accessor doco [ci skip]Nate Berkopec2015-12-171-1/+1
|
* Add thread_m/cattr_accessor/reader/writer suite of methods for declaring ↵David Heinemeier Hansson2015-12-171-0/+140
| | | | class and module variables that live per-thread
* Don't leak Object constants in core_ext/module/qualified_constGenadi Samokovarov2015-12-161-12/+30
|
* Minor fix in Module#mattr_reader documentationYuri Kasperovich2015-11-091-1/+1
|
* Make `Module#redefine_method` to keep method visibilityyui-knk2015-10-261-0/+13
| | | | | | | Before this commit `Module#redefine_method` always changes visibility of redefined method to `public`. This commit changes behavior of Module#redefine_method` to keep method visibility.
* [ci skip] Add more code examples for `Module#anonymous?` docsyui-knk2015-10-231-2/+4
| | | | | In later code examples, it is better to write how `Module#anonymous?` works.
* Add Module#remove_possible_singleton_methodAndrew White2015-10-211-0/+7
| | | | | This is primarily to fix method redefinition warnings in class_attribute but may be of use in other places where we define singleton methods.
* Merge pull request #21302 from theunraveler/delegate_reserved_argument_namesSean Griffin2015-10-201-5/+6
|\ | | | | ActiveSupport: Fixing issue when delegating to methods named "block", "args", or "arg"
| * Fixing issue when delegating to methods named "block", "args", or "arg"Jake Bell2015-08-191-5/+6
| |
* | Regex fix for mattr_accessor validationAliaksandr Buhayeu2015-10-011-2/+2
| | | | | | | | | | Change ^ and $ operators to \A and \z to prevent code injection after the line breaks
* | Correcting `NameError` error message in `mattr_reader` method. Since this ↵amitkumarsuroliya2015-09-191-2/+2
|/ | | | | | commit https://github.com/rails/rails/commit/7dfbd91b0780fbd6a1dd9bfbc176e10894871d2d, `NameError` includes attribute_name also in error message [ci skip]
* Only invoke the default block for mattr_accessor once so that it does not ↵Lachlan Sylvester2015-08-071-1/+1
| | | | cause issues if it is not idempotent
* Freeze string literals when not mutated.schneems2015-07-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I wrote a utility that helps find areas where you could optimize your program using a frozen string instead of a string literal, it's called [let_it_go](https://github.com/schneems/let_it_go). After going through the output and adding `.freeze` I was able to eliminate the creation of 1,114 string objects on EVERY request to [codetriage](codetriage.com). How does this impact execution? To look at memory: ```ruby require 'get_process_mem' mem = GetProcessMem.new GC.start GC.disable 1_114.times { " " } before = mem.mb after = mem.mb GC.enable puts "Diff: #{after - before} mb" ``` Creating 1,114 string objects results in `Diff: 0.03125 mb` of RAM allocated on every request. Or 1mb every 32 requests. To look at raw speed: ```ruby require 'benchmark/ips' number_of_objects_reduced = 1_114 Benchmark.ips do |x| x.report("freeze") { number_of_objects_reduced.times { " ".freeze } } x.report("no-freeze") { number_of_objects_reduced.times { " " } } end ``` We get the results ``` Calculating ------------------------------------- freeze 1.428k i/100ms no-freeze 609.000 i/100ms ------------------------------------------------- freeze 14.363k (± 8.5%) i/s - 71.400k no-freeze 6.084k (± 8.1%) i/s - 30.450k ``` Now we can do some maths: ```ruby ips = 6_226k # iterations / 1 second call_time_before = 1.0 / ips # seconds per iteration ips = 15_254 # iterations / 1 second call_time_after = 1.0 / ips # seconds per iteration diff = call_time_before - call_time_after number_of_objects_reduced * diff * 100 # => 0.4530373333993266 miliseconds saved per request ``` So we're shaving off 1 second of execution time for every 220 requests. Is this going to be an insane speed boost to any Rails app: nope. Should we merge it: yep. p.s. If you know of a method call that doesn't modify a string input such as [String#gsub](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37) please [give me a pull request to the appropriate file](https://github.com/schneems/let_it_go/blob/b0e2da69f0cca87ab581022baa43291cdf48638c/lib/let_it_go/core_ext/string.rb#L37), or open an issue in LetItGo so we can track and freeze more strings. Keep those strings Frozen ![](https://www.dropbox.com/s/z4dj9fdsv213r4v/let-it-go.gif?dl=1)
* adding brackets to array in docsJulio Lopez2015-07-071-1/+1
|
* Clearify that alias_method_chain is deprecatedPrem Sichanugrist2015-04-221-0/+3
| | | | | This was not clear on the API documentation that the method was deprecated in a982a42d766169c2170d7f100c2a5ceb5430efb1.
* Fix typos and improve the documentationJon Atack2015-04-151-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a squash of the following commits, from first to last: - Fix minor, random things I’ve come across lately that individually did not seem worth making a PR for, so I saved them for one commit. One common error is using “it’s” (which is an abbreviation of “it is”) when the possessive “its” should be used for indicating possession. - Changes include the name of a test, so remove the `[skip ci]` (thanks @senny). - Line wrap the changes at 80 chars and add one more doc fix. - Add a missing line wrap in the Contributing to Ruby on Rails Guide. - Line wrap the `TIP` section in the Contributing to Ruby on Rails Guide as well. Rendering the guide locally with `bundle exec rake guides:generate` did not show any change in on-screen formatting after adding the line wrap. The HTML generated is (extra line added to illustrate where the line wrap takes place): <div class="info"><p>Please squash your commits into a single commit when appropriate. This simplifies future cherry picks and also keeps the git log clean.</p></div> - Squash commits.
* [ci skip] Replace `query methods` with `a predicate`yui-knk2015-03-311-1/+1
|