Class: Event

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/acts_as_eventable/event.rb

Class Method Summary collapse

Class Method Details

.attributes_from(model, key, old_val, new_val) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/acts_as_eventable/event.rb', line 3

def self.attributes_from(model, key, old_val, new_val)
  eventable_options = model.class.eventable_options
  msg = if eventable_options[:events][key.to_sym] && eventable_options[:events][key.to_sym][new_val]
    eventable_options[:events][key.to_sym][new_val]
  elsif eventable_options[:events][key.to_sym] && eventable_options[:events][key.to_sym][:message]
    the_proc = eventable_options[:events][key.to_sym][:message]
    if key.index("_id") # hackish, but this is a convention
      reference = key[0..-4].to_sym
      the_proc.call(model.send(reference).to_s)
    else
      the_proc.call(new_val)
    end
  elsif key.index("_id") # hackish, but this is a convention
    reference = key[0..-4].to_sym
    "#{key.titleize} changed to #{model.send(reference).to_s}"
  else
    "#{key.titleize} changed to #{new_val}"
  end
  {:field_name => key, :message => msg, :whodunnit => Eventable.whodunnit}
end