Module: Hound::Model::ClassMethods

Defined in:
lib/hound/model.rb

Instance Method Summary collapse

Instance Method Details

#hound(options = {}) ⇒ Object

Tell Hound to track this models actions.

options - a Hash of configuration options.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hound/model.rb', line 13

def hound(options = {})
  send :include, InstanceMethods

  has_many :actions,
    as: 'actionable',
    class_name: 'Hound::Action'

  options[:actions] ||= Hound.config.actions
  options[:actions] = Array(options[:actions]).map(&:to_s)

  class_attribute :hound_options
  self.hound_options = options.dup

  attr_accessor :hound

  # Add action hooks
  after_create :hound_create if options[:actions].include?('create')
  before_update :hound_update if options[:actions].include?('update')
  after_destroy :hound_destroy if options[:actions].include?('destroy')
end