Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

Commit

Permalink
close #3 properly use args if tmp_args not passed
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Dec 17, 2012
1 parent 57eaef1 commit eac98af
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,3 @@
## 0.1.0

- Fix #3 properly use args if tmp_args not passed
4 changes: 2 additions & 2 deletions lib/method_cacheable.rb
Expand Up @@ -143,8 +143,8 @@ def for(method , *args)
# cache.method = "foo" # => "foo" # cache.method = "foo" # => "foo"
# cache.key # => "users:foo:263619" # cache.key # => "users:foo:263619"
def key(tmp_method = nil, *tmp_args) def key(tmp_method = nil, *tmp_args)
tmp_method ||= method tmp_method = method if tmp_method.blank?
tmp_args ||= args tmp_args = args if tmp_args.blank?
key_method = "#{tmp_method}_key".to_sym key_method = "#{tmp_method}_key".to_sym
key = caller.send key_method, *tmp_args if caller.respond_to? key_method key = caller.send key_method, *tmp_args if caller.respond_to? key_method
key ||= caller.build_key(:name => tmp_method, :args => tmp_args) key ||= caller.build_key(:name => tmp_method, :args => tmp_args)
Expand Down
7 changes: 7 additions & 0 deletions spec/method_cacheable/method_cache_spec.rb
Expand Up @@ -24,6 +24,13 @@
it 'returns the key' do it 'returns the key' do
user.cache.key(:foo).should == "users:foo:#{user.id}" user.cache.key(:foo).should == "users:foo:#{user.id}"
end end

it 'returns the key after specifying args and method' do
cache = user.cache
cache.method = "foo#{@uniq}"
cache.args = [1]
cache.key.should == "users:foo#{@uniq}:#{user.id}:1"
end
end end


describe 'exists?' do describe 'exists?' do
Expand Down

0 comments on commit eac98af

Please sign in to comment.