Module: Card::Set::Abstract::Pointer::Events

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb,
card/tmpsets/set/mod008-card-mod-list/abstract/01_pointer/events.rb

Overview

Set: Abstract (Pointer, Events)

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

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, #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 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

#event

Class Method Details

.source_locationObject



7
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card-mod-list/set/abstract/01_pointer/events.rb"; end

Instance Method Details

#added_item_cardsObject



74
75
76
77
78
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 74

def added_item_cards
  return item_cards unless db_content_before_act

  all_item_cards item_names: added_item_names
end

#added_item_namesObject



52
53
54
55
56
57
58
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 52

def added_item_names
  return [] if trash
  return item_names unless (old_content = db_content_before_act)

  old_items = item_names content: old_content
  item_names - old_items
end

#changed_item_cardsObject

TODO: refactor. many of the above could be written more elegantly with improved handling of :content in item_names. If content is nil here, we would expect an empty set of cards, but in fact we get items based on self.content.



64
65
66
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 64

def changed_item_cards
  dropped_item_cards + added_item_cards
end

#changed_item_namesObject



40
41
42
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 40

def changed_item_names
  dropped_item_names + added_item_names
end

#dropped_item_cardsObject



68
69
70
71
72
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 68

def dropped_item_cards
  return [] unless db_content_before_act

  all_item_cards item_names: dropped_item_names
end

#dropped_item_namesObject



44
45
46
47
48
49
50
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 44

def dropped_item_names
  return item_names if trash
  return [] unless (old_content = db_content_before_act)

  old_items = item_names content: old_content
  old_items - item_names
end

#event: add_and_drop_itemsObject



8
9
10
11
12
13
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 8

event :add_and_drop_items, :prepare_to_validate, on: :save do
  adds = Env.params["add_item"]
  drops = Env.params["drop_item"]
  Array.wrap(adds).each { |i| add_item i } if adds
  Array.wrap(drops).each { |i| drop_item i } if drops
end

#event: insert_item_eventObject



15
16
17
18
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 15

event :insert_item_event, :prepare_to_validate, on: :save, when: :item_to_insert do
  index = Env.params["item_index"] || 0
  insert_item index.to_i, item_to_insert
end

#event: standardize_itemsObject

If a card’s type and content are updated in the same action, the new module will override the old module’s events and functions. But this event is only on pointers – other type cards do not have this event, Therefore if something is changed from a pointer and its content is changed in the same action, this event will be run and will treat the content like it’ still pointer content. The “when” clause helps with that (but is a hack)



30
31
32
33
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 30

event :standardize_items, :prepare_to_validate,
      on: :save, changed: :content, when: :still_pointer? do
  items_to_content item_strings
end

#item_to_insertObject



20
21
22
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 20

def item_to_insert
  Env.params["insert_item"]
end

#still_pointer?Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'card/tmpsets/set/mod009-card-mod-list/abstract/01_pointer/events.rb', line 35

def still_pointer?
  type_id == PointerID
  # Card.new(type_id: type_id).is_a? Abstract::Pointer
end