Skip to content

Commit

Permalink
Rename Kernel#memoize to Kernel#expirable_memoize so that it doesn't …
Browse files Browse the repository at this point in the history
…conflict with memoize method in ActiveSupport which has an entirely different API and semantics. Reported by [Florian Dütsc (mail@florian-duetsch.de)].
  • Loading branch information
marcel committed Apr 20, 2009
1 parent 3f148e1 commit af27b54
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions lib/aws/s3/acl.rb
Expand Up @@ -528,7 +528,7 @@ def acl(name = nil, policy = nil)
# bucket.acl(bucket.acl)
def acl(reload = false)
policy = reload.is_a?(ACL::Policy) ? reload : nil
memoize(reload) do
expirable_memoize(reload) do
self.class.acl(name, policy) if policy
self.class.acl(name)
end
Expand Down Expand Up @@ -579,7 +579,7 @@ def acl(name, bucket = nil, policy = nil)
# object.acl(object.acl)
def acl(reload = false)
policy = reload.is_a?(ACL::Policy) ? reload : nil
memoize(reload) do
expirable_memoize(reload) do
self.class.acl(key, bucket.name, policy) if policy
self.class.acl(key, bucket.name)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/aws/s3/extensions.rb
Expand Up @@ -133,7 +133,7 @@ def __called_from__
caller[1][/`([^']+)'/, 1]
end if RUBY_VERSION > '1.8.7'

def memoize(reload = false, storage = nil)
def expirable_memoize(reload = false, storage = nil)
current_method = RUBY_VERSION >= '1.8.7' ? __called_from__ : __method__(1)
storage = "@#{storage || current_method}"
if reload
Expand Down Expand Up @@ -174,7 +174,7 @@ def memoized(method_name)
alias_method original_method, method_name
module_eval(<<-EVAL, __FILE__, __LINE__)
def #{method_name}(reload = false, *args, &block)
memoize(reload) do
expirable_memoize(reload) do
send(:#{original_method}, *args, &block)
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/aws/s3/object.rb
Expand Up @@ -485,7 +485,7 @@ def value(options = {}, &block)
reload = options
options = {}
end
memoize(reload) do
expirable_memoize(reload) do
self.class.stream(key, bucket.name, options, &block)
end
end
Expand Down Expand Up @@ -561,7 +561,7 @@ def rename(to, options = {})

def etag(reload = false)
return nil unless stored?
memoize(reload) do
expirable_memoize(reload) do
reload ? about(reload)['etag'][1...-1] : attributes['e_tag'][1...-1]
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/aws/s3/version.rb
Expand Up @@ -4,7 +4,7 @@ module VERSION #:nodoc:
MAJOR = '0'
MINOR = '6'
TINY = '0'
BETA = nil # Time.now.to_i.to_s
BETA = Time.now.to_i.to_s
end

Version = [VERSION::MAJOR, VERSION::MINOR, VERSION::TINY, VERSION::BETA].compact * '.'
Expand Down
4 changes: 2 additions & 2 deletions test/extensions_test.rb
Expand Up @@ -144,13 +144,13 @@ def test___method___depth
class ModuleExtensionsTest < Test::Unit::TestCase
class Foo
def foo(reload = false)
memoize(reload) do
expirable_memoize(reload) do
Time.now
end
end

def bar(reload = false)
memoize(reload, :baz) do
expirable_memoize(reload, :baz) do
Time.now
end
end
Expand Down

0 comments on commit af27b54

Please sign in to comment.