Class: Breathing::ChangeLog
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Breathing::ChangeLog
- Defined in:
- lib/breathing/change_log.rb
Instance Method Summary collapse
- #attributes_for_excel ⇒ Object
- #changed_attribute_columns ⇒ Object
- #data ⇒ Object
- #data_attributes ⇒ Object
- #data_column_names ⇒ Object
- #diff ⇒ Object
Instance Method Details
#attributes_for_excel ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/breathing/change_log.rb', line 37 def attributes_for_excel { 'change_logs.id' => id, 'created_at' => created_at.to_fs(:db), 'table_name' => table_name, 'action' => action, 'id' => transaction_id, 'diff' => diff } end |
#changed_attribute_columns ⇒ Object
5 6 7 8 9 |
# File 'lib/breathing/change_log.rb', line 5 def changed_attribute_columns before_data.each.with_object([]) do |(column, value), columns| columns << column if after_data[column] != value end end |
#data ⇒ Object
16 17 18 |
# File 'lib/breathing/change_log.rb', line 16 def data action == 'DELETE' ? before_data : after_data end |
#data_attributes ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/breathing/change_log.rb', line 20 def data_attributes data_column_names.each.with_object('change_logs.id' => id, 'change_logs.created_at' => created_at.to_fs(:db), 'action' => action, 'id' => transaction_id) do |name, hash| hash[name] = data[name] end end |
#data_column_names ⇒ Object
11 12 13 14 |
# File 'lib/breathing/change_log.rb', line 11 def data_column_names names = before_data.keys.present? ? before_data.keys : after_data.keys names.reject { |name| name == 'id' } end |
#diff ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/breathing/change_log.rb', line 29 def diff return nil if action != 'UPDATE' changed_attribute_columns.map do |column_name| "#{column_name}: #{before_data[column_name]} -> #{after_data[column_name]}" end.join(" \n") end |