diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-20 15:18:42 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-20 15:18:42 +0100 |
commit | 6a6fc4e1db2469bd309c074f607abb60764ba20d (patch) | |
tree | f25d87262f1a77ae9aea66543cf4e132d5bf7e3a /activesupport | |
parent | 6c57177f2c7f4f934716d588545902d5fc00fa99 (diff) | |
download | rails-6a6fc4e1db2469bd309c074f607abb60764ba20d.tar.gz rails-6a6fc4e1db2469bd309c074f607abb60764ba20d.tar.bz2 rails-6a6fc4e1db2469bd309c074f607abb60764ba20d.zip |
Remove deprecations from Active Support.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/concern.rb | 5 | ||||
-rw-r--r-- | activesupport/lib/active_support/memoizable.rb | 116 | ||||
-rw-r--r-- | activesupport/lib/active_support/message_encryptor.rb | 17 | ||||
-rw-r--r-- | activesupport/lib/active_support/message_verifier.rb | 5 | ||||
-rw-r--r-- | activesupport/test/flush_cache_on_private_memoization_test.rb | 45 | ||||
-rw-r--r-- | activesupport/test/memoizable_test.rb | 290 | ||||
-rw-r--r-- | activesupport/test/message_encryptor_test.rb | 6 | ||||
-rw-r--r-- | activesupport/test/message_verifier_test.rb | 6 |
9 files changed, 0 insertions, 491 deletions
diff --git a/activesupport/lib/active_support.rb b/activesupport/lib/active_support.rb index a5aeeacaef..896d0e5f65 100644 --- a/activesupport/lib/active_support.rb +++ b/activesupport/lib/active_support.rb @@ -62,7 +62,6 @@ module ActiveSupport autoload :Gzip autoload :Inflector autoload :JSON - autoload :Memoizable autoload :MessageEncryptor autoload :MessageVerifier autoload :Multibyte diff --git a/activesupport/lib/active_support/concern.rb b/activesupport/lib/active_support/concern.rb index af3da937c7..c94a8d99f4 100644 --- a/activesupport/lib/active_support/concern.rb +++ b/activesupport/lib/active_support/concern.rb @@ -109,11 +109,6 @@ module ActiveSupport @_dependencies.each { |dep| base.send(:include, dep) } super base.extend const_get("ClassMethods") if const_defined?("ClassMethods") - if const_defined?("InstanceMethods") - base.send :include, const_get("InstanceMethods") - ActiveSupport::Deprecation.warn "The InstanceMethods module inside ActiveSupport::Concern will be " \ - "no longer included automatically. Please define instance methods directly in #{base} instead.", caller - end base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block") end end diff --git a/activesupport/lib/active_support/memoizable.rb b/activesupport/lib/active_support/memoizable.rb deleted file mode 100644 index 4c67676ad5..0000000000 --- a/activesupport/lib/active_support/memoizable.rb +++ /dev/null @@ -1,116 +0,0 @@ -require 'active_support/core_ext/kernel/singleton_class' -require 'active_support/core_ext/module/aliasing' -require 'active_support/deprecation' - -module ActiveSupport - module Memoizable - def self.extended(base) - ActiveSupport::Deprecation.warn "ActiveSupport::Memoizable is deprecated and will be removed in future releases," \ - "simply use Ruby memoization pattern instead.", caller - super - end - - def self.memoized_ivar_for(symbol) - "@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym - end - - module InstanceMethods - def self.included(base) - base.class_eval do - unless base.method_defined?(:freeze_without_memoizable) - alias_method_chain :freeze, :memoizable - end - end - end - - def freeze_with_memoizable - memoize_all unless frozen? - freeze_without_memoizable - end - - def memoize_all - prime_cache ".*" - end - - def unmemoize_all - flush_cache ".*" - end - - def prime_cache(*syms) - syms.each do |sym| - methods.each do |m| - if m.to_s =~ /^_unmemoized_(#{sym})/ - if method(m).arity == 0 - __send__($1) - else - ivar = ActiveSupport::Memoizable.memoized_ivar_for($1) - instance_variable_set(ivar, {}) - end - end - end - end - end - - def flush_cache(*syms) - syms.each do |sym| - (methods + private_methods + protected_methods).each do |m| - if m.to_s =~ /^_unmemoized_(#{sym.to_s.gsub(/\?\Z/, '\?')})/ - ivar = ActiveSupport::Memoizable.memoized_ivar_for($1) - instance_variable_get(ivar).clear if instance_variable_defined?(ivar) - end - end - end - end - end - - def memoize(*symbols) - symbols.each do |symbol| - original_method = :"_unmemoized_#{symbol}" - memoized_ivar = ActiveSupport::Memoizable.memoized_ivar_for(symbol) - - class_eval <<-EOS, __FILE__, __LINE__ + 1 - include InstanceMethods # include InstanceMethods - # - if method_defined?(:#{original_method}) # if method_defined?(:_unmemoized_mime_type) - raise "Already memoized #{symbol}" # raise "Already memoized mime_type" - end # end - alias #{original_method} #{symbol} # alias _unmemoized_mime_type mime_type - # - if instance_method(:#{symbol}).arity == 0 # if instance_method(:mime_type).arity == 0 - def #{symbol}(reload = false) # def mime_type(reload = false) - if reload || !defined?(#{memoized_ivar}) || #{memoized_ivar}.empty? # if reload || !defined?(@_memoized_mime_type) || @_memoized_mime_type.empty? - #{memoized_ivar} = [#{original_method}] # @_memoized_mime_type = [_unmemoized_mime_type] - end # end - #{memoized_ivar}[0] # @_memoized_mime_type[0] - end # end - else # else - def #{symbol}(*args) # def mime_type(*args) - #{memoized_ivar} ||= {} unless frozen? # @_memoized_mime_type ||= {} unless frozen? - args_length = method(:#{original_method}).arity # args_length = method(:_unmemoized_mime_type).arity - if args.length == args_length + 1 && # if args.length == args_length + 1 && - (args.last == true || args.last == :reload) # (args.last == true || args.last == :reload) - reload = args.pop # reload = args.pop - end # end - # - if defined?(#{memoized_ivar}) && #{memoized_ivar} # if defined?(@_memoized_mime_type) && @_memoized_mime_type - if !reload && #{memoized_ivar}.has_key?(args) # if !reload && @_memoized_mime_type.has_key?(args) - #{memoized_ivar}[args] # @_memoized_mime_type[args] - elsif #{memoized_ivar} # elsif @_memoized_mime_type - #{memoized_ivar}[args] = #{original_method}(*args) # @_memoized_mime_type[args] = _unmemoized_mime_type(*args) - end # end - else # else - #{original_method}(*args) # _unmemoized_mime_type(*args) - end # end - end # end - end # end - # - if private_method_defined?(#{original_method.inspect}) # if private_method_defined?(:_unmemoized_mime_type) - private #{symbol.inspect} # private :mime_type - elsif protected_method_defined?(#{original_method.inspect}) # elsif protected_method_defined?(:_unmemoized_mime_type) - protected #{symbol.inspect} # protected :mime_type - end # end - EOS - end - end - end -end diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index 9ef2b29580..7d8a7fb687 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -24,29 +24,12 @@ module ActiveSupport OpenSSLCipherError = OpenSSL::Cipher.const_defined?(:CipherError) ? OpenSSL::Cipher::CipherError : OpenSSL::CipherError def initialize(secret, options = {}) - unless options.is_a?(Hash) - ActiveSupport::Deprecation.warn "The second parameter should be an options hash. Use :cipher => 'algorithm' to specify the cipher algorithm." - options = { :cipher => options } - end - @secret = secret @cipher = options[:cipher] || 'aes-256-cbc' @verifier = MessageVerifier.new(@secret, :serializer => NullSerializer) @serializer = options[:serializer] || Marshal end - def encrypt(value) - ActiveSupport::Deprecation.warn "MessageEncryptor#encrypt is deprecated as it is not safe without a signature. " \ - "Please use MessageEncryptor#encrypt_and_sign instead." - _encrypt(value) - end - - def decrypt(value) - ActiveSupport::Deprecation.warn "MessageEncryptor#decrypt is deprecated as it is not safe without a signature. " \ - "Please use MessageEncryptor#decrypt_and_verify instead." - _decrypt(value) - 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 def encrypt_and_sign(value) diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index 9d7c81142a..30ac44f6fa 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -27,11 +27,6 @@ module ActiveSupport class InvalidSignature < StandardError; end def initialize(secret, options = {}) - unless options.is_a?(Hash) - ActiveSupport::Deprecation.warn "The second parameter should be an options hash. Use :digest => 'algorithm' to specify the digest algorithm." - options = { :digest => options } - end - @secret = secret @digest = options[:digest] || 'SHA1' @serializer = options[:serializer] || Marshal diff --git a/activesupport/test/flush_cache_on_private_memoization_test.rb b/activesupport/test/flush_cache_on_private_memoization_test.rb deleted file mode 100644 index bc488cc743..0000000000 --- a/activesupport/test/flush_cache_on_private_memoization_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'abstract_unit' -require 'test/unit' - -class FlushCacheOnPrivateMemoizationTest < Test::Unit::TestCase - ActiveSupport::Deprecation.silence do - extend ActiveSupport::Memoizable - end - - def test_public - assert_method_unmemoizable :pub - end - - def test_protected - assert_method_unmemoizable :prot - end - - def test_private - assert_method_unmemoizable :priv - end - - def pub; rand end - memoize :pub - - protected - - def prot; rand end - memoize :prot - - private - - def priv; rand end - memoize :priv - - def assert_method_unmemoizable(meth, message=nil) - full_message = build_message(message, "<?> not unmemoizable.\n", meth) - assert_block(full_message) do - a = send meth - b = send meth - unmemoize_all - c = send meth - a == b && a != c - end - end - -end diff --git a/activesupport/test/memoizable_test.rb b/activesupport/test/memoizable_test.rb deleted file mode 100644 index e333b9a78c..0000000000 --- a/activesupport/test/memoizable_test.rb +++ /dev/null @@ -1,290 +0,0 @@ -require 'abstract_unit' - -class MemoizableTest < ActiveSupport::TestCase - class Person - ActiveSupport::Deprecation.silence do - extend ActiveSupport::Memoizable - end - - attr_reader :name_calls, :age_calls, :is_developer_calls, :name_query_calls - - def initialize - @name_calls = 0 - @age_calls = 0 - @is_developer_calls = 0 - @name_query_calls = 0 - end - - def name - @name_calls += 1 - "Josh" - end - - def name? - @name_query_calls += 1 - true - end - memoize :name? - - def update(name) - "Joshua" - end - memoize :update - - def age - @age_calls += 1 - nil - end - - memoize :name, :age - - protected - - def memoize_protected_test - 'protected' - end - memoize :memoize_protected_test - - private - - def is_developer? - @is_developer_calls += 1 - "Yes" - end - memoize :is_developer? - end - - class Company - attr_reader :name_calls - def initialize - @name_calls = 0 - end - - def name - @name_calls += 1 - "37signals" - end - end - - module Rates - ActiveSupport::Deprecation.silence do - extend ActiveSupport::Memoizable - end - - attr_reader :sales_tax_calls - def sales_tax(price) - @sales_tax_calls ||= 0 - @sales_tax_calls += 1 - price * 0.1025 - end - memoize :sales_tax - end - - class Calculator - ActiveSupport::Deprecation.silence do - extend ActiveSupport::Memoizable - end - include Rates - - attr_reader :fib_calls - def initialize - @fib_calls = 0 - end - - def fib(n) - @fib_calls += 1 - - if n == 0 || n == 1 - n - else - fib(n - 1) + fib(n - 2) - end - end - memoize :fib - - def add_or_subtract(i, j, add) - if add - i + j - else - i - j - end - end - memoize :add_or_subtract - - def counter - @count ||= 0 - @count += 1 - end - memoize :counter - end - - def setup - @person = Person.new - @calculator = Calculator.new - end - - def test_memoization - assert_equal "Josh", @person.name - assert_equal 1, @person.name_calls - - 3.times { assert_equal "Josh", @person.name } - assert_equal 1, @person.name_calls - end - - def test_memoization_with_punctuation - assert_equal true, @person.name? - - assert_nothing_raised(NameError) do - @person.memoize_all - @person.unmemoize_all - end - end - - def test_memoization_flush_with_punctuation - assert_equal true, @person.name? - @person.flush_cache(:name?) - 3.times { assert_equal true, @person.name? } - assert_equal 2, @person.name_query_calls - end - - def test_memoization_with_nil_value - assert_equal nil, @person.age - assert_equal 1, @person.age_calls - - 3.times { assert_equal nil, @person.age } - assert_equal 1, @person.age_calls - end - - def test_reloadable - assert_equal 1, @calculator.counter - assert_equal 2, @calculator.counter(:reload) - assert_equal 2, @calculator.counter - assert_equal 3, @calculator.counter(true) - assert_equal 3, @calculator.counter - end - - def test_flush_cache - assert_equal 1, @calculator.counter - - assert @calculator.instance_variable_get(:@_memoized_counter).any? - @calculator.flush_cache(:counter) - assert @calculator.instance_variable_get(:@_memoized_counter).empty? - - assert_equal 2, @calculator.counter - end - - def test_unmemoize_all - assert_equal 1, @calculator.counter - - assert @calculator.instance_variable_get(:@_memoized_counter).any? - @calculator.unmemoize_all - assert @calculator.instance_variable_get(:@_memoized_counter).empty? - - assert_equal 2, @calculator.counter - end - - def test_memoize_all - @calculator.memoize_all - assert @calculator.instance_variable_defined?(:@_memoized_counter) - end - - def test_memoization_cache_is_different_for_each_instance - assert_equal 1, @calculator.counter - assert_equal 2, @calculator.counter(:reload) - assert_equal 1, Calculator.new.counter - end - - def test_memoized_is_not_affected_by_freeze - @person.freeze - assert_equal "Josh", @person.name - assert_equal "Joshua", @person.update("Joshua") - end - - def test_memoization_with_args - assert_equal 55, @calculator.fib(10) - assert_equal 11, @calculator.fib_calls - end - - def test_reloadable_with_args - assert_equal 55, @calculator.fib(10) - assert_equal 11, @calculator.fib_calls - assert_equal 55, @calculator.fib(10, :reload) - assert_equal 12, @calculator.fib_calls - assert_equal 55, @calculator.fib(10, true) - assert_equal 13, @calculator.fib_calls - end - - def test_memoization_with_boolean_arg - assert_equal 4, @calculator.add_or_subtract(2, 2, true) - assert_equal 2, @calculator.add_or_subtract(4, 2, false) - end - - def test_object_memoization - [Company.new, Company.new, Company.new].each do |company| - ActiveSupport::Deprecation.silence do - company.extend ActiveSupport::Memoizable - end - company.memoize :name - - assert_equal "37signals", company.name - assert_equal 1, company.name_calls - assert_equal "37signals", company.name - assert_equal 1, company.name_calls - end - end - - def test_memoized_module_methods - assert_equal 1.025, @calculator.sales_tax(10) - assert_equal 1, @calculator.sales_tax_calls - assert_equal 1.025, @calculator.sales_tax(10) - assert_equal 1, @calculator.sales_tax_calls - assert_equal 2.5625, @calculator.sales_tax(25) - assert_equal 2, @calculator.sales_tax_calls - end - - def test_object_memoized_module_methods - company = Company.new - company.extend(Rates) - - assert_equal 1.025, company.sales_tax(10) - assert_equal 1, company.sales_tax_calls - assert_equal 1.025, company.sales_tax(10) - assert_equal 1, company.sales_tax_calls - assert_equal 2.5625, company.sales_tax(25) - assert_equal 2, company.sales_tax_calls - end - - def test_double_memoization - assert_raise(RuntimeError) { Person.memoize :name } - person = Person.new - ActiveSupport::Deprecation.silence do - person.extend ActiveSupport::Memoizable - end - assert_raise(RuntimeError) { person.memoize :name } - - company = Company.new - ActiveSupport::Deprecation.silence do - company.extend ActiveSupport::Memoizable - end - company.memoize :name - assert_raise(RuntimeError) { company.memoize :name } - end - - def test_protected_method_memoization - person = Person.new - - assert_raise(NoMethodError) { person.memoize_protected_test } - assert_equal "protected", person.send(:memoize_protected_test) - end - - def test_private_method_memoization - person = Person.new - - assert_raise(NoMethodError) { person.is_developer? } - assert_equal "Yes", person.send(:is_developer?) - assert_equal 1, person.is_developer_calls - assert_equal "Yes", person.send(:is_developer?) - assert_equal 1, person.is_developer_calls - end - -end diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb index 3e6a5c6602..db97c1b80b 100644 --- a/activesupport/test/message_encryptor_test.rb +++ b/activesupport/test/message_encryptor_test.rb @@ -61,12 +61,6 @@ class MessageEncryptorTest < ActiveSupport::TestCase assert_equal encryptor.decrypt_and_verify(message), { "foo" => 123, "bar" => "2010-01-01T00:00:00Z" } end - def test_digest_algorithm_as_second_parameter_deprecation - assert_deprecated(/options hash/) do - ActiveSupport::MessageEncryptor.new(SecureRandom.hex(64), 'aes-256-cbc') - end - end - private def assert_not_decrypted(value) diff --git a/activesupport/test/message_verifier_test.rb b/activesupport/test/message_verifier_test.rb index 35747abe5b..5adff41653 100644 --- a/activesupport/test/message_verifier_test.rb +++ b/activesupport/test/message_verifier_test.rb @@ -50,12 +50,6 @@ class MessageVerifierTest < ActiveSupport::TestCase assert_equal verifier.verify(message), { "foo" => 123, "bar" => "2010-01-01T00:00:00Z" } end - def test_digest_algorithm_as_second_parameter_deprecation - assert_deprecated(/options hash/) do - ActiveSupport::MessageVerifier.new("secret", "SHA1") - end - end - def assert_not_verified(message) assert_raise(ActiveSupport::MessageVerifier::InvalidSignature) do @verifier.verify(message) |