提交 36253916 编写于 作者: J José Valim

Deprecate memoizable.

上级 6c3e80af
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 instead.", caller
super
end
def self.memoized_ivar_for(symbol)
"@_memoized_#{symbol.to_s.sub(/\?\Z/, '_query').sub(/!\Z/, '_bang')}".to_sym
end
......
......@@ -2,7 +2,9 @@
require 'test/unit'
class FlashCacheOnPrivateMemoizationTest < Test::Unit::TestCase
extend ActiveSupport::Memoizable
ActiveSupport::Deprecation.silence do
extend ActiveSupport::Memoizable
end
def test_public
assert_method_unmemoizable :pub
......
......@@ -2,7 +2,9 @@
class MemoizableTest < ActiveSupport::TestCase
class Person
extend ActiveSupport::Memoizable
ActiveSupport::Deprecation.silence do
extend ActiveSupport::Memoizable
end
attr_reader :name_calls, :age_calls, :is_developer_calls, :name_query_calls
......@@ -65,7 +67,9 @@ def name
end
module Rates
extend ActiveSupport::Memoizable
ActiveSupport::Deprecation.silence do
extend ActiveSupport::Memoizable
end
attr_reader :sales_tax_calls
def sales_tax(price)
......@@ -77,7 +81,9 @@ def sales_tax(price)
end
class Calculator
extend ActiveSupport::Memoizable
ActiveSupport::Deprecation.silence do
extend ActiveSupport::Memoizable
end
include Rates
attr_reader :fib_calls
......@@ -215,7 +221,9 @@ def test_memoization_with_boolean_arg
def test_object_memoization
[Company.new, Company.new, Company.new].each do |company|
company.extend ActiveSupport::Memoizable
ActiveSupport::Deprecation.silence do
company.extend ActiveSupport::Memoizable
end
company.memoize :name
assert_equal "37signals", company.name
......@@ -249,11 +257,15 @@ def test_object_memoized_module_methods
def test_double_memoization
assert_raise(RuntimeError) { Person.memoize :name }
person = Person.new
person.extend ActiveSupport::Memoizable
ActiveSupport::Deprecation.silence do
person.extend ActiveSupport::Memoizable
end
assert_raise(RuntimeError) { person.memoize :name }
company = Company.new
company.extend ActiveSupport::Memoizable
ActiveSupport::Deprecation.silence do
company.extend ActiveSupport::Memoizable
end
company.memoize :name
assert_raise(RuntimeError) { company.memoize :name }
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册