Sha256: 72da73e17038a4503b21500b8464ea49aa2ac3375ab1cf725197f338c8aedd68
Contents?: true
Size: 1.91 KB
Versions: 9
Compression:
Stored size: 1.91 KB
Contents
# -*- encoding : utf-8 -*- class Card; module Set; class Abstract; module Pointer; # Set: Abstract (Pointer, Events) # module Events; extend Card::Set def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/pointer/set/abstract/02_pointer/events.rb"; end 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, :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 def item_to_insert Env.params["insert_item"] end # 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) event :standardize_items, :prepare_to_validate, on: :save, changed: :content, when: :still_pointer? do self.content = item_names(context: :raw).map do |name| "[[#{name}]]" end.join "\n" end def still_pointer? type_id == Card::PointerID end stage_method :changed_item_names do dropped_item_names + added_item_names end stage_method :dropped_item_names do old_items = item_names content: db_content_before_act old_items - item_names end stage_method :added_item_names do old_items = item_names content: db_content_before_act item_names - old_items end stage_method :changed_item_cards do item_cards content: changed_item_names end end;end;end;end;end; # ~~ generated from /Users/ethan/dev/decko/gem/card/mod/pointer/set/abstract/02_pointer/events.rb ~~
Version data entries
9 entries across 9 versions & 1 rubygems