Permalink
Browse files

automatic array conversion for args

  • Loading branch information...
1 parent eac98af commit df52ee357049b4bb45a6fff1bfd2d2312f54bf20 @schneems committed Dec 17, 2012
Showing with 13 additions and 0 deletions.
  1. +5 −0 lib/method_cacheable.rb
  2. +8 −0 spec/method_cacheable/method_cache_spec.rb
View
@@ -89,6 +89,11 @@ def cache(*args)
class MethodCache
attr_accessor :caller, :method, :args, :options, :cache_operation
+ def args=(args)
+ args = [args] unless args.is_a? Array
+ @args = args
+ end
+
def initialize(caller, *method_cache_args)
self.caller = caller
self.cache_operation = method_cache_args.map {|x| x if x.is_a? Symbol }.compact.first||:fetch
@@ -20,6 +20,14 @@
end
+ describe 'args' do
+ it 'converts non array args to array' do
+ cache = user.cache
+ cache.args = 1
+ cache.args.should == [1]
+ end
+ end
+
describe 'key' do
it 'returns the key' do
user.cache.key(:foo).should == "users:foo:#{user.id}"

0 comments on commit df52ee3

Please sign in to comment.