aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
Commit message (Collapse)AuthorAgeFilesLines
...
* | Merge pull request #27792 from tjoyal/sandbox-tagged-loggingRafael Mendonça França2018-09-111-2/+9
|\ \ | | | | | | | | | TaggedLogging to return a new logger instance
| * | TaggedLogging to return a new logger instanceThierry Joyal2017-02-271-2/+9
| | |
* | | use "minitest" consistentlyXavier Noria2018-09-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | The name of the minitest library is spelled that way: regular font, and lowercase. Lowercase is used even at the beginning of sentences, see http://docs.seattlerb.org/minitest/ I double-checked this with @zenspider too (thanks!).
* | | Oxford comma [ci skip]Xavier Noria2018-09-101-1/+1
| | | | | | | | | | | | | | | Followup to a recently merged PR, too minor and detailed to require a modification to the contributed patch.
* | | Add #unfreeze_time to ActiveSupport::Testing::TimeHelpersryanwhocodes2018-09-101-1/+2
| | |
* | | trace autoloads, and document hints for troubleshootingXavier Noria2018-09-071-4/+21
| | | | | | | | | | | | Closes #32885.
* | | Merge pull request #33808 from itsbagpack/fix-access-safety-buffer-sliceAaron Patterson2018-09-061-3/+1
|\ \ \ | | | | | | | | Maintain html_safe? on sliced HTML safe strings
| * | | SafeBuffer should maintain safety upon getting a slice via a range if ↵Yumin Wong2018-08-311-3/+1
| | |/ | |/| | | | | | | | | | | | | original buffer was safe. Co-Authored-By: no-itsbackpack <no-itsbackpack@github.com>
* | | Fix typo in i18n_railtie.rbOlivier2018-09-061-1/+1
| | |
* | | Merge pull request #33805 from schneems/schneems/faster-file-storeRichard Schneeman2018-09-061-6/+10
|\ \ \ | | | | | | | | Faster File Store
| * | | Faster File Storeschneems2018-09-061-6/+10
| |/ / | | | | | | | | | | | | | | | Memory before 1826584.8 memory after: 1797795.6 difference: 1.58% memory (speed) savings. When the key is not longer than the limit we can avoid allocating two strings and an array.
* | | Merge pull request #33574 from ↵Rafael França2018-09-061-1/+13
|\ \ \ | | | | | | | | | | | | | | | | lsylvester/change-i18n-defaults-behaviour-to-match-i18n-1.1.0 update I18n fallbacks configuration to be compatible with i18n 1.1.0
| * | | update I18n fallbacks configuration to be compatible with i18n 1.1.0Lachlan Sylvester2018-08-231-1/+13
| | | |
* | | | Ensure we always cleanup the databasesEileen Uchitelle2018-09-051-11/+13
| |/ / |/| | | | | | | | | | | | | | This commit moves the `run_cleanup` hook into an `ensure` block so we make sure to cleanup the databases even if an exception is raised while running the parallel tests.
* | | 20% faster `try`Sean Griffin2018-08-291-8/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Following up on #33747, this takes things a step further by pulling out the method name from the arguments array, letting us skip an allocation in the case where there are no arguments -- notably, this also no longer *requires* the splat to be an array, allowing us to benefit from optimizations in Jruby (and maybe MRI in the future) of skipping the array allocation entirely. Benchmark results: ``` Warming up -------------------------------------- old 179.987k i/100ms new 199.201k i/100ms Calculating ------------------------------------- old 3.029M (± 1.6%) i/s - 15.299M in 5.052417s new 3.657M (± 1.2%) i/s - 18.326M in 5.012648s Comparison: new: 3656620.7 i/s old: 3028848.3 i/s - 1.21x slower ```
* | | Merge pull request #33747 from schneems/schneems/faster-tryRichard Schneeman2018-08-291-1/+10
|\ \ \ | | | | | | | | 32% Faster Object#try
| * | | 32% Faster Object#tryschneems2018-08-291-1/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Here’s the micro benchmark: ```ruby module ActiveSupport module NewTryable #:nodoc: def try(*a, &b) return unless a.empty? || respond_to?(a.first) return public_send(*a, &b) unless a.empty? return nil unless block_given? return instance_eval(&b) if b.arity == 0 yield self end def try!(*a, &b) return public_send(*a, &b) if !a.empty? return nil unless block_given? return instance_eval(&b) if b.arity == 0 yield self end end end module ActiveSupport module OldTryable #:nodoc: def try(*a, &b) try!(*a, &b) if a.empty? || respond_to?(a.first) end def try!(*a, &b) if a.empty? && block_given? if b.arity == 0 instance_eval(&b) else yield self end else public_send(*a, &b) end end end end class FooNew include ActiveSupport::NewTryable def foo end end class FooOld include ActiveSupport::OldTryable def foo end end foo_new = FooNew.new foo_old = FooOld.new require 'benchmark/ips' Benchmark.ips do |x| x.report("old") { foo_old.try(:foo) } x.report("new") { foo_new.try(:foo) } x.compare! end # Warming up -------------------------------------- # old 144.178k i/100ms # new 172.371k i/100ms # Calculating ------------------------------------- # old 2.181M (± 8.0%) i/s - 10.813M in 5.001419s # new 2.889M (± 7.7%) i/s - 14.479M in 5.051760s # Comparison: # new: 2888691.7 i/s # old: 2180740.7 i/s - 1.32x slower ``` Also reduces memory. On https://www.codetriage.com i’m seeing 1.5% fewer object allocations per request (in object count). Before: Total allocated: 1014475 bytes (8525 objects) After: Total allocated: 1015499 bytes (8389 objects)
* | | | Update the comments for TimeWithZone subtraction (#33721)Rob Race2018-08-281-2/+10
| |/ / |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Update the comments for TimeWithZone subtraction While reading the description/documentation comments for the subtraction method, it was confusing. While in practical usage, the returned values make sense. It seems as though the explanation could be a bit clearer. * Removed erroneous closing parenthesis [ci skip] [Rob Race + Ryuta Kamizono]
* | | Merge pull request #33162 from utilum/stop_using_mochaKasper Timm Hansen2018-08-221-0/+29
|\ \ \ | |/ / |/| | Stop using Mocha
| * | Add method_call_assertions and use them instead of Mochautilum2018-08-131-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Six Mocha calls prove quite resistant to Minitestification. For example, if we replace ``` ActiveRecord::Associations::HasManyAssociation .any_instance .expects(:reader) .never ``` with `assert_not_called`, Minitest wisely raises ``` NameError: undefined method `reader' for class `ActiveRecord::Associations::HasManyAssociation' ``` as `:reader` comes from a deeply embedded abstract class, `ActiveRecord::Associations::CollectionAssociation`. This patch tackles this difficulty by adding `ActiveSupport::Testing::MethodCallAsserts#assert_called_on_instance_of` which injects a stubbed method into `klass`, and verifies the number of times it is called, similar to `assert_called`. It also adds a convenience method, `assert_not_called_on_instance_of`, mirroring `assert_not_called`. It uses the new method_call_assertions to replace the remaining Mocha calls in `ActiveRecord` tests. [utilum + bogdanvlviv + kspath]
* | | Improve documentation of Procs as :if / :unless options for callbacksFabian Schwahn2018-08-201-0/+8
| | |
* | | Merge pull request #31132 from ↵Ryuta Kamizono2018-08-201-0/+5
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | emaxi/feature/add-missing-documentation-option-to-number-to-currency Add missing documentation option to number_to_currency [ci skip]
| * | | Add missing documentation options to number_to_currency [ci skip]emaxi2018-07-111-0/+5
| | | |
* | | | Merge pull request #33499 from lsylvester/caller-ignore-pathsKasper Timm Hansen2018-08-151-0/+23
|\ \ \ \ | | | | | | | | | | use BacktraceCleaner for ActiveRecord verbose logging
| * | | | Use backtrace cleaner to clean up backtrace for verbose query logsLachlan Sylvester2018-08-141-0/+23
| | |/ / | |/| |
* | | | Refactor `Array#extract!`bogdanvlviv2018-08-141-7/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Avoid allocating the second array by using `Array#reject!` instead of `Enumerable#partition` in `Array#extract!`. There are benchmarks in order to ensure that the changes speed up the method: ``` begin require "bundler/inline" rescue LoadError => e $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" raise e end class Array def extract_v1!(&block) unless block_given? to_enum(:extract!) { size } else extracted_elements, other_elements = partition(&block) replace(other_elements) extracted_elements end end def extract_v2! return to_enum(:extract!) { size } unless block_given? extracted_elements = [] reject! do |element| extracted_elements << element if yield(element) end extracted_elements end end gemfile(true) do source "https://rubygems.org" gem "benchmark-ips" end arrays_for_partition = Array.new(1000) { (0..10000).to_a } arrays_for_extract_v1 = Array.new(1000) { (0..10000).to_a } arrays_for_extract_v2 = Array.new(1000) { (0..10000).to_a } Benchmark.ips do |x| x.report("Array#partition") do arrays_for_partition.each do |numbers| odd_numbers, numbers = numbers.partition { |number| number.odd? } numbers end end x.report("Array#extract_v1!") do arrays_for_extract_v1.each do |numbers| odd_numbers = numbers.extract_v1! { |number| number.odd? } numbers end end x.report("Array#extract_v2!") do arrays_for_extract_v2.each do |numbers| odd_numbers = numbers.extract_v2! { |number| number.odd? } numbers end end x.compare! end ``` The result of the benchmarks: ``` ruby -v ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux] ``` ``` Fetching gem metadata from https://rubygems.org/. Resolving dependencies... Using benchmark-ips 2.7.2 Using bundler 1.16.1 Warming up -------------------------------------- Array#partition 1.000 i/100ms Array#extract_v1! 1.000 i/100ms Array#extract_v2! 1.000 i/100ms Calculating ------------------------------------- Array#partition 1.390 (± 0.0%) i/s - 7.000 in 5.044843s Array#extract_v1! 2.781 (± 0.0%) i/s - 14.000 in 5.050589s Array#extract_v2! 3.151 (± 0.0%) i/s - 16.000 in 5.080608s Comparison: Array#extract_v2!: 3.2 i/s Array#extract_v1!: 2.8 i/s - 1.13x slower Array#partition: 1.4 i/s - 2.27x slower ``` Avoid `unless`/`else` in favour of an early return. The double-negative of that `else` can be confusing, even though the code layout is nearly the same. Also using of early return would improve `git diff` if we needed to change this method.
* | | | Add `Array#extract!`bogdanvlviv2018-08-142-0/+22
|/ / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The method removes and returns the elements for which the block returns a true value. If no block is given, an Enumerator is returned instead. ``` numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] odd_numbers = numbers.extract! { |number| number.odd? } # => [1, 3, 5, 7, 9] numbers # => [0, 2, 4, 6, 8] ```
* | | 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.