Module: FancyCount::HasCountable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/fancy_count/has_countable.rb
Instance Method Summary collapse
Instance Method Details
#fancy_counter_value(counter_key) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fancy_count/has_countable.rb', line 102 def fancy_counter_value(counter_key) case FancyCount.config.adapter when :redis Redis::Objects.redis.get(counter_key) when :test FancyCount::TestAdapter.counts[counter_key] else raise "Unknown adapter: #{FancyCount.config.adapter}" end end |
#fancy_counters_reconcile(name) ⇒ Object
113 114 115 116 117 118 119 120 121 |
# File 'lib/fancy_count/has_countable.rb', line 113 def fancy_counters_reconcile(name) count_method_name = "fancy_#{name.to_s.singularize}_count" data = self.class.fancy_counters.detect { |entry| entry[:name] == name.to_sym } raise UnknownCounterError.new("#{count_method_name} doesn't exist") if data.nil? raise MissingLogicError.new("#{count_method_name} doesn't have ':reconcile'") unless data.has_key?(:reconcile_logic) new_count = send(data[:reconcile_logic]) public_send(data[:counter_name]).change(new_count) end |