mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Deprecate memoizable.
This commit is contained in:
parent
6c3e80af68
commit
36253916b0
3 changed files with 28 additions and 7 deletions
|
@ -1,8 +1,15 @@
|
|||
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 'abstract_unit'
|
|||
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 @@ require 'abstract_unit'
|
|||
|
||||
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 @@ class MemoizableTest < ActiveSupport::TestCase
|
|||
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 @@ class MemoizableTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
class Calculator
|
||||
extend ActiveSupport::Memoizable
|
||||
ActiveSupport::Deprecation.silence do
|
||||
extend ActiveSupport::Memoizable
|
||||
end
|
||||
include Rates
|
||||
|
||||
attr_reader :fib_calls
|
||||
|
@ -215,7 +221,9 @@ class MemoizableTest < ActiveSupport::TestCase
|
|||
|
||||
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 @@ class MemoizableTest < ActiveSupport::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue