aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
Commit message (Collapse)AuthorAgeFilesLines
* 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
| * `SetupAndTeardown` has few caveats that breaks libraries:Edouard CHIN2018-04-272-10/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - In #32472 I introduced a fix in order for all `after_teardown` method provided by libraries and Rails to run, even if the application's `teardown` method raised an error (That's the default minitest behavior). However this change wasn't enough and doesn't take in consideration the ancestors chain. If a library's module containing an `after_teardown` method get included after the `SetupAndTeardown` module (one example is the [ActiveRecord::TestFixtures module](https://github.com/rails/rails/blob/7d2400ab61c8e3ed95e14d03ba3844e8ba2e36e4/activerecord/lib/active_record/fixtures.rb#L855-L856), then the ancestors of the test class would look something like ```ruby class MyTest < ActiveSupport::TestCase end puts MyTest.ancestors # [MyTest, ActiveSupport::TestCase, ActiveRecord::TestFixtures, ActiveSupport::Testing::SetupAndTeardown] ``` Any class/module in the ancestors chain that are **before** the `ActiveSupport::Testing::SetupAndTeardown` will behave incorrectly: - Their `before_setup` method will get called **after** all regular setup method - Their `after_teardown` method won't even get called in case an exception is raised inside a regular's test `teardown` A simple reproduction script of the problem here https://gist.github.com/Edouard-chin/70705542a59a8593f619b02e1c0a188c - One solution to this problem is to have the `AS::SetupAndTeardown` module be the very first in the ancestors chain. By doing that we ensure that no `before_setup` / `after_teardown` get executed prior to running the teardown callbacks
* | Don't dup Strings when jsonifyingAkira Matsuda2018-04-271-2/+6
|/ | | | This method would be called so many times and would create so many temporary garbage Strings
* Reduce extra object creations in TaggedLoggingAkira Matsuda2018-04-271-1/+3
| | | | | | | | | | | | | | | | | | | | | | tags_text method creates 3 Ruby objects per each logger call when no custom tags are given (which is the default setting, and so presumably the majority use case). This patch reduces two temporary object creations in this case. require 'allocation_tracer' ObjectSpace::AllocationTracer.setup(%i{type}) tags = ['a'] pp before: ObjectSpace::AllocationTracer.trace { tags.collect { |tag| "[#{tag}] " }.join } pp after: ObjectSpace::AllocationTracer.trace { "[#{tags[0]}] " } {:before=>{[:T_ARRAY]=>[1, 0, 0, 0, 0, 0], [:T_STRING]=>[2, 0, 0, 0, 0, 0]}} {:after=>{[:T_STRING]=>[1, 0, 0, 0, 0, 0]}}
* Fix Style/RedundantReturn offensesBart de Water2018-04-211-1/+1
|
* Return back "/" to the end of RAILS_GEM_ROOTbogdanvlviv2018-04-201-1/+1
| | | | | | | | | | | - The "/" was removed in 40bdbce191ad90dfea43dad51fac5c4726b89392 during refactoring. It may cause regression since looks like was added intentionaly because it is possible that a name of any another gem can start with /rails/, so slash was added to ensure that it is "rails" gem. I would like to backport this to `5-2-stable` too. - Use `__dir__` instead of `__FILE__`. Follow up #29176.
* Merge pull request #32168 from christianblais/activesupport-ordinalize-i18nRafael França2018-04-193-13/+31
|\ | | | | `#ordinal` and `#ordinalize` now support I18n
| * `ActiveSupport::Inflector#ordinal` and `ActiveSupport::Inflector#ordinalize`Christian Blais2018-03-053-13/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | now support translations through I18n. { fr: { number: { nth: { ordinals: lambda do |_key, number:, **_options| if number.to_i.abs == 1 'er' else 'e' end end, ordinalized: lambda do |_key, number:, **_options| "#{number}#{ActiveSupport::Inflector.ordinal(number)}" end } } } }
* | Merge branch 'master' into fix-as-timezone-allAndrew White2018-04-191-6/+13
|\ \
| * | Redis cache store: avoid blocking the server in `#delete_matched`Gleb Mazovetskiy2018-04-181-6/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fixes #32610. Closes #32614. Lua scripts in redis are *blocking*, meaning that no other client can execute any commands while the script is running. See https://redis.io/commands/eval#atomicity-of-scripts. This results in the following exceptions once the number of keys is sufficiently large: BUSY Redis is busy running a script. You can only call SCRIPT KILL or SHUTDOWN NOSAVE. This commit replaces the lua-based implementation with one that uses `SCAN` and `DEL` in batches. This doesn't block the server. The primary limitation of `SCAN`, i.e. potential duplicate keys, is of no consequence here, because `DEL` ignores keys that do not exist.
* | | Fix exception in AS::Timezone.all when any tzinfo data is missingDominik Sander2018-04-181-1/+2
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Before this change missing timezone data for any of the time zones defined in `ActiveSupport::Timezone::MAPPING` caused a `comparison of NilClass with ActiveSupport::TimeZone failed` exception. Attempting to get a timezone by passing a number/duration to `[]` or calling `all` directly will try to sort sort the values of `zones_map`. Those values are initialized by the return value of `create(zonename)` which returns `nil` if `TZInfo` is unable to find the timezone information. In our case the exception was triggered by an outdated tzdata package which did not include information for the "recently" added time zones. Before 078421bacba178eac6a8e607b16f3f4511c5d72f `zones_map` only returned the information that have been loaded into `@lazy_zone_map` which ignored time zones for which the data could not be loaded, this change restores the previous behaviour.
* | Inclusive Language in Documentation Examples [ci skip]Cassidy Kobewka2018-04-151-2/+2
| |
* | Fix redis store clear keys outside the namespaceRei2018-04-151-1/+1
| | | | | | | | | | | | | | | | | | | | Namespace not working in RedisCacheStore#clear method. Bacause namespace = merged_options(options)[namespace] is always nil, Correct is namespace = merged_options(options)[:namespace]
* | Merge pull request #32551 from chrisarcand/no-doc-original-sumRafael França2018-04-121-1/+1
|\ \ | | | | | | Don't doc _original_sum_with_required_identity
| * | Don't doc _original_sum_with_required_identityChris Arcand2018-04-121-1/+1
| | | | | | | | | | | | It's not public API so don't document it.
* | | Merge pull request #32539 from chancancode/anticompressRafael França2018-04-121-35/+32
|\ \ \ | |/ / |/| | Fix ActiveSupport::Cache compression
| * | Fix `ActiveSupport::Cache` compressionGodfrey Chan2018-04-111-35/+32
| | | | | | | | | | | | (See previous commit for a description of the issue)
* | | Merge pull request #32542 from ↵George Claghorn2018-04-121-2/+3
|\ \ \ | | | | | | | | | | | | | | | | teddywing/active-support-cache-store--fix-end-tag-in-read-method-documentation Cache::Store#read: Fix fixed-width end tag in docs
| * | | Cache::Store#read: Fix fixed-width end tag in docsTeddy Wing2018-04-121-2/+3
| |/ / | | | | | | | | | | | | | | | | | | | | | * Fix the ending `</tt>` tag for `:expires_in`. Otherwise, the "or" is set in fixed-width also. * Re-wrap paragraph to 80 columns. [ci skip]
* | | Merge pull request #31913 from rywall/define-callbacks-descMatthew Draper2018-04-121-1/+3
|\ \ \ | |/ / |/| | Define callbacks on descendants.
| * | No need to define methods on descendants.Ryan Wallace2018-02-241-18/+18
| | | | | | | | | | | | Addresses feedback from https://github.com/rails/rails/pull/31913#issuecomment-365983580
| * | Define callbacks on descendants.Ryan Wallace2018-02-061-17/+19
| | | | | | | | | | | | We set callbacks on all descendants, so we need to make sure that they are also defined on all descendants as well.
* | | `SetupAndTeardown#teardown` should call any subsequent after_teardown:Edouard CHIN2018-04-061-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | If you have a regular test that have a teardown block, and for any reason an exception get raised, ActiveSupport will not run subsequent after_teardown method provided by other module or gems. One of them being the ActiveRecord::TestFixtures which won't rollback the transation when the test ends making all subsequent test to be in a weird state. The default implementation of minitest is to run all teardown methods from the user's test, rescue all exceptions, run all after_teardown methods provided by libraries and finally re-raise the exception that happened in the user's teardown method. Rails should do the same.
* | | [ci skip] Add :private option to delegation docYoshiyuki Hirano2018-04-051-1/+2
| | |
* | | Small doc fixesT.J. Schuck2018-04-021-4/+4
| | | | | | | | | | | | [ci skip]
* | | Merge pull request #32268 from freeletics/encrypted-tmp-file-nameKasper Timm Hansen2018-04-011-1/+1
|\ \ \ | | | | | | | | Change temporary file name extension while editing encrypted file.
| * | | Change temporary file name extension while editing encrypted file.Wojciech Wnętrzak2018-03-181-1/+1
| | | | | | | | | | | | | | | | To have syntax highlighting in an editor try to preserve original extension of edited file.
* | | | Move implementation of `before?` and `after?` to `DateAndTime::Calculations`bogdanvlviv2018-03-314-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This prevents duplication of code. Prevent duplication of tests by moving them to `DateAndTimeBehavior`. Related to #32185.
* | | | Adding missing extension for `cattr_accessor` methodWojciech Wnętrzak2018-03-301-0/+1
| | | |
* | | | Merge pull request #32185 from nholden/human_readable_date_time_comparisonsRafael França2018-03-264-0/+8
|\ \ \ \ | | | | | | | | | | Add `before?` and `after?` methods to date and time classes
| * | | | Add `before?` and `after?` methods to date and time classesNick Holden2018-03-064-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Equality comparisons between dates and times can take some extra time to comprehend. I tend to think of a date or time as "before" or "after" another date or time, but I naturally read `<` and `>` as "less than" and "greater than." This change seeks to make date/time comparisons more human readable.