lib/method_cacheable.rb in method_cacheable-0.0.4 vs lib/method_cacheable.rb in method_cacheable-0.1.0

- old
+ new

@@ -87,10 +87,15 @@ end 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 self.options = method_cache_args.map {|x| x if x.is_a? Hash }.compact.first end @@ -141,11 +146,11 @@ # @example # cache = User.find(263619).cache # => #<MethodCacheable::MethodCache ... > # cache.method = "foo" # => "foo" # cache.key # => "users:foo:263619" def key(tmp_method = nil, *tmp_args) - tmp_method ||= method - tmp_args ||= args + tmp_method = method if tmp_method.blank? + tmp_args = args if tmp_args.blank? key_method = "#{tmp_method}_key".to_sym key = caller.send key_method, *tmp_args if caller.respond_to? key_method key ||= caller.build_key(:name => tmp_method, :args => tmp_args) end