Module: Card::Set::All::History
- Extended by:
- Card::Set
- Defined in:
- platypus/tmp/set/gem-defaults/mod015-history/all/history.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/acts.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/last.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/views.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/events.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/actions.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/revision.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/selected.rb,
platypus/tmp/set/gem-defaults/mod015-history/all/history/act_listing.rb
Overview
Set: All cards (History)
Defined Under Namespace
Modules: ActListing, Actions, Acts, Events, Last, Revision, Selected, Views
Constant Summary
Constants included from Helpers
Helpers::SET_PATTERN_TEST_REGEXP
Constants included from Event::Api
Class Method Summary collapse
Instance Method Summary collapse
-
#action_count ⇒ Object
-
#changed_fields ⇒ Object
-
#clear_history ⇒ Object
-
#delete_all_changes ⇒ Object
-
#delete_old_actions ⇒ Object
-
#diff_args ⇒ Object
-
#event: update_ancestor_timestamps ⇒ Object
-
#first_change? ⇒ Boolean
~~FIXME~~: optimize (no need to instantiate all actions and changes!) Nothing is instantiated here.
-
#first_create? ⇒ Boolean
-
#has_edits? ⇒ Boolean
card has account that is responsible for prior acts.
-
#history? ⇒ Boolean
track history (acts, actions, changes) on this card.
-
#history_ancestor_ids(recursion_level = 0) ⇒ Object
-
#history_card_ids ⇒ Object
all cards whose acts are considered part of this card’s history.
-
#history_parent_ids ⇒ Object
all cards who are considered updated if this card’s was updated.
-
#make_last_action_the_initial_action ⇒ Object
Delete all changes and old actions and make the last action the create action (that way the changes for that action will be created with the first update).
-
#nestee_ids ⇒ Object
-
#nester_ids ⇒ Object
-
#save_content_draft(content) ⇒ Object
Methods included from Card::Set
Methods included from I18nScope
Methods included from Registrar
#extended, #finalize_load, #process_base_modules, #register_set
Methods included from Helpers
#format_module, #format_modules, #method_missing, #modules, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscored_name
Methods included from Card::Set::AdvancedApi
#assign_type, #attachment, #define_set_from_error, #ensure_set, #setting_opts, #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 Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
Class Method Details
.source_location ⇒ Object
7 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 7 def self.source_location; "/Users/ethan/dev/decko/gem/mod/history/set/all/history.rb"; end |
Instance Method Details
#action_count ⇒ Object
53 54 55 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 53 def action_count Card::Action.where(card_id: @current_action.card_id).count end |
#changed_fields ⇒ Object
62 63 64 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 62 def changed_fields Card::Change::TRACKED_FIELDS & (changed_attribute_names_to_save | saved_changes.keys) end |
#clear_history ⇒ Object
86 87 88 89 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 86 def clear_history delete_all_changes delete_old_actions end |
#delete_all_changes ⇒ Object
95 96 97 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 95 def delete_all_changes Card::Change.where(card_action_id: all_action_ids).delete_all end |
#delete_old_actions ⇒ Object
91 92 93 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 91 def delete_old_actions old_actions.delete_all end |
#diff_args ⇒ Object
74 75 76 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 74 def diff_args { diff_format: :text } end |
#event: update_ancestor_timestamps ⇒ Object
8 9 10 11 12 13 14 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 8 event :update_ancestor_timestamps, :integrate do ids = history_ancestor_ids return unless ids.present? Card.where(id: ids).update_all(updater_id: Auth.current_id, updated_at: Time.now) ids.map { |anc_id| Card.expire anc_id.cardname } end |
#first_change? ⇒ Boolean
~~FIXME~~: optimize (no need to instantiate all actions and changes!) Nothing is instantiated here. ActiveRecord is much smarter than you think. Methods like #empty? and #size make sql queries if their receivers are not already loaded -pk
43 44 45 46 47 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 43 def first_change? # = update or delete @current_action.action_type != :create && action_count == 2 && create_action.card_changes.empty? end |
#first_create? ⇒ Boolean
49 50 51 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 49 def first_create? @current_action.action_type == :create && action_count == 1 end |
#has_edits? ⇒ Boolean
card has account that is responsible for prior acts
58 59 60 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 58 def has_edits? Card::Act.where(actor_id: id).where("card_id IS NOT NULL").present? end |
#history? ⇒ Boolean
track history (acts, actions, changes) on this card
17 18 19 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 17 def history? true end |
#history_ancestor_ids(recursion_level = 0) ⇒ Object
31 32 33 34 35 36 37 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 31 def history_ancestor_ids recursion_level=0 return [] if recursion_level > 5 ids = history_parent_ids + history_parent_ids.map { |id| Card[id].history_ancestor_ids(recursion_level + 1) } ids.flatten end |
#history_card_ids ⇒ Object
all cards whose acts are considered part of this card’s history
22 23 24 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 22 def history_card_ids nestee_ids << id end |
#history_parent_ids ⇒ Object
all cards who are considered updated if this card’s was updated
27 28 29 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 27 def history_parent_ids nester_ids end |
#make_last_action_the_initial_action ⇒ Object
Delete all changes and old actions and make the last action the create action (that way the changes for that action will be created with the first update)
80 81 82 83 84 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 80 def make_last_action_the_initial_action delete_all_changes old_actions.delete_all last_action.update! action_type: :create end |
#nestee_ids ⇒ Object
66 67 68 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 66 def nestee_ids requiring_id { @nestee_ids ||= nesting_ids(:referee_id, :referer_id) } end |
#nester_ids ⇒ Object
70 71 72 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 70 def nester_ids requiring_id { @nester_ids ||= nesting_ids(:referer_id, :referee_id) } end |
#save_content_draft(content) ⇒ Object
99 100 101 102 103 104 105 |
# File 'platypus/tmp/set/gem-defaults/mod015-history/all/history.rb', line 99 def save_content_draft content super acts.create do |act| act.ar_actions.build(draft: true, card_id: id, action_type: :update) .card_changes.build(field: :db_content, value: content) end end |