Sha256: a6b8dc64617be2c6d91c1fbedec7dd1703a813cbab4412fa91e44db633fbc0be

Contents?: true

Size: 385 Bytes

Versions: 6

Compression:

Stored size: 385 Bytes

Contents

# Allow hooks to be defined on the counter
module Counter::Hooks
  extend ActiveSupport::Concern

  included do
    after_save :call_counter_hooks

    def call_counter_hooks
      return unless previous_changes["value"]

      from, to = previous_changes["value"]
      definition.counter_hooks.each do |hook|
        definition.send(hook, self, from, to)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
counterwise-0.1.5 app/models/concerns/counter/hooks.rb
counterwise-0.1.4 app/models/concerns/counter/hooks.rb
counterwise-0.1.3 app/models/concerns/counter/hooks.rb
counterwise-0.1.2 app/models/concerns/counter/hooks.rb
counterwise-0.1.1 app/models/concerns/counter/hooks.rb
counterwise-0.1.0 app/models/concerns/counter/hooks.rb