Module: Hound::Model::ClassMethods
- Defined in:
- lib/hound/model.rb
Instance Method Summary collapse
-
#hound(options = {}) ⇒ Object
Tell Hound to track this models actions.
- #hound_user(options = {}) ⇒ Object
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( = {}) send :include, InstanceMethods has_many :actions, as: :actionable, class_name: 'Hound::Action' [:actions] ||= Hound.config.actions [:actions] = Array([:actions]).map(&:to_s) class_attribute :hound_options self. = .dup attr_accessor :hound # Add action hooks after_create :hound_create, if: :hound? if [:actions].include?('create') before_update :hound_update, if: :hound? if [:actions].include?('update') after_destroy :hound_destroy, if: :hound? if [:actions].include?('destroy') end |
#hound_user(options = {}) ⇒ Object
36 37 38 |
# File 'lib/hound/model.rb', line 36 def hound_user( = {}) has_many :actions, as: :user, class_name: 'Hound::Action' end |