Module: Card::Set::All::History::Revision
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod005-history/all/history/revision.rb
Overview
Set: All cards (History, Revision)
Constant Summary
Constants included from Helpers
Helpers::SET_PATTERN_TEST_REGEXP
Class Method Summary collapse
Instance Method Summary collapse
- #actions_to_revert ⇒ Object
- #explicit_actions_to_revert ⇒ Object
- #merge_revert_action!(action, update_args, reverting_to_previous) ⇒ Object
- #process_revert_actions(revert_actions = nil) ⇒ Object
- #revision(action, before_action = false) ⇒ Object
- #revision_attributes(action) ⇒ Object
- #revision_before_action(action) ⇒ Object
- #rollback_request? ⇒ Boolean
Methods included from Card::Set
Methods included from I18nScope
Methods included from Loader
#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set
Methods included from Helpers
#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore
Methods included from Card::Set::AdvancedApi
#attachment, #ensure_set, #stage_method
Methods included from Format
#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name
Methods included from Inheritance
#include_set, #include_set_formats
Methods included from Basket
#abstract_basket, #add_to_basket, #basket, #unshift_basket
Methods included from Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
Class Method Details
.source_location ⇒ Object
7 |
# File 'tmpsets/set/mod005-history/all/history/revision.rb', line 7 def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/history/set/all/history/revision.rb"; end |
Instance Method Details
#actions_to_revert ⇒ Object
50 51 52 53 54 55 56 |
# File 'tmpsets/set/mod005-history/all/history/revision.rb', line 50 def actions_to_revert if (act_id = Env.params["revert_act"]) Act.find(act_id).actions else explicit_actions_to_revert end end |
#explicit_actions_to_revert ⇒ Object
58 59 60 61 62 |
# File 'tmpsets/set/mod005-history/all/history/revision.rb', line 58 def explicit_actions_to_revert Array.wrap(Env.params["revert_actions"]).map do |a_id| Action.fetch(a_id) || nil end.compact end |
#merge_revert_action!(action, update_args, reverting_to_previous) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'tmpsets/set/mod005-history/all/history/revision.rb', line 64 def merge_revert_action! action, update_args, reverting_to_previous rev = action.card.revision(action, reverting_to_previous) if action.card_id == id update_args.merge! rev else update_args[:subcards][action.card.name] = rev end end |
#process_revert_actions(revert_actions = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'tmpsets/set/mod005-history/all/history/revision.rb', line 40 def process_revert_actions revert_actions=nil revert_actions ||= actions_to_revert update_args = { subcards: {} } reverting_to_previous = Env.params["revert_to"] == "previous" revert_actions.each do |action| merge_revert_action! action, update_args, reverting_to_previous end update_args end |
#revision(action, before_action = false) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'tmpsets/set/mod005-history/all/history/revision.rb', line 8 def revision action, before_action=false # a "revision" refers to the state of all tracked fields # at the time of a given action action = Card::Action.fetch(action) if action.is_a? Integer return unless action if before_action revision_before_action action else revision_attributes action end end |
#revision_attributes(action) ⇒ Object
21 22 23 24 25 26 |
# File 'tmpsets/set/mod005-history/all/history/revision.rb', line 21 def revision_attributes action Card::Change::TRACKED_FIELDS.each_with_object({}) do |field, attr_changes| last_change = action.change(field) || last_change_on(field, not_after: action) attr_changes[field.to_sym] = (last_change ? last_change.value : self[field]) end end |
#revision_before_action(action) ⇒ Object
28 29 30 31 32 33 34 |
# File 'tmpsets/set/mod005-history/all/history/revision.rb', line 28 def revision_before_action action if (prev_action = action.previous_action) revision prev_action else { trash: true } end end |
#rollback_request? ⇒ Boolean
36 37 38 |
# File 'tmpsets/set/mod005-history/all/history/revision.rb', line 36 def rollback_request? history? && actions_to_revert.any? end |