module Redis::Objects::DailyCounters::ClassMethods
Public Instance Methods
daily_counter(name, options = {})
click to toggle source
# File lib/redis/objects/daily_counters.rb, line 15 def daily_counter(name, options = {}) options[:start] ||= 0 options[:type] ||= options[:start] == 0 ? :increment : :decrement redis_objects[name.to_sym] = options.merge(type: :counter) mod = Module.new do define_method(name) do Redis::DailyCounter.new( redis_field_key(name), redis_field_redis(name), redis_options(name) ) end end if options[:global] extend mod # dispatch to class methods define_method(name) do self.class.public_send(name) end else include mod end end