Module: Footprintable::ClassMethods

Defined in:
lib/footprintable/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#has_footprints(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/footprintable/class_methods.rb', line 4

def has_footprints options = {}
  # 触发时间
  options[:on]   ||= [:create, :update, :destroy]
  # 摘取字段 [] => 所有字段
  options[:extract] ||= []
  # 排除字段
  options[:except] ||= [:updated_at, :created_at]
  self.footprint_options = options
  setup_callbacks_from_options(options[:on])
end

#setup_callbacks_from_options(options_on = []) ⇒ Object



15
16
17
18
19
# File 'lib/footprintable/class_methods.rb', line 15

def setup_callbacks_from_options options_on = []
  options_on.each do |action|
    after_commit ->(obj) { obj.create_footprint action }, on: action
  end
end