Module: Historyable::ClassMethods

Defined in:
lib/historyable.rb

Instance Method Summary collapse

Instance Method Details

#has_history(*attributes) ⇒ Object

Define

Parameters:

  • attributes (Array, Symbol)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/historyable.rb', line 25

def has_history(*attributes)
  self.historyable_items = attributes.map do |attribute|
    attribute_name   = attribute.to_sym
    association_name = "#{attribute}_changes".to_sym

    Item.new(attribute_name, association_name)
  end

  historyable_items.each do |historyable|
    # Associations
    define_historyable_association(historyable)

    # Instance methods
    define_historyable_attribute_history_raw(historyable)
    define_historyable_attribute_history(historyable)
    define_historyable_attribute_history?(historyable)
  end

  # Callbacks
  around_save :save_changes
end