Class: Card::Action
- Defined in:
- mod/01_history/lib/card/action.rb
Constant Summary collapse
- TYPE =
replace with enum if we start using rails 4
[:create, :update, :delete].freeze
Class Method Summary collapse
- .cache ⇒ Object
- .delete_cardless ⇒ Object
- .delete_changeless ⇒ Object
- .delete_old ⇒ Object
- .fetch(id) ⇒ Object
Instance Method Summary collapse
- #action_type ⇒ Object
- #action_type=(value) ⇒ Object
- #card ⇒ Object
- #cardtype_diff(opts = {}) ⇒ Object
- #change(field) ⇒ Object
- #changes ⇒ Object
- #content_diff(diff_type = :expanded, opts = nil) ⇒ Object
- #expire ⇒ Object
- #green? ⇒ Boolean
- #name_diff(opts = {}) ⇒ Object
- #new_content? ⇒ Boolean
- #new_name? ⇒ Boolean
- #new_type? ⇒ Boolean
- #previous_value(field) ⇒ Object
- #red? ⇒ Boolean
- #revision_nr ⇒ Object
-
#value(field) ⇒ Object
def changed_fields obj, changed_fields changed_fields.each do |f| Card::Change.create field: f, value: obj, card_action_id: id end end.
Class Method Details
.cache ⇒ Object
26 27 28 |
# File 'mod/01_history/lib/card/action.rb', line 26 def cache Card::Cache[Action] end |
.delete_cardless ⇒ Object
36 37 38 39 |
# File 'mod/01_history/lib/card/action.rb', line 36 def delete_cardless left_join = 'LEFT JOIN cards ON card_actions.card_id = cards.id' joins(left_join).where('cards.id IS NULL').delete_all end |
.delete_changeless ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'mod/01_history/lib/card/action.rb', line 41 def delete_changeless joins( 'LEFT JOIN card_changes '\ 'ON card_changes.card_action_id = card_actions.id' ).where( 'card_changes.id IS NULL' ).delete_all end |
.delete_old ⇒ Object
50 51 52 53 |
# File 'mod/01_history/lib/card/action.rb', line 50 def delete_old Card.find_each(&:delete_old_actions) Card::Act.delete_actionless end |
.fetch(id) ⇒ Object
30 31 32 33 34 |
# File 'mod/01_history/lib/card/action.rb', line 30 def fetch id cache.fetch id.to_s do find id.to_i end end |
Instance Method Details
#action_type ⇒ Object
116 117 118 |
# File 'mod/01_history/lib/card/action.rb', line 116 def action_type TYPE[read_attribute(:action_type)] end |
#action_type=(value) ⇒ Object
112 113 114 |
# File 'mod/01_history/lib/card/action.rb', line 112 def action_type= value write_attribute :action_type, TYPE.index(value) end |
#card ⇒ Object
151 152 153 |
# File 'mod/01_history/lib/card/action.rb', line 151 def card Card.fetch card_id, look_in_trash: true, skip_modules: true end |
#cardtype_diff(opts = {}) ⇒ Object
137 138 139 140 |
# File 'mod/01_history/lib/card/action.rb', line 137 def cardtype_diff opts={} return unless new_type? Card::Diff.complete previous_value(:cardtype), value(:cardtype), opts end |
#change(field) ⇒ Object
83 84 85 |
# File 'mod/01_history/lib/card/action.rb', line 83 def change field changes[interpret_field field] end |
#changes ⇒ Object
87 88 89 90 91 92 |
# File 'mod/01_history/lib/card/action.rb', line 87 def changes @changes ||= card_changes.each_with_object({}) do |change, hash| hash[change.field.to_sym] = change end end |
#content_diff(diff_type = :expanded, opts = nil) ⇒ Object
142 143 144 145 146 147 148 149 |
# File 'mod/01_history/lib/card/action.rb', line 142 def content_diff diff_type=:expanded, opts=nil return unless new_content? if diff_type == :summary content_diff_object(opts).summary else content_diff_object(opts).complete end end |
#expire ⇒ Object
19 20 21 |
# File 'mod/01_history/lib/card/action.rb', line 19 def expire self.class.cache.delete id.to_s end |
#green? ⇒ Boolean
128 129 130 |
# File 'mod/01_history/lib/card/action.rb', line 128 def green? content_diff_object.green? end |
#name_diff(opts = {}) ⇒ Object
132 133 134 135 |
# File 'mod/01_history/lib/card/action.rb', line 132 def name_diff opts={} return unless new_name? Card::Diff.complete previous_value(:name), value(:name), opts end |
#new_content? ⇒ Boolean
104 105 106 |
# File 'mod/01_history/lib/card/action.rb', line 104 def new_content? value :db_content end |
#new_name? ⇒ Boolean
108 109 110 |
# File 'mod/01_history/lib/card/action.rb', line 108 def new_name? value :name end |
#new_type? ⇒ Boolean
100 101 102 |
# File 'mod/01_history/lib/card/action.rb', line 100 def new_type? value :type_id end |
#previous_value(field) ⇒ Object
94 95 96 97 98 |
# File 'mod/01_history/lib/card/action.rb', line 94 def previous_value field return if action_type == :create return unless (previous_change = previous_change field) interpret_value field, previous_change.value end |
#red? ⇒ Boolean
124 125 126 |
# File 'mod/01_history/lib/card/action.rb', line 124 def red? content_diff_object.red? end |
#revision_nr ⇒ Object
120 121 122 |
# File 'mod/01_history/lib/card/action.rb', line 120 def revision_nr card.actions.index_of self end |
#value(field) ⇒ Object
78 79 80 81 |
# File 'mod/01_history/lib/card/action.rb', line 78 def value field return unless (change = change field) interpret_value field, change.value end |