Class: RollbackerChange
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- RollbackerChange
show all
- Includes:
- Rollbacker::Status
- Defined in:
- lib/rollbacker/rollbacker_change.rb
Instance Method Summary
collapse
#disable_rollbacker!, #enable_rollbacker!, #rollbacker_as, #rollbacker_disabled?, #rollbacker_enabled?, #with_rollbacker, #without_rollbacker
Instance Method Details
#approve(*fields) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/rollbacker/rollbacker_change.rb', line 36
def approve(*fields)
without_rollbacker do
edits = self.new_attributes(*fields)
case self.action.to_s
when 'update'
if edits.present? && self.rollbackable && self.rollbackable.update_attributes(edits)
update_changes_after_approve_or_reject(*fields)
return true
end
when 'create'
if edits.present? && self.rollbackable_type.constantize.create(edits)
self.rollbacked_changes = nil
self.destroy
end
when 'destroy'
if self.rollbackable && self.rollbackable.destroy
self.rollbacked_changes = nil
self.destroy
end
end
end
end
|
#create_action? ⇒ Boolean
59
|
# File 'lib/rollbacker/rollbacker_change.rb', line 59
def create_action?; self[:action].to_s == 'create' end
|
#destroy_action? ⇒ Boolean
61
|
# File 'lib/rollbacker/rollbacker_change.rb', line 61
def destroy_action?; self[:action].to_s == 'destroy' end
|
#new_attributes(*fields) ⇒ Object
14
15
16
17
18
19
20
21
|
# File 'lib/rollbacker/rollbacker_change.rb', line 14
def new_attributes(*fields)
(rollbacked_changes || {}).inject({}.with_indifferent_access) do |attrs,(attr,values)|
attrs[attr] = values.is_a?(Array) ? values.last : values
attrs
end.select do |k,v|
fields.blank? ? true : fields.map(&:to_s).include?(k)
end
end
|
#reject(*fields) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/rollbacker/rollbacker_change.rb', line 24
def reject(*fields)
without_rollbacker do
case self.action.to_s
when 'update', 'create'
update_changes_after_approve_or_reject(*fields)
when 'destroy'
self.rollbacked_changes = nil
self.destroy
end
end
end
|
#update_action? ⇒ Boolean
60
|
# File 'lib/rollbacker/rollbacker_change.rb', line 60
def update_action?; self[:action].to_s == 'update' end
|