aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
Commit message (Collapse)AuthorAgeFilesLines
* Support skip nil for cache fetch (#25437)Martin2018-08-051-1/+9
| | | | | | | | | | | | * test case for fetch cache miss with skip_nil * abondon nil cache if skip_nil specified * ensure not cache key for skip nil * add document with skip_nil for Store#fetch * add a new change log entry for #25437
* Fix example in thread_mattr_accessor documentationFabian Mersch2018-07-311-1/+1
|
* Remove unused requireRyuta Kamizono2018-07-311-1/+0
| | | | | "active_support/core_ext/module/aliasing" is no longer used since #19434.
* Merge pull request #33325 from Edouard-chin/ec-deprecate-class-methodRyuta Kamizono2018-07-311-14/+17
|\ | | | | A regression in `deprecate_methods` was introduced in a982a42:
| * A regression in deprecate_methods was introduced in a982a42:Edouard CHIN2018-07-301-14/+17
| | | | | | | | | | | | | | | | | | | | | | - Refactoring alias_chain to Module#prepend broke the possibility to deprecate class methods since the module generated was prepended to the target's instance. A suggestion to fix this was to use `AS#redefine_method` which would solve the problem but with the cost of redefining directly the method. Decided to go with the same alias_chain implementation as before instead. - Fixes #33253
* | Merge pull request #33467 from bdewater/chomp-unconditionallyKasper Timm Hansen2018-07-301-2/+2
|\ \ | | | | | | Chomp will work without checking for end of the string
| * | Chomp will work without checking for end of the stringBart de Water2018-07-291-2/+2
| | |
* | | Only use CLOCK_PROCESS_CPUTIME_ID if it's definedBart de Water2018-07-291-2/+8
|/ / | | | | | | It's not defined on JRuby and unlike monotonic time, concurrent-ruby doesn't have an cross-platform abstraction for this.
* | Remove unused `require "active_support/core_ext/regexp"`Ryuta Kamizono2018-07-2911-12/+0
| | | | | | | | | | | | | | | | Ruby 2.4 has native `Regexp#match?`. https://ruby-doc.org/core-2.4.0/Regexp.html#method-i-match-3F Related #32034.
* | Work around Performance/EndWith false positiveBart de Water2018-07-281-2/+2
| | | | | | | | | | Rubocop warns about "Use String#end_with? instead of a regex match anchored to the end of the string", it doesn't seem aware of the $` special variable like Performance/RegexpMatch
* | Merge pull request #33441 from bogdanvlviv/remove-rubocop-comments-from-codebaseRyuta Kamizono2018-07-271-1/+1
|\ \ | | | | | | Remove Rubocop's comments from Rails code base
| * | Fix Rubocop offensebogdanvlviv2018-07-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ``` Offenses: activesupport/lib/active_support/subscriber.rb:91:17: C: Layout/SpaceAroundOperators: Operator = should be surrounded by a single space. event = event_stack.pop ```
* | | fix arity check to use "parameters" for backwards compatAaron Patterson2018-07-261-4/+9
| | |
* | | Always subscribe to event objects via `AS::Notifications.subscribe`Aaron Patterson2018-07-262-12/+9
| | | | | | | | | | | | | | | | | | | | | We don't need to have a special subscribe method for objects. The regular `subscribe` method is more expensive than a specialized method, but `subscribe` should not be called frequently. If that turns out to be a hotspot, we can introduce a specialized method. :)
* | | Subscribe to event objects via `subscribe_event`Aaron Patterson2018-07-262-1/+39
| | | | | | | | | | | | | | | | | | Fanout notifier can send event objects to subscribers now. Also moved `end` lower in the `finish!` method to guarantee that CPU time is shorter than real time.
* | | Match the units in `duration` (milliseconds)Aaron Patterson2018-07-261-1/+7
|/ /
* | Add cpu_time, idle_time, and allocations to EventEileen Uchitelle2018-07-262-4/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * Use process clock instead of Time.now This fixes any issues with the system clock changing and also eliminates 2 object allocations per event. * Add start! and finish! methods to the event object so we can record more information * Adds cpu time, idle time, and allocation count for a particular event. Co-authored-by: Aaron Patterson <aaron.patterson@gmail.com>
* | Merge pull request #32381 from q-centrix/update-codeclimate-configsRichard Schneeman2018-07-254-19/+11
|\ \ | | | | | | Turn on performance based cops
| * | Turn on performance based copsDillon Welch2018-07-234-19/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Use attr_reader/attr_writer instead of methods method is 12% slower Use flat_map over map.flatten(1) flatten is 66% slower Use hash[]= instead of hash.merge! with single arguments merge! is 166% slower See https://github.com/rails/rails/pull/32337 for more conversation
* | | Update with_options.rbDaniel Amireh2018-07-251-1/+1
| | | | | | | | | explicit mapping for enum accepts a Hash not an Array, plus the example is using `.keys` which also exists on hash
* | | Merge pull request #33229 from ↵Matthew Draper2018-07-251-1/+1
|\ \ \ | |/ / |/| | | | | | | | albertoalmagro/albertoalmagro/prefer-rails-command-over-bin-rails Prefer rails command over bin/rails
| * | Fix typo 'in via'Alberto Almagro2018-07-061-1/+1
| | | | | | | | | | | | Substitutes 'in via' for 'by running'
| * | Recommend use of rails over bin/railsAlberto Almagro2018-07-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | As discussed in #33203 rails command already looks for, and runs, bin/rails if it is present. We were mixing recommendations within guides and USAGE guidelines, in some files we recommended using rails, in others bin/rails and in some cases we even had both options mixed together.
* | | e4e1b62 broke `to_param` handling:Edouard CHIN2018-07-121-2/+5
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - There was an issue inside controller tests where order params were not respected, the reason was because we were calling `Hash#to_query` which sorts the results lexicographically. 1e4e1b62 fixed that issue by not using `to_query` but instead a utility function provided by rack. - However with the fix came another issue where it's now no longer possible to do this ``` post :foo, params: { user: User.first } # Prior to the patch the controller will receive { "user" => "1" } # Whereas now you get { "user": "#<User: ...>" } ``` The fix in this PR is to modify `Hash#to_query` to sort only when it doesn't contain an array structure that looks something like "bar[]" Ref https://github.com/rails/rails/pull/33341#issuecomment-404039396
* | added tests for assert_no_difference with multiple expressionslxxxvi2018-07-081-0/+12
|/
* A Class is a Module so we remove one conditionalRafael Mendonça França2018-07-041-1/+1
|
* Merge pull request #33289 from Edouard-chin/ec-lazy-load-hooksRafael França2018-07-041-1/+5
|\ | | | | Use class_eval or instance_eval when triggering lazy load hooks
| * Use class_eval or instance_eval when triggering lazy load hooks:Edouard CHIN2018-07-031-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - When lazy load hooks were triggered we were using `Object.instance_eval` which evaluates the block in the context of the class being passed. Most of the time that class was a `Class`. If one wants to define a instance method on the class then it wasn't possible. ```ruby class A; end; A.instance_eval do def foo puts 'bar' end end A.new.foo #> NoMethodError: undefined method `foo` A.foo #> bar ``` - This PR checks what object is passed when triggering the hooks and either call `class_eval` or `instance_eval`. My rational and assumptions being that if an instance of a class is passed, then the blocks needs to evaluate in the context of that instance (i.e. defining a method should only define it on that instance). On the other hand, if a Class or Module is passed when triggering hooks, then defining a method should define it on the class itself - #32776 Pushed me to introduce this change
* | Refactor #33254.Kasper Timm Hansen2018-07-011-16/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | Firstly, increment and decrement shouldn't care about the particulars of key expiry. They should only know that they have to pass that responsibility on to somewhere else. Secondly, it moves the key normalization back inside the instrumentation like it was originally. I think that matches the original design intention or at the very least it lets users catch haywire key truncation. Thirdly, it moves the changelog entry to the top of the file, where new entries go. I couldn't understand what the entry was saying so I tried to rewrite it.
* | Fix Cache :redis_store increment/decrement ttl check and add more tests.Jason Lee2018-06-301-2/+2
| |
* | Add :expires_in option support for RedisCacheStore increment/decrement method.Jason Lee2018-06-291-2/+22
|/
* Merge pull request #33106 from marcandre/datecalcRafael Mendonça França2018-06-111-15/+12
|\ | | | | | | Improve some DateAndTime calculations
| * Use fetch for better error handlingMarc-Andre Lafortune2018-06-091-2/+2
| |
| * Use same weekday correspondance as Date#wday.Marc-Andre Lafortune2018-06-091-13/+10
|/ | | | | | | | | DeepCover revealed that most of these `wday != 0 ? wday - 1 : 6` were not entirely covered, i.e. the case of `wday == 0` was not tested: https://deep-cover.github.io/rails-cover/activesupport/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb.html#L351 There's actually no valid reason to consider Sunday a special case, so this commit simply reajusts the values used for calculations.
* Add `ActiveSupport::CompareWithRange` to API docsbogdanvlviv2018-06-071-1/+1
| | | | | | | | Since it is documented in the guides http://edgeguides.rubyonrails.org/active_support_core_extensions.html#include-questionmark-and-cover-questionmark we can add it to API docs http://edgeapi.rubyonrails.org too. [ci skip]
* Don't expose `Enumerable#_original_sum_with_required_identity` which is ↵yuuji.yaginuma2018-06-041-1/+5
| | | | | | | | | | internal API [ci skip] `:nodoc:` is specified, but unfortunately, it is exposed in the API doc. http://edgeapi.rubyonrails.org/classes/Enumerable.html#method-i-_original_sum_with_required_identity If the method of the `alias` destination is public, the specification of `:nodoc:` does not seem to work.
* Merge pull request #33020 from joshpencheon/time_zone_frac_microsecondsRafael França2018-05-301-2/+7
|\ | | | | Align Time.zone.at method signature with that of Time::at
| * Allow Time.zone.at to receive a second argumentJosh Pencheon2018-05-301-2/+7
| | | | | | | | For parity with Ruby's Time::at
* | Remove unused `require "active_support/file_update_checker"`yuuji.yaginuma2018-05-301-1/+0
|/ | | | This is unnecessary since #22269.
* Improve grammar for DateAndTime before? and after? calculations [ci skip]Aaron Sumner2018-05-241-2/+2
|
* Merge pull request #32822 from lxxxvi/improved_error_message_in_assert_changesRafael França2018-05-221-1/+3
|\ | | | | Clearer error message in assert_changes
| * Clearer error message in assert_changeslxxxvi2018-05-051-1/+3
| | | | | | | | When `to:` is passed to `assert_changes`, it now prints the well-known `"Expected: x\n Actual: y"` message. Before, the message only contained the actual value.
* | Merge pull request #32851 from yskkin/doc_require_dependencyRafael França2018-05-221-0/+4
|\ \ | | | | | | Document require_dependency [ci skip]
| * | Document require_dependency [ci skip]Yoshiyuki Kinjo2018-05-091-0/+4
| |/
* | Allow Range#=== and Range#cover? on Rangeutilum2018-05-223-23/+68
| | | | | | | | | | | | | | | | | | | | | | ruby/ruby@989e07c features switching `Range#===` to use internal `r_cover_p` instead of rubyland `include?`. This breaks expected behavior of `ActiveSupport::CoreExt::Range` documented since at least 8b67a02. This patch adds overrides on `Range#cover?` and `Range#===` and places all three in a single module, `CompareWithRange`. *Requiring core_ext/range/include_range now causes a deprecation warnning*
* | Add Enumerable#index_with.Kasper Timm Hansen2018-05-211-1/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In the app I'm working on I've wished that index_by had a buddy that would assign the hash value instead of the key multiple times. Enter index_with. Useful when building a hash from a static list of symbols. Before you'd do: ```ruby POST_ATTRIBUTES.map { |attr_name| [ attr_name, public_send(attr_name) ] }.to_h ``` But now that's a little clearer and faster with: ````ruby POST_ATTRIBUTES.index_with { |attr_name| public_send(attr_name) } ``` It's also useful when you have an enumerable that should be converted to a hash, but you don't want to muddle the code up with the overhead that it takes to create that hash. So before, that's: ```ruby WEEKDAYS.each_with_object(Hash.new) do |day, intervals| intervals[day] = [ Interval.all_day ] end ``` And now it's just: ```ruby WEEKDAYS.index_with([ Interval.all_day ]) ``` It's also nice to quickly get a hash with either nil, [], or {} as the value.
* | Raise a better exception when a invalid depreation behavior is setRafael Mendonça França2018-05-181-0/+4
|/ | | | Fixes #32928.
* Fix #29632 - nil #path leads to NoMethodError in LoadError#is_missing?Neil Souza2018-05-041-1/+1
| | | | | | | | See #29632 for details. In short, it's possible to enter `LoadError#is_missing?` when `LoadError#path` returns `nil`, leading to `path.sub` throwing an none-to-helpful `NoMethodError`. This tiniest of patch inserts `#to_s` before the `sub` call to make sure it succeeds. Affected surface area should be just as tiny since something has already gone wrong to get us into `#is_missing?` and the current behavior when `#path` returns `nil` seems clearly not intended. [Gannon McGibbon + Neil Souza]
* Improve the performance of `ActiveSupport::Inflector.ordinal`Ryuta Kamizono2018-04-291-9/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This improves the performance for the most ordinalized numbers (1st, 2nd, 3rd, etc). ``` require "benchmark/ips" def o1(number) abs_number = number.to_i.abs if (11..13).include?(abs_number % 100) "th" else case abs_number % 10 when 1; "st" when 2; "nd" when 3; "rd" else "th" end end end def o3(number) case number when 1; "st" when 2; "nd" when 3; "rd" when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th" else num_modulo = number.to_i.abs % 100 if 11 <= num_modulo && num_modulo <= 13 "th" else case num_modulo % 10 when 1; "st" when 2; "nd" when 3; "rd" else "th" end end end end def o4(number) case number when 1; "st" when 2; "nd" when 3; "rd" when 4, 5, 6, 7, 8, 9, 10, 11, 12, 13; "th" else num_modulo = number.to_i.abs % 100 num_modulo %= 10 if num_modulo > 13 case num_modulo when 1; "st" when 2; "nd" when 3; "rd" else "th" end end end puts RUBY_DESCRIPTION Benchmark.ips do |x| x.report("orig") { o1(1); o1(2); o1(3); o1(4); o1(11); o1(111); o1(1523) } x.report("ord3") { o3(1); o3(2); o3(3); o3(4); o3(11); o3(111); o3(1523) } x.report("ord4") { o4(1); o4(2); o4(3); o4(4); o4(11); o4(111); o4(1523) } x.compare! end ``` ``` ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin15] Warming up -------------------------------------- orig 25.305k i/100ms ord3 121.146k i/100ms ord4 124.944k i/100ms Calculating ------------------------------------- orig 275.496k (± 2.4%) i/s - 1.392M in 5.054720s ord3 1.649M (± 5.0%) i/s - 8.238M in 5.009801s ord4 1.700M (± 7.0%) i/s - 8.496M in 5.031646s Comparison: ord4: 1700059.6 i/s ord3: 1649154.9 i/s - same-ish: difference falls within error orig: 275496.3 i/s - 6.17x slower ``` Closes #25020. [lvl0nax, Jeremy Daer, Ryuta Kamizono]
* Merge pull request #32733 from Edouard-chin/ec-setupand-teardownRafael França2018-04-272-10/+6
|\ | | | | `SetupAndTeardown` has few caveats that breaks libraries