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 (default: {}).

:limit   - An Integer limit to restrict the maximum actions
           stored (optional, default: nil (no limit)).
:actions - An Array of actions to track.
           (default: [:create, :update, :destroy])


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

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: :hound? if options[:actions].include?('create')
  before_update :hound_update, if: :hound? if options[:actions].include?('update')
  after_destroy :hound_destroy, if: :hound? if options[:actions].include?('destroy')
end

#hound_user(options = {}) ⇒ Object



36
37
38
# File 'lib/hound/model.rb', line 36

def hound_user(options = {})
  has_many :actions, as: :user, class_name: 'Hound::Action'
end