diff options
Diffstat (limited to 'activesupport')
25 files changed, 71 insertions, 50 deletions
diff --git a/activesupport/CHANGELOG.md b/activesupport/CHANGELOG.md index 450669968b..f5f2aa85ef 100644 --- a/activesupport/CHANGELOG.md +++ b/activesupport/CHANGELOG.md @@ -1,5 +1,11 @@ ## Rails 4.0.0 (unreleased) ## +* Deprecate `ActiveSupport::BasicObject` in favor of `ActiveSupport::ProxyObject`. + This class is used for proxy classes. It avoids confusion with Ruby's BasicObject + class. + + *Francesco Rodriguez* + * Patched Marshal#load to work with constant autoloading. Fixes autoloading with cache stores that relay on Marshal(MemCacheStore and FileStore). [fixes #8167] diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index 4e397ea110..b602686114 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -40,6 +40,7 @@ module ActiveSupport eager_autoload do autoload :BacktraceCleaner autoload :BasicObject + autoload :ProxyObject autoload :Benchmarkable autoload :Cache autoload :Callbacks diff --git a/activesupport/lib/active_support/basic_object.rb b/activesupport/lib/active_support/basic_object.rb index 6ccb0cd525..242b766b58 100644 --- a/activesupport/lib/active_support/basic_object.rb +++ b/activesupport/lib/active_support/basic_object.rb @@ -1,13 +1,7 @@ -module ActiveSupport - # A class with no predefined methods that behaves similarly to Builder's - # BlankSlate. Used for proxy classes. - class BasicObject < ::BasicObject - undef_method :== - undef_method :equal? +require 'active_support/deprecation' - # Let ActiveSupport::BasicObject at least raise exceptions. - def raise(*args) - ::Object.send(:raise, *args) - end - end +module ActiveSupport + # :nodoc: + # Deprecated in favor of ActiveSupport::ProxyObject + BasicObject = Deprecation::DeprecatedConstantProxy.new('ActiveSupport::BasicObject', 'ActiveSupport::ProxyObject') end diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index 9a53870b3d..fdec2de1d5 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -582,7 +582,7 @@ module ActiveSupport end # Returns the size of the cached value. This could be less than - # <tt>value.size</tt> if the data is compressed. + # <tt>value.size</tt> if the data is compressed. def size if defined?(@s) @s diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 8199f431f1..3a8353857e 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -14,7 +14,7 @@ module ActiveSupport # Mixing in this module allows you to define the events in the object's # lifecycle that will support callbacks (via +ClassMethods.define_callbacks+), # set the instance methods, procs, or callback objects to be called (via - # +ClassMethods.set_callback+), and run the installed callbacks at the + # +ClassMethods.set_callback+), and run the installed callbacks at the # appropriate times (via +run_callbacks+). # # Three kinds of callbacks are supported: before callbacks, run before a @@ -382,7 +382,7 @@ module ActiveSupport # set_callback :save, :before_meth # # The callback can specified as a symbol naming an instance method; as a - # proc, lambda, or block; as a string to be instance evaluated; or as an + # proc, lambda, or block; as a string to be instance evaluated; or as an # object that responds to a certain method determined by the <tt>:scope</tt> # argument to +define_callback+. # diff --git a/activesupport/lib/active_support/configurable.rb b/activesupport/lib/active_support/configurable.rb index 16d2a6a290..e0d39d509f 100644 --- a/activesupport/lib/active_support/configurable.rb +++ b/activesupport/lib/active_support/configurable.rb @@ -38,7 +38,7 @@ module ActiveSupport end # Allows you to add shortcut so that you don't have to refer to attribute - # through config. Also look at the example for config to contrast. + # through config. Also look at the example for config to contrast. # # Defines both class and instance config accessors. # @@ -75,7 +75,7 @@ module ActiveSupport # end # # User.allowed_access = false - # User.allowed_access # => false + # User.allowed_access # => false # # User.new.allowed_access = true # => NoMethodError # User.new.allowed_access # => NoMethodError @@ -88,7 +88,7 @@ module ActiveSupport # end # # User.allowed_access = false - # User.allowed_access # => false + # User.allowed_access # => false # # User.new.allowed_access = true # => NoMethodError # User.new.allowed_access # => NoMethodError diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index ff06436bd6..64e9945ef5 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -26,7 +26,7 @@ class Array # # [].to_sentence # => "" # ['one'].to_sentence # => "one" - # ['one', 'two'].to_sentence # => "one and two" + # ['one', 'two'].to_sentence # => "one and two" # ['one', 'two', 'three'].to_sentence # => "one, two, and three" # # ['one', 'two'].to_sentence(passing: 'invalid option') @@ -41,7 +41,7 @@ class Array # Examples using <tt>:locale</tt> option: # # # Given this locale dictionary: - # # + # # # # es: # # support: # # array: @@ -53,7 +53,7 @@ class Array # # => "uno y dos" # # ['uno', 'dos', 'tres'].to_sentence(locale: :es) - # # => "uno o dos o al menos tres" + # # => "uno o dos o al menos tres" def to_sentence(options = {}) options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale) diff --git a/activesupport/lib/active_support/core_ext/class/attribute.rb b/activesupport/lib/active_support/core_ext/class/attribute.rb index 1c3d26ead4..1504e18839 100644 --- a/activesupport/lib/active_support/core_ext/class/attribute.rb +++ b/activesupport/lib/active_support/core_ext/class/attribute.rb @@ -72,6 +72,9 @@ class Class instance_reader = options.fetch(:instance_accessor, true) && options.fetch(:instance_reader, true) instance_writer = options.fetch(:instance_accessor, true) && options.fetch(:instance_writer, true) + # We use class_eval here rather than define_method because class_attribute + # may be used in a performance sensitive context therefore the overhead that + # define_method introduces may become significant. attrs.each do |name| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def self.#{name}() nil end diff --git a/activesupport/lib/active_support/core_ext/class/subclasses.rb b/activesupport/lib/active_support/core_ext/class/subclasses.rb index c2e0ebb3d4..9a2dc6e7c5 100644 --- a/activesupport/lib/active_support/core_ext/class/subclasses.rb +++ b/activesupport/lib/active_support/core_ext/class/subclasses.rb @@ -31,7 +31,7 @@ class Class # class Bar < Foo; end # class Baz < Foo; end # - # Foo.subclasses # => [Baz, Bar] + # Foo.subclasses # => [Baz, Bar] def subclasses subclasses, chain = [], descendants chain.each do |k| diff --git a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb index 6c7e876fca..981e8436bf 100644 --- a/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb +++ b/activesupport/lib/active_support/core_ext/hash/indifferent_access.rb @@ -16,7 +16,7 @@ class Hash # converting to an <tt>ActiveSupport::HashWithIndifferentAccess</tt> would not be # desirable. # - # b = { b: 1 } + # b = { b: 1 } # { a: b }.with_indifferent_access['a'] # calls b.nested_under_indifferent_access alias nested_under_indifferent_access with_indifferent_access end diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index 13081995b0..b4c451ace4 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -24,7 +24,7 @@ class Hash # Return a new hash with all keys converted to strings. # - # hash = { name: 'Rob', age: '28' } + # hash = { name: 'Rob', age: '28' } # # hash.stringify_keys # #=> { "name" => "Rob", "age" => "28" } @@ -44,7 +44,7 @@ class Hash # hash = { 'name' => 'Rob', 'age' => '28' } # # hash.symbolize_keys - # #=> { name: "Rob", age: "28" } + # #=> { name: "Rob", age: "28" } def symbolize_keys transform_keys{ |key| key.to_sym rescue key } end @@ -102,7 +102,7 @@ class Hash # This includes the keys from the root hash and from all # nested hashes. # - # hash = { person: { name: 'Rob', age: '28' } } + # hash = { person: { name: 'Rob', age: '28' } } # # hash.deep_stringify_keys # # => { "person" => { "name" => "Rob", "age" => "28" } } @@ -121,10 +121,10 @@ class Hash # they respond to +to_sym+. This includes the keys from the root hash # and from all nested hashes. # - # hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } } + # hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } } # # hash.deep_symbolize_keys - # # => { person: { name: "Rob", age: "28" } } + # # => { person: { name: "Rob", age: "28" } } def deep_symbolize_keys deep_transform_keys{ |key| key.to_sym rescue key } end diff --git a/activesupport/lib/active_support/core_ext/object/deep_dup.rb b/activesupport/lib/active_support/core_ext/object/deep_dup.rb index f55fbc282e..1d639f3af6 100644 --- a/activesupport/lib/active_support/core_ext/object/deep_dup.rb +++ b/activesupport/lib/active_support/core_ext/object/deep_dup.rb @@ -32,7 +32,7 @@ end class Hash # Returns a deep copy of hash. # - # hash = { a: { b: 'b' } } + # hash = { a: { b: 'b' } } # dup = hash.deep_dup # dup[:a][:c] = 'c' # diff --git a/activesupport/lib/active_support/dependencies.rb b/activesupport/lib/active_support/dependencies.rb index b816ecae5a..efd351d741 100644 --- a/activesupport/lib/active_support/dependencies.rb +++ b/activesupport/lib/active_support/dependencies.rb @@ -44,7 +44,7 @@ module ActiveSupport #:nodoc: self.autoload_once_paths = [] # An array of qualified constant names that have been loaded. Adding a name - # to this array will cause it to be unloaded the next time Dependencies are + # to this array will cause it to be unloaded the next time Dependencies are # cleared. mattr_accessor :autoloaded_constants self.autoloaded_constants = [] @@ -344,7 +344,7 @@ module ActiveSupport #:nodoc: # Given +path+, a filesystem path to a ruby file, return an array of # constant paths which would cause Dependencies to attempt to load this - # file. + # file. def loadable_constants_for_path(path, bases = autoload_paths) path = $` if path =~ /\.rb\z/ expanded_path = File.expand_path(path) @@ -394,7 +394,7 @@ module ActiveSupport #:nodoc: # Attempt to autoload the provided module name by searching for a directory # matching the expected path suffix. If found, the module is created and # assigned to +into+'s constants with the name +const_name+. Provided that - # the directory was loaded from a reloadable base path, it is added to the + # the directory was loaded from a reloadable base path, it is added to the # set of constants that are to be unloaded. def autoload_module!(into, const_name, qualified_name, path_suffix) return nil unless base_path = autoloadable_module?(path_suffix) diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb index 7e99646117..2cb1f408b6 100644 --- a/activesupport/lib/active_support/duration.rb +++ b/activesupport/lib/active_support/duration.rb @@ -1,4 +1,4 @@ -require 'active_support/basic_object' +require 'active_support/proxy_object' require 'active_support/core_ext/array/conversions' require 'active_support/core_ext/object/acts_like' @@ -7,7 +7,7 @@ module ActiveSupport # Time#advance, respectively. It mainly supports the methods on Numeric. # # 1.month.ago # equivalent to Time.now.advance(months: -1) - class Duration < BasicObject + class Duration < ProxyObject attr_accessor :value, :parts def initialize(value, parts) #:nodoc: diff --git a/activesupport/lib/active_support/file_update_checker.rb b/activesupport/lib/active_support/file_update_checker.rb index a6b9aa3503..20136dd1b0 100644 --- a/activesupport/lib/active_support/file_update_checker.rb +++ b/activesupport/lib/active_support/file_update_checker.rb @@ -68,7 +68,7 @@ module ActiveSupport end # Executes the given block and updates the latest watched files and - # timestamp. + # timestamp. def execute @last_watched = watched @last_update_at = updated_at(@last_watched) diff --git a/activesupport/lib/active_support/inflector/inflections.rb b/activesupport/lib/active_support/inflector/inflections.rb index af506d6f2e..6f259a093b 100644 --- a/activesupport/lib/active_support/inflector/inflections.rb +++ b/activesupport/lib/active_support/inflector/inflections.rb @@ -36,7 +36,7 @@ module ActiveSupport end # Private, for the test suite. - def initialize_dup(orig) # :nodoc: + def initialize_dup(orig) # :nodoc: %w(plurals singulars uncountables humans acronyms acronym_regex).each do |scope| instance_variable_set("@#{scope}", orig.send(scope).dup) end @@ -44,7 +44,7 @@ module ActiveSupport # Specifies a new acronym. An acronym must be specified as it will appear # in a camelized string. An underscore string that contains the acronym - # will retain the acronym when passed to +camelize+, +humanize+, or + # will retain the acronym when passed to +camelize+, +humanize+, or # +titleize+. A camelized string that contains the acronym will maintain # the acronym when titleized or humanized, and will convert the acronym # into a non-delimited single lowercase word when passed to +underscore+. @@ -79,7 +79,7 @@ module ActiveSupport # # +acronym+ may be used to specify any word that contains an acronym or # otherwise needs to maintain a non-standard capitalization. The only - # restriction is that the word must begin with a capital letter. + # restriction is that the word must begin with a capital letter. # # acronym 'RESTful' # underscore 'RESTful' #=> 'restful' @@ -97,7 +97,7 @@ module ActiveSupport end # Specifies a new pluralization rule and its replacement. The rule can - # either be a string or a regular expression. The replacement should + # either be a string or a regular expression. The replacement should # always be a string that may include references to the matched data from # the rule. def plural(rule, replacement) diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index 1588674afc..b7dc0689b0 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -33,7 +33,7 @@ module ActiveSupport # the cipher key size. For the default 'aes-256-cbc' cipher, this is 256 # bits. If you are using a user-entered secret, you can generate a suitable # key with <tt>OpenSSL::Digest::SHA256.new(user_secret).digest</tt> or - # similar. + # similar. # # Options: # * <tt>:cipher</tt> - Cipher to use. Can be any cipher returned by @@ -50,7 +50,7 @@ module ActiveSupport end # Encrypt and sign a message. We need to sign the message in order to avoid - # padding attacks. Reference: http://www.limited-entropy.com/padding-oracle-attacks. + # padding attacks. Reference: http://www.limited-entropy.com/padding-oracle-attacks. def encrypt_and_sign(value) verifier.generate(_encrypt(value)) end diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index 140b6ca08d..a87383fe99 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -6,7 +6,7 @@ module ActiveSupport # signed to prevent tampering. # # This is useful for cases like remember-me tokens and auto-unsubscribe links - # where the session store isn't suitable or available. + # where the session store isn't suitable or available. # # Remember Me: # cookies[:remember_me] = @verifier.generate([@user.id, 2.weeks.from_now]) diff --git a/activesupport/lib/active_support/multibyte.rb b/activesupport/lib/active_support/multibyte.rb index 1bf8e618ad..ffebd9a60b 100644 --- a/activesupport/lib/active_support/multibyte.rb +++ b/activesupport/lib/active_support/multibyte.rb @@ -5,7 +5,7 @@ module ActiveSupport #:nodoc: # The proxy class returned when calling mb_chars. You can use this accessor # to configure your own proxy class so you can support other encodings. See - # the ActiveSupport::Multibyte::Chars implementation for an example how to + # the ActiveSupport::Multibyte::Chars implementation for an example how to # do this. # # ActiveSupport::Multibyte.proxy_class = CharsForUTF32 diff --git a/activesupport/lib/active_support/proxy_object.rb b/activesupport/lib/active_support/proxy_object.rb new file mode 100644 index 0000000000..a2bdf1d790 --- /dev/null +++ b/activesupport/lib/active_support/proxy_object.rb @@ -0,0 +1,13 @@ +module ActiveSupport + # A class with no predefined methods that behaves similarly to Builder's + # BlankSlate. Used for proxy classes. + class ProxyObject < ::BasicObject + undef_method :== + undef_method :equal? + + # Let ActiveSupport::BasicObject at least raise exceptions. + def raise(*args) + ::Object.send(:raise, *args) + end + end +end diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb index 33810442da..18bc919734 100644 --- a/activesupport/lib/active_support/tagged_logging.rb +++ b/activesupport/lib/active_support/tagged_logging.rb @@ -11,7 +11,7 @@ module ActiveSupport # logger.tagged('BCX') { logger.tagged('Jason') { logger.info 'Stuff' } } # Logs "[BCX] [Jason] Stuff" # # This is used by the default Rails.logger as configured by Railties to make - # it easy to stamp log lines with subdomains, request ids, and anything else + # it easy to stamp log lines with subdomains, request ids, and anything else # to aid debugging of multi-user production applications. module TaggedLogging module Formatter # :nodoc: diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index ee7bda9f93..e4f182a3aa 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -69,7 +69,7 @@ module ActiveSupport alias :assert_no_match :refute_match alias :assert_not_same :refute_same - # Fails if the block raises an exception. + # Fails if the block raises an exception. # # assert_nothing_raised do # ... diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index b6fca9df91..d087955587 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -326,7 +326,7 @@ module ActiveSupport end # Available so that TimeZone instances respond like TZInfo::Timezone - # instances. + # instances. def period_for_utc(time) tzinfo.period_for_utc(time) end diff --git a/activesupport/test/core_ext/duration_test.rb b/activesupport/test/core_ext/duration_test.rb index c8312aa653..2826f51f2d 100644 --- a/activesupport/test/core_ext/duration_test.rb +++ b/activesupport/test/core_ext/duration_test.rb @@ -21,7 +21,7 @@ class DurationTest < ActiveSupport::TestCase assert ActiveSupport::Duration === 1.day assert !(ActiveSupport::Duration === 1.day.to_i) assert !(ActiveSupport::Duration === 'foo') - assert !(ActiveSupport::Duration === ActiveSupport::BasicObject.new) + assert !(ActiveSupport::Duration === ActiveSupport::ProxyObject.new) end def test_equals @@ -131,7 +131,7 @@ class DurationTest < ActiveSupport::TestCase assert_equal Time.local(2009,3,29,0,0,0) + 1.day, Time.local(2009,3,30,0,0,0) end end - + def test_delegation_with_block_works counter = 0 assert_nothing_raised do diff --git a/activesupport/test/dependencies_test.rb b/activesupport/test/dependencies_test.rb index 952c82f9d8..51a7e4b2fe 100644 --- a/activesupport/test/dependencies_test.rb +++ b/activesupport/test/dependencies_test.rb @@ -923,8 +923,10 @@ class DependenciesTest < ActiveSupport::TestCase def test_remove_constant_does_not_autoload_already_removed_parents_as_a_side_effect with_autoloading_fixtures do - ::A - ::A::B + silence_warnings do + ::A + ::A::B + end ActiveSupport::Dependencies.remove_constant('A') ActiveSupport::Dependencies.remove_constant('A::B') assert !defined?(A) @@ -934,7 +936,9 @@ class DependenciesTest < ActiveSupport::TestCase def test_load_once_constants_should_not_be_unloaded with_autoloading_fixtures do ActiveSupport::Dependencies.autoload_once_paths = ActiveSupport::Dependencies.autoload_paths - ::A.to_s + silence_warnings do + ::A + end assert defined?(A) ActiveSupport::Dependencies.clear assert defined?(A) |