Module: Card::Set::Abstract::List::Events
- Extended by:
- Card::Set
- Defined in:
- platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb
Overview
Set: Abstract (List, 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
Methods included from I18nScope
#mod_name, #scope
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
#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
#include_set, #include_set_formats
Methods included from Trait
#card_accessor, #card_reader, #card_writer, #require_field
Methods included from Event::Api
#event
Class Method Details
.source_location ⇒ Object
7
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 7
def self.source_location; "/Users/ethan/dev/decko/gem/mod/list/set/abstract/01_list/events.rb"; end
|
Instance Method Details
#added_item_cards ⇒ Object
94
95
96
97
98
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 94
def added_item_cards
return item_cards unless db_content_before_act
all_item_cards item_names: added_item_names
end
|
#added_item_names ⇒ Object
72
73
74
75
76
77
78
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 72
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_cards ⇒ Object
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.
84
85
86
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 84
def changed_item_cards
dropped_item_cards + added_item_cards
end
|
#changed_item_names ⇒ Object
60
61
62
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 60
def changed_item_names
dropped_item_names + added_item_names
end
|
#dropped_item_cards ⇒ Object
88
89
90
91
92
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 88
def dropped_item_cards
return [] unless db_content_before_act
all_item_cards item_names: dropped_item_names
end
|
#dropped_item_names ⇒ Object
64
65
66
67
68
69
70
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 64
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
|
#duplicate_item_names ⇒ Object
38
39
40
41
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 38
def duplicate_item_names
names = item_names
names.uniq.select { |n| names.count(n) > 1 }
end
|
#event: add_and_drop_items ⇒ Object
8
9
10
11
12
13
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/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_event ⇒ Object
15
16
17
18
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/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: validate_item_type ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 20
event :validate_item_type, :validate, on: :save, when: :validate_item_type? do
ok_types = Array.wrap(ok_item_types).map(&:codename)
item_cards.each do |item|
next if ok_types.include? item.type_code
errors.add :content, t(:list_invalid_item_type,
item: item.name,
type: item.type,
allowed_types: ok_types.map(&:cardname).to_sentence)
end
end
|
#event: validate_item_uniqueness ⇒ Object
32
33
34
35
36
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 32
event :validate_item_uniqueness, :validate, on: :save, when: :unique_items? do
return unless (dupes = duplicate_item_names)&.present?
errors.add :content, t(:list_duplicate_items_names, duplicates: dupes.to_sentence)
end
|
#item_to_insert ⇒ Object
56
57
58
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 56
def item_to_insert
Env.params["insert_item"]
end
|
#ok_item_types ⇒ Object
48
49
50
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 48
def ok_item_types
nil
end
|
#unique_items? ⇒ Boolean
44
45
46
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 44
def unique_items?
false
end
|
#validate_item_type? ⇒ Boolean
52
53
54
|
# File 'platypus/tmp/set/gem-defaults/mod005-list/abstract/01_list/events.rb', line 52
def validate_item_type?
ok_item_types.present?
end
|