From f42562f97bb791a7662fce0106a93eec211b2803 Mon Sep 17 00:00:00 2001 From: "Oriol Gual and Josep M. Bach" Date: Mon, 28 Feb 2011 14:31:29 +0100 Subject: Make ActiveSupport::Configurable work with modules [#6486 state:committed] Signed-off-by: Santiago Pastorino --- activesupport/lib/active_support/configurable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb index 644db0b205..be19189c04 100644 --- a/activesupport/lib/active_support/configurable.rb +++ b/activesupport/lib/active_support/configurable.rb @@ -26,7 +26,7 @@ module ActiveSupport module ClassMethods def config - @_config ||= if superclass.respond_to?(:config) + @_config ||= if respond_to?(:superclass) && superclass.respond_to?(:config) superclass.config.inheritable_copy else # create a new "anonymous" class that will host the compiled reader methods -- cgit v1.2.3 From 726599df984daca45afe5b969c74b416fcd6c11a Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Mon, 28 Feb 2011 10:52:09 -0500 Subject: Remove redundant to_sym call. [#6483 state:committed] Signed-off-by: Santiago Pastorino --- activesupport/lib/active_support/ordered_options.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index 124e1a74f8..b40cbceb7e 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -31,7 +31,7 @@ module ActiveSupport #:nodoc: def method_missing(name, *args) if name.to_s =~ /(.*)=$/ - self[$1.to_sym] = args.first + self[$1] = args.first else self[name] end -- cgit v1.2.3 From 0f8d2794f229175447163d2b5e16d94d2cee5468 Mon Sep 17 00:00:00 2001 From: Josh Kalderimis Date: Sun, 27 Feb 2011 20:24:39 +0100 Subject: updated Time, Date and DateTime current methods in AS to use Time.zone and not Time.zone_default. [#6410 state:committed] --- activesupport/lib/active_support/core_ext/date/calculations.rb | 4 ++-- activesupport/lib/active_support/core_ext/date/zones.rb | 6 +++--- activesupport/lib/active_support/core_ext/date_time/calculations.rb | 3 ++- activesupport/lib/active_support/core_ext/time/calculations.rb | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index f34185f22c..724e076407 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -36,9 +36,9 @@ class Date ::Date.current.tomorrow end - # Returns Time.zone.today when config.time_zone is set, otherwise just returns Date.today. + # Returns Time.zone.today when Time.zone or config.time_zone are set, otherwise just returns Date.today. def current - ::Time.zone_default ? ::Time.zone.today : ::Date.today + ::Time.zone ? ::Time.zone.today : ::Date.today end end diff --git a/activesupport/lib/active_support/core_ext/date/zones.rb b/activesupport/lib/active_support/core_ext/date/zones.rb index 3a83af6be2..a70b47b7bc 100644 --- a/activesupport/lib/active_support/core_ext/date/zones.rb +++ b/activesupport/lib/active_support/core_ext/date/zones.rb @@ -2,10 +2,10 @@ require 'date' require 'active_support/core_ext/time/zones' class Date - # Converts Date to a TimeWithZone in the current zone if Time.zone_default is set, - # otherwise converts Date to a Time via Date#to_time + # Converts Date to a TimeWithZone in the current zone if Time.zone or Time.zone_default + # is set, otherwise converts Date to a Time via Date#to_time def to_time_in_current_zone - if ::Time.zone_default + if ::Time.zone ::Time.zone.local(year, month, day) else to_time diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index 1dc3933e12..8d01376f1d 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -9,8 +9,9 @@ class DateTime ::Time.local(2007).utc_offset.to_r / 86400 end + # Returns Time.zone.now.to_datetime when Time.zone or config.time_zone are set, otherwise returns Time.now.to_datetime. def current - ::Time.zone_default ? ::Time.zone.now.to_datetime : ::Time.now.to_datetime + ::Time.zone ? ::Time.zone.now.to_datetime : ::Time.now.to_datetime end end diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index fa052fa86b..6e4b69f681 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -41,9 +41,9 @@ class Time time_with_datetime_fallback(:local, *args) end - # Returns Time.zone.now when config.time_zone is set, otherwise just returns Time.now. + # Returns Time.zone.now when Time.zone or config.time_zone are set, otherwise just returns Time.now. def current - ::Time.zone_default ? ::Time.zone.now : ::Time.now + ::Time.zone ? ::Time.zone.now : ::Time.now end end -- cgit v1.2.3 From 7b6bfe84f332a3c99656f73cf0251bce0a16ba88 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 1 Mar 2011 17:20:10 -0800 Subject: refactor Reference to a ClassCache object, fix lazy lookup in Middleware so that anonymous classes are supported --- activesupport/lib/active_support/dependencies.rb | 43 ++++++++++++++++++------ 1 file changed, 32 insertions(+), 11 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index dab6fdbac6..94a8608aeb 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -524,31 +524,52 @@ module ActiveSupport #:nodoc: explicitly_unloadable_constants.each { |const| remove_constant const } end - class Reference - @@constants = Hash.new { |h, k| h[k] = Inflector.constantize(k) } + class ClassCache + def initialize + @store = Hash.new { |h, k| h[k] = Inflector.constantize(k) } + end + + def empty? + @store.empty? + end + + def key?(key) + @store.key?(key) + end - attr_reader :name + def []=(key, value) + return unless key.respond_to?(:name) - def initialize(name) - @name = name.to_s - @@constants[@name] = name if name.respond_to?(:name) + raise(ArgumentError, 'anonymous classes cannot be cached') unless key.name + + @store[key.name] = value + end + + def [](key) + key = key.name if key.respond_to?(:name) + + @store[key] end + alias :get :[] - def get - @@constants[@name] + def new(name) + self[name] = name + self end - def self.clear! - @@constants.clear + def clear! + @store.clear end end + Reference = ClassCache.new + def ref(name) references[name] ||= Reference.new(name) end def constantize(name) - ref(name).get + ref(name).get(name) end # Determine if the given constant has been automatically loaded. -- cgit v1.2.3 From f345e2380cac2560f3bbd80defe1ef485e0d564e Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Tue, 1 Mar 2011 17:43:45 -0800 Subject: yo dawg, directly use the class cache rather than the cache of the cache --- activesupport/lib/active_support/dependencies.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 94a8608aeb..d5c51ca417 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -47,9 +47,6 @@ module ActiveSupport #:nodoc: mattr_accessor :autoloaded_constants self.autoloaded_constants = [] - mattr_accessor :references - self.references = {} - # An array of constant names that need to be unloaded on every request. Used # to allow arbitrary constants to be marked for unloading. mattr_accessor :explicitly_unloadable_constants @@ -565,11 +562,11 @@ module ActiveSupport #:nodoc: Reference = ClassCache.new def ref(name) - references[name] ||= Reference.new(name) + Reference.new(name) end def constantize(name) - ref(name).get(name) + Reference.get(name) end # Determine if the given constant has been automatically loaded. -- cgit v1.2.3 From 66245441d4471f29043433f6cf789498cf35b96c Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Mar 2011 09:18:05 -0800 Subject: adding backwards compat for class cache references. <3<3 --- activesupport/lib/active_support/dependencies.rb | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index d5c51ca417..97e20bdaf4 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -549,10 +549,21 @@ module ActiveSupport #:nodoc: end alias :get :[] + class Getter # :nodoc: + def initialize(name) + @name = name + end + + def get + Reference.get @name + end + end + def new(name) self[name] = name - self + Getter.new(name) end + deprecate :new def clear! @store.clear -- cgit v1.2.3 From 69e348013bc3ce4289c5fefc29c1aacc47048c0d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Mar 2011 09:31:40 -0800 Subject: adding deprecation noticies to deprecated class cache methods --- activesupport/lib/active_support/dependencies.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 97e20bdaf4..4abeb74c45 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -557,6 +557,7 @@ module ActiveSupport #:nodoc: def get Reference.get @name end + deprecate :get end def new(name) @@ -565,6 +566,11 @@ module ActiveSupport #:nodoc: end deprecate :new + def store(name) + self[name] = name + self + end + def clear! @store.clear end @@ -575,7 +581,14 @@ module ActiveSupport #:nodoc: def ref(name) Reference.new(name) end + deprecate :ref + + # Store a reference to a class +klass+. + def reference(klass) + Reference.store klass + end + # Get the reference for class named +name+. def constantize(name) Reference.get(name) end -- cgit v1.2.3 From 72405efe64c7f2d4fc759744b8facbd781f56165 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Mar 2011 10:23:04 -0800 Subject: anonymous classes have blank names on ruby 1.8 --- activesupport/lib/active_support/dependencies.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 4abeb74c45..9776eb6a79 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -537,7 +537,7 @@ module ActiveSupport #:nodoc: def []=(key, value) return unless key.respond_to?(:name) - raise(ArgumentError, 'anonymous classes cannot be cached') unless key.name + raise(ArgumentError, 'anonymous classes cannot be cached') if key.name.blank? @store[key.name] = value end -- cgit v1.2.3 From 272ede9b9abeba6c987b66f047e24b472e99921d Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Mar 2011 10:42:43 -0800 Subject: require deprecation so that we can deprecate methods! --- activesupport/lib/active_support/dependencies.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 9776eb6a79..47596a389d 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -5,6 +5,7 @@ require 'active_support/core_ext/module/aliasing' require 'active_support/core_ext/module/attribute_accessors' require 'active_support/core_ext/module/introspection' require 'active_support/core_ext/module/anonymous' +require 'active_support/core_ext/module/deprecation' require 'active_support/core_ext/object/blank' require 'active_support/core_ext/load_error' require 'active_support/core_ext/name_error' -- cgit v1.2.3 From b247c8d71a54d684a1c307986a03d1759bbc20e0 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Mar 2011 14:04:41 -0800 Subject: * LocalCache strategy is now a real middleware class, not an anonymous class posing for pictures. --- .../active_support/cache/strategy/local_cache.rb | 52 ++++++++++++---------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index 4dce35f1c9..99b26b19fe 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -50,34 +50,40 @@ module ActiveSupport end end - # Middleware class can be inserted as a Rack handler to be local cache for the - # duration of request. - def middleware - @middleware ||= begin - klass = Class.new - klass.class_eval(<<-EOS, __FILE__, __LINE__ + 1) - class << self - def name - "ActiveSupport::Cache::Strategy::LocalCache" - end - alias :to_s :name - end + #-- + # This class wraps up local storage for middlewares. Only the middleware method should + # construct them. + class Middleware # :nodoc: + attr_reader :name, :thread_local_key + alias :to_s :name - def initialize(app) - @app = app - end + def initialize(name, thread_local_key) + @name = name + @thread_local_key = thread_local_key + @app = nil + end - def call(env) - Thread.current[:#{thread_local_key}] = LocalStore.new - @app.call(env) - ensure - Thread.current[:#{thread_local_key}] = nil - end - EOS - klass + def new(app) + @app = app + self + end + + def call(env) + Thread.current[thread_local_key] = LocalStore.new + @app.call(env) + ensure + Thread.current[thread_local_key] = nil end end + # Middleware class can be inserted as a Rack handler to be local cache for the + # duration of request. + def middleware + @middleware ||= Middleware.new( + "ActiveSupport::Cache::Strategy::LocalCache", + thread_local_key) + end + def clear(options = nil) # :nodoc: local_cache.clear(options) if local_cache super -- cgit v1.2.3 From dc89e29f4937a68e91cd7572f45f06c523430c23 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 2 Mar 2011 15:17:13 -0800 Subject: remove to_s implementation so that inspect is helpful --- activesupport/lib/active_support/cache/strategy/local_cache.rb | 1 - 1 file changed, 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/cache/strategy/local_cache.rb b/activesupport/lib/active_support/cache/strategy/local_cache.rb index 99b26b19fe..0649a058aa 100644 --- a/activesupport/lib/active_support/cache/strategy/local_cache.rb +++ b/activesupport/lib/active_support/cache/strategy/local_cache.rb @@ -55,7 +55,6 @@ module ActiveSupport # construct them. class Middleware # :nodoc: attr_reader :name, :thread_local_key - alias :to_s :name def initialize(name, thread_local_key) @name = name -- cgit v1.2.3 From 7872cc992bac76e976334d0c20649d69aad5652e Mon Sep 17 00:00:00 2001 From: Diego Carrion Date: Fri, 4 Mar 2011 12:04:22 -0300 Subject: refactored Time#<=> and DateTime#<=> by removing unnecessary calls without losing performance Signed-off-by: Santiago Pastorino --- .../lib/active_support/core_ext/date_time/calculations.rb | 10 ++-------- .../lib/active_support/core_ext/time/calculations.rb | 13 ++----------- activesupport/lib/active_support/time_with_zone.rb | 2 +- 3 files changed, 5 insertions(+), 20 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index 8d01376f1d..8d924ad420 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -1,6 +1,4 @@ require 'rational' unless RUBY_VERSION >= '1.9.2' -require 'active_support/core_ext/object/acts_like' -require 'active_support/core_ext/time/zones' class DateTime class << self @@ -105,11 +103,7 @@ class DateTime end # Layers additional behavior on DateTime#<=> so that Time and ActiveSupport::TimeWithZone instances can be compared with a DateTime - def compare_with_coercion(other) - other = other.comparable_time if other.respond_to?(:comparable_time) - other = other.to_datetime unless other.acts_like?(:date) - compare_without_coercion(other) + def <=>(other) + super other.to_datetime end - alias_method :compare_without_coercion, :<=> - alias_method :<=>, :compare_with_coercion end diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 6e4b69f681..7e134db118 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -1,7 +1,4 @@ require 'active_support/duration' -require 'active_support/core_ext/date/acts_like' -require 'active_support/core_ext/date/calculations' -require 'active_support/core_ext/date_time/conversions' class Time COMMON_YEAR_DAYS_IN_MONTH = [nil, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] @@ -283,14 +280,8 @@ class Time # Layers additional behavior on Time#<=> so that DateTime and ActiveSupport::TimeWithZone instances # can be chronologically compared with a Time def compare_with_coercion(other) - # if other is an ActiveSupport::TimeWithZone, coerce a Time instance from it so we can do <=> comparison - other = other.comparable_time if other.respond_to?(:comparable_time) - if other.acts_like?(:date) - # other is a Date/DateTime, so coerce self #to_datetime and hand off to DateTime#<=> - to_datetime.compare_without_coercion(other) - else - compare_without_coercion(other) - end + # we're avoiding Time#to_datetime cause it's expensive + other.is_a?(Time) ? compare_without_coercion(other.to_time) : to_datetime <=> other end alias_method :compare_without_coercion, :<=> alias_method :<=>, :compare_with_coercion diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 3da216ac78..c66aa78ce8 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -281,7 +281,7 @@ module ActiveSupport # A TimeWithZone acts like a Time, so just return +self+. def to_time - self + utc end def to_datetime -- cgit v1.2.3 From 4c27ad0c23d8d8889221d5234496b39f1cc9bdb8 Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Sat, 26 Feb 2011 12:59:27 -0500 Subject: Correct example that did not do what it claimed. Rework explanation. --- .../lib/active_support/core_ext/hash/reverse_merge.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb b/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb index a82cdfc360..87a7bebd7b 100644 --- a/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb +++ b/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb @@ -6,14 +6,14 @@ class Hash # options.reverse_merge! :size => 25, :velocity => 10 # end # - # Using merge, the above example would look as follows: + # The default :size and :velocity are only set if the +options+ hash passed in doesn't already + # have the respective key. + # + # As contrast, using Ruby's built in merge would require writing the following: # # def setup(options = {}) - # { :size => 25, :velocity => 10 }.merge(options) + # options = { :size => 25, :velocity => 10 }.merge(options) # end - # - # The default :size and :velocity are only set if the +options+ hash passed in doesn't already - # have the respective key. def reverse_merge(other_hash) other_hash.merge(self) end -- cgit v1.2.3 From ac4c5e97226fd70510ed49872f0ae41ba0d71c52 Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Sat, 26 Feb 2011 13:36:47 -0500 Subject: Example descriptions and their examples were flipped. Fix. --- activesupport/lib/active_support/core_ext/string/filters.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb index e15a1df9c9..d478ee0ef6 100644 --- a/activesupport/lib/active_support/core_ext/string/filters.rb +++ b/activesupport/lib/active_support/core_ext/string/filters.rb @@ -25,13 +25,13 @@ class String # "Once upon a time in a world far far away".truncate(27) # # => "Once upon a time in a wo..." # - # The last characters will be replaced with the :omission string (defaults to "...") - # for a total length not exceeding :length: + # Pass a :separator to truncate +text+ at a natural break: # # "Once upon a time in a world far far away".truncate(27, :separator => ' ') # # => "Once upon a time in a..." # - # Pass a :separator to truncate +text+ at a natural break: + # The last characters will be replaced with the :omission string (defaults to "...") + # for a total length not exceeding :length: # # "And they found that many people were sleeping better.".truncate(25, :omission => "... (continued)") # # => "And they f... (continued)" -- cgit v1.2.3 From f305c608166e72217d8f47b227deb4db233cd879 Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Sat, 26 Feb 2011 14:29:22 -0500 Subject: Clarify comment by removing french reference ('a la'). Should improve readability for non-native english speakers. --- activesupport/lib/active_support/core_ext/enumerable.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/enumerable.rb b/activesupport/lib/active_support/core_ext/enumerable.rb index 6ecedc26ef..6d7f771b5d 100644 --- a/activesupport/lib/active_support/core_ext/enumerable.rb +++ b/activesupport/lib/active_support/core_ext/enumerable.rb @@ -94,7 +94,7 @@ module Enumerable end # Returns true if the collection has more than 1 element. Functionally equivalent to collection.size > 1. - # Works with a block too ala any?, so people.many? { |p| p.age > 26 } # => returns true if more than 1 person is over 26. + # Can be called with a block too, much like any?, so people.many? { |p| p.age > 26 } returns true if more than 1 person is over 26. def many?(&block) size = block_given? ? select(&block).size : self.size size > 1 -- cgit v1.2.3 From ea6a2b7c111cd3794b2ee41bc60a4071631d01aa Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Sun, 27 Feb 2011 16:45:57 -0500 Subject: Fix incorrect word. --- activesupport/lib/active_support/log_subscriber/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/log_subscriber/test_helper.rb b/activesupport/lib/active_support/log_subscriber/test_helper.rb index 52a64383a2..3227600078 100644 --- a/activesupport/lib/active_support/log_subscriber/test_helper.rb +++ b/activesupport/lib/active_support/log_subscriber/test_helper.rb @@ -27,7 +27,7 @@ module ActiveSupport # up the queue, subscriptions and turning colors in logs off. # # The messages are available in the @logger instance, which is a logger with limited - # powers (it actually do not send anything to your output), and you can collect them + # powers (it actually does not send anything to your output), and you can collect them # doing @logger.logged(level), where level is the level used in logging, like info, # debug, warn and so on. # -- cgit v1.2.3 From 67af97c4c1561f28801a89a4d2c1c97b419e9fa4 Mon Sep 17 00:00:00 2001 From: Ben Orenstein Date: Sun, 27 Feb 2011 20:22:55 -0500 Subject: Fix incorrect example. --- activesupport/lib/active_support/ordered_options.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/ordered_options.rb b/activesupport/lib/active_support/ordered_options.rb index b40cbceb7e..8d8e6ebc58 100644 --- a/activesupport/lib/active_support/ordered_options.rb +++ b/activesupport/lib/active_support/ordered_options.rb @@ -2,13 +2,13 @@ require 'active_support/ordered_hash' # Usually key value pairs are handled something like this: # -# h = ActiveSupport::OrderedOptions.new +# h = {} # h[:boy] = 'John' # h[:girl] = 'Mary' # h[:boy] # => 'John' # h[:girl] # => 'Mary' # -# Using OrderedOptions above code could be reduced to: +# Using OrderedOptions, the above code could be reduced to: # # h = ActiveSupport::OrderedOptions.new # h.boy = 'John' -- cgit v1.2.3 From 3eca9d5b43c270d01ac92491281dd96a5ceaa783 Mon Sep 17 00:00:00 2001 From: "Jonathon D. Jones" Date: Thu, 3 Mar 2011 18:10:33 -0500 Subject: Adds link to Object.blank? from Object.present? --- activesupport/lib/active_support/core_ext/object/blank.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 51670b148f..f70853073a 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -13,7 +13,7 @@ class Object respond_to?(:empty?) ? empty? : !self end - # An object is present if it's not blank. + # An object is present if it's not #blank?. def present? !blank? end -- cgit v1.2.3 From 273700cbd0f8e9013fd4b4a33ab310e4ac02ff62 Mon Sep 17 00:00:00 2001 From: "R.T. Lechow" Date: Thu, 3 Mar 2011 23:14:18 -0500 Subject: Active Support typos. --- activesupport/lib/active_support/core_ext/object/try.rb | 2 +- activesupport/lib/active_support/core_ext/string/multibyte.rb | 2 +- activesupport/lib/active_support/core_ext/string/output_safety.rb | 2 +- activesupport/lib/active_support/dependencies.rb | 2 +- activesupport/lib/active_support/log_subscriber/test_helper.rb | 2 +- activesupport/lib/active_support/multibyte/unicode.rb | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/try.rb b/activesupport/lib/active_support/core_ext/object/try.rb index ff812234e3..04619124a1 100644 --- a/activesupport/lib/active_support/core_ext/object/try.rb +++ b/activesupport/lib/active_support/core_ext/object/try.rb @@ -21,7 +21,7 @@ class Object # Person.try(:find, 1) # @people.try(:collect) {|p| p.name} # - # Without a method argument try will yield to the block unless the reciever is nil. + # Without a method argument try will yield to the block unless the receiver is nil. # @person.try { |p| "#{p.first_name} #{p.last_name}" } #-- # +try+ behaves like +Object#send+, unless called on +NilClass+. diff --git a/activesupport/lib/active_support/core_ext/string/multibyte.rb b/activesupport/lib/active_support/core_ext/string/multibyte.rb index 0b974f5e0a..41de4d6435 100644 --- a/activesupport/lib/active_support/core_ext/string/multibyte.rb +++ b/activesupport/lib/active_support/core_ext/string/multibyte.rb @@ -9,7 +9,7 @@ class String # # In Ruby 1.8 and older it creates and returns an instance of the ActiveSupport::Multibyte::Chars class which # encapsulates the original string. A Unicode safe version of all the String methods are defined on this proxy - # class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsuled string. + # class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsulated string. # # name = 'Claus Müller' # name.reverse # => "rell??M sualC" diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index c930abc003..addd4dab95 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -24,7 +24,7 @@ class ERB end end - # Aliasing twice issues a warning "dicarding old...". Remove first to avoid it. + # Aliasing twice issues a warning "discarding old...". Remove first to avoid it. remove_method(:h) alias h html_escape diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index 47596a389d..dc10f78104 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -513,7 +513,7 @@ module ActiveSupport #:nodoc: # to its class/module if it implements +before_remove_const+. # # The callback implementation should be restricted to cleaning up caches, etc. - # as the enviroment will be in an inconsistent state, e.g. other constants + # as the environment will be in an inconsistent state, e.g. other constants # may have already been unloaded and not accessible. def remove_unloadable_constants! autoloaded_constants.each { |const| remove_constant const } diff --git a/activesupport/lib/active_support/log_subscriber/test_helper.rb b/activesupport/lib/active_support/log_subscriber/test_helper.rb index 3227600078..392e33edbc 100644 --- a/activesupport/lib/active_support/log_subscriber/test_helper.rb +++ b/activesupport/lib/active_support/log_subscriber/test_helper.rb @@ -23,7 +23,7 @@ module ActiveSupport # end # # All you need to do is to ensure that your log subscriber is added to Rails::Subscriber, - # as in the second line of the code above. The test helpers is reponsible for setting + # as in the second line of the code above. The test helpers are responsible for setting # up the queue, subscriptions and turning colors in logs off. # # The messages are available in the @logger instance, which is a logger with limited diff --git a/activesupport/lib/active_support/multibyte/unicode.rb b/activesupport/lib/active_support/multibyte/unicode.rb index 1139783b65..513f83e445 100644 --- a/activesupport/lib/active_support/multibyte/unicode.rb +++ b/activesupport/lib/active_support/multibyte/unicode.rb @@ -247,7 +247,7 @@ module ActiveSupport if is_unused || is_restricted bytes[i] = tidy_byte(byte) elsif is_cont - # Not expecting contination byte? Clean up. Otherwise, now expect one less. + # Not expecting continuation byte? Clean up. Otherwise, now expect one less. conts_expected == 0 ? bytes[i] = tidy_byte(byte) : conts_expected -= 1 else if conts_expected > 0 -- cgit v1.2.3 From 5f99a899a82c7201b7047e4e95d591a572a9099b Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 5 Mar 2011 11:08:05 +0100 Subject: copy-edits 108561f --- activesupport/lib/active_support/core_ext/object/blank.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index f70853073a..d0c1ea8326 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -13,7 +13,7 @@ class Object respond_to?(:empty?) ? empty? : !self end - # An object is present if it's not #blank?. + # An object is present if it's not blank?. def present? !blank? end -- cgit v1.2.3 From 20768176292cbcb883ab152b4aa9ed8c664771cd Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 5 Mar 2011 11:54:06 +0100 Subject: revises the RDoc of Hash#reverse_merge --- .../active_support/core_ext/hash/reverse_merge.rb | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb b/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb index 87a7bebd7b..01863a162b 100644 --- a/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb +++ b/activesupport/lib/active_support/core_ext/hash/reverse_merge.rb @@ -1,25 +1,19 @@ class Hash - # Allows for reverse merging two hashes where the keys in the calling hash take precedence over those - # in the other_hash. This is particularly useful for initializing an option hash with default values: + # Merges the caller into +other_hash+. For example, # - # def setup(options = {}) - # options.reverse_merge! :size => 25, :velocity => 10 - # end + # options = options.reverse_merge(:size => 25, :velocity => 10) # - # The default :size and :velocity are only set if the +options+ hash passed in doesn't already - # have the respective key. + # is equivalent to # - # As contrast, using Ruby's built in merge would require writing the following: + # options = {:size => 25, :velocity => 10}.merge(options) # - # def setup(options = {}) - # options = { :size => 25, :velocity => 10 }.merge(options) - # end + # This is particularly useful for initializing an options hash + # with default values. def reverse_merge(other_hash) other_hash.merge(self) end - # Performs the opposite of merge, with the keys and values from the first hash taking precedence over the second. - # Modifies the receiver in place. + # Destructive +reverse_merge+. def reverse_merge!(other_hash) # right wins if there is no left merge!( other_hash ){|key,left,right| left } -- cgit v1.2.3