diff options
Diffstat (limited to 'activesupport/lib/active_support')
8 files changed, 55 insertions, 38 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 430a35fbaf..3807ee63b1 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -12,7 +12,7 @@ class Array # pass an option key that doesn't exist in the list below, it will raise an # <tt>ArgumentError</tt>. # - # Options: + # ==== Options # # * <tt>:words_connector</tt> - The sign or word used to join the elements # in arrays with two or more elements (default: ", "). @@ -24,6 +24,8 @@ class Array # the connector options defined on the 'support.array' namespace in the # corresponding dictionary file. # + # ==== Examples + # # [].to_sentence # => "" # ['one'].to_sentence # => "one" # ['one', 'two'].to_sentence # => "one and two" @@ -38,10 +40,10 @@ class Array # ['one', 'two', 'three'].to_sentence(words_connector: ' or ', last_word_connector: ' or at least ') # # => "one or two or at least three" # - # Examples using <tt>:locale</tt> option: + # Using <tt>:locale</tt> option: # # # Given this locale dictionary: - # # + # # # # es: # # support: # # array: diff --git a/activesupport/lib/active_support/core_ext/array/uniq_by.rb b/activesupport/lib/active_support/core_ext/array/uniq_by.rb index ca3b7748cd..23573c97de 100644 --- a/activesupport/lib/active_support/core_ext/array/uniq_by.rb +++ b/activesupport/lib/active_support/core_ext/array/uniq_by.rb @@ -1,5 +1,5 @@ class Array - # *DEPRECATED*: Use +Array#uniq+ instead. + # *DEPRECATED*: Use <tt>Array#uniq</tt> instead. # # Returns a unique array based on the criteria in the block. # @@ -9,7 +9,7 @@ class Array uniq(&block) end - # *DEPRECATED*: Use +Array#uniq!+ instead. + # *DEPRECATED*: Use <tt>Array#uniq!</tt> instead. # # Same as +uniq_by+, but modifies +self+. def uniq_by!(&block) diff --git a/activesupport/lib/active_support/core_ext/benchmark.rb b/activesupport/lib/active_support/core_ext/benchmark.rb index 2d110155a5..eb25b2bc44 100644 --- a/activesupport/lib/active_support/core_ext/benchmark.rb +++ b/activesupport/lib/active_support/core_ext/benchmark.rb @@ -1,6 +1,13 @@ require 'benchmark' class << Benchmark + # Benchmark realtime in milliseconds. + # + # Benchmark.realtime { User.all } + # # => 8.0e-05 + # + # Benchmark.ms { User.all } + # # => 0.074 def ms 1000 * realtime { yield } end diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb index a1b3f79748..c62bb41416 100644 --- a/activesupport/lib/active_support/core_ext/string/filters.rb +++ b/activesupport/lib/active_support/core_ext/string/filters.rb @@ -50,6 +50,6 @@ class String length_with_room_for_omission end - self[0...stop] + options[:omission] + "#{self[0...stop]}#{options[:omission]}" end end diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index 6522145572..0b506a6030 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -41,7 +41,7 @@ class String # # If the optional parameter +locale+ is specified, # the word will be singularized as a word of that language. - # By default, this paramter is set to <tt>:en</tt>. + # By default, this parameter is set to <tt>:en</tt>. # You must define your own inflection rules for languages other than English. # # 'posts'.singularize # => "post" diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 5c985601f4..c45358bba9 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -193,10 +193,6 @@ module ActiveSupport class InstrumentationRegistry # :nodoc: extend ActiveSupport::PerThreadRegistry - class << self - delegate :instrumenter_for, to: :instance - end - def initialize @registry = {} end diff --git a/activesupport/lib/active_support/per_thread_registry.rb b/activesupport/lib/active_support/per_thread_registry.rb index fb9a4c0e33..aa682fb36c 100644 --- a/activesupport/lib/active_support/per_thread_registry.rb +++ b/activesupport/lib/active_support/per_thread_registry.rb @@ -1,41 +1,52 @@ module ActiveSupport - # This module creates a local registry class inside each thread. It provides - # basic methods which will store thread locals in a single class. This - # prevents the proliferation of too many thread locals and allows you to - # explicitly keep track of each of the variables you're using as thread - # locals in a class which includes this module. + # This module is used to encapsulate access to thread local variables. # - # For example, instead of using a bunch of different thread locals to keep - # track of some variables like so: + # Instead of polluting the thread locals namespace: # - # Thread.current[:active_record_connection_handler] = connection_handler - # Thread.current[:active_record_sql_runtime] = sql_runtime + # Thread.current[:connection_handler] # - # You could use the following class which implements the +PerThreadRegistry+ - # module: + # you define a class that extends this module: # - # class NewRegistry - # extend ActiveSupport::PerThreadRegistry + # module ActiveRecord + # class RuntimeRegistry + # extend ActiveSupport::PerThreadRegistry # - # attr_accessor :connection_handler, :sql_runtime + # attr_accessor :connection_handler + # end # end # - # NewRegistry.instance.connection_handler = connection_handler - # NewRegistry.instance.sql_runtime = sql_runtime + # and invoke the declared instance accessors as class methods. So # - # The new way of keeping track of the thread locals will create a new local - # inside of +Thread.current+ with a key which is the name of the extended - # class. Now you can easily access per thread variables by just calling the - # variable name on the registry. + # ActiveRecord::RuntimeRegistry.connection_handler = connection_handler + # + # sets a connection handler local to the current thread, and + # + # ActiveRecord::RuntimeRegistry.connection_handler + # + # returns a connection handler local to the current thread. + # + # This feature is accomplished by instantiating the class and storing the + # instance as a thread local keyed by the class name. In the example above + # a key "ActiveRecord::RuntimeRegistry" is stored in <tt>Thread.current</tt>. + # The class methods proxy to said thread local instance. + # + # If the class has an initializer, it must accept no arguments. module PerThreadRegistry - def instance - Thread.current[self.name] ||= new - end - protected - def method_missing(*args, &block) - instance.public_send(*args, &block) + def method_missing(name, *args, &block) # :nodoc: + # Caches the method definition as a singleton method of the receiver. + define_singleton_method(name) do |*a, &b| + per_thread_registry_instance.public_send(name, *a, &b) + end + + send(name, *args, &block) + end + + private + + def per_thread_registry_instance + Thread.current[name] ||= new end end end diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 21a0620c22..3cf82a24b9 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -5,7 +5,7 @@ module ActiveSupport # The TimeZone class serves as a wrapper around TZInfo::Timezone instances. # It allows us to do the following: # - # * Limit the set of zones provided by TZInfo to a meaningful subset of 142 + # * Limit the set of zones provided by TZInfo to a meaningful subset of 146 # zones. # * Retrieve and display zones with a friendlier name # (e.g., "Eastern Time (US & Canada)" instead of "America/New_York"). @@ -177,6 +177,7 @@ module ActiveSupport "Wellington" => "Pacific/Auckland", "Nuku'alofa" => "Pacific/Tongatapu", "Tokelau Is." => "Pacific/Fakaofo", + "Chatham Is." => "Pacific/Chatham", "Samoa" => "Pacific/Apia" } |