module Card::Set::Event::All
card methods for scheduling events and testing event applicability
Public Instance Methods
event_applies?(event)
click to toggle source
# File lib/card/set/event/all.rb, line 16 def event_applies? event return unless set_condition_applies? event.set_module, event.opts[:changing] CONDITIONS.all? { |c| send "#{c}_condition_applies?", event, event.opts[c] } end
schedule(event)
click to toggle source
# File lib/card/set/event/all.rb, line 6 def schedule event @scheduled ||= {} return if @scheduled[event.to_sym] send :"#{event}_with_delay" @scheduled[event.to_sym] = true end
Private Instance Methods
changed_condition_applies?(_event, db_columns)
click to toggle source
# File lib/card/set/event/all.rb, line 67 def changed_condition_applies? _event, db_columns return true unless action == :update db_columns = Array(db_columns).compact return true if db_columns.empty? db_columns.any? { |col| single_changed_condition_applies? col } end
Also aliased as: changing_condition_applies?
no_current_action?()
click to toggle source
prevents locking in set_condition_card
# File lib/card/set/event/all.rb, line 53 def no_current_action? return false if @current_action @set_condition_card = nil true end
on_condition_applies?(_event, actions)
click to toggle source
# File lib/card/set/event/all.rb, line 30 def on_condition_applies? _event, actions actions = Array(actions).compact actions.empty? ? true : actions.include?(action) end
set_condition_applies?(set_module, old_sets)
click to toggle source
# File lib/card/set/event/all.rb, line 24 def set_condition_applies? set_module, old_sets return true if set_module == Card set_condition_card(old_sets).singleton_class.include? set_module end
set_condition_card(old_sets)
click to toggle source
if changing name/type, the old card has no-longer-applicable set modules, so we create a new card to determine whether events apply. (note: cached condition card would ideally be cleared after all conditions are reviewed) @param old_sets [True/False] whether to use the old_sets
# File lib/card/set/event/all.rb, line 40 def set_condition_card old_sets return self if old_sets || no_current_action? @set_condition_card ||= updating_sets? ? set_condition_card_with_new_set_modules : self end
set_condition_card_with_new_set_modules()
click to toggle source
# File lib/card/set/event/all.rb, line 60 def set_condition_card_with_new_set_modules cc = Card.find id cc.name = name cc.type_id = type_id cc.include_set_modules end
single_changed_condition_applies?(db_column)
click to toggle source
# File lib/card/set/event/all.rb, line 85 def single_changed_condition_applies? db_column return true unless db_column send "#{db_column}_is_changing?" end
updating_sets?()
click to toggle source
existing card is being changed in a way that alters its sets
# File lib/card/set/event/all.rb, line 48 def updating_sets? action == :update && real? && (type_id_is_changing? || name_is_changing?) end
when_condition_applies?(_event, block)
click to toggle source
# File lib/card/set/event/all.rb, line 77 def when_condition_applies? _event, block case block when Proc then block.call(self) when Symbol then send block else true end end
wrong_action(actn)
click to toggle source
# File lib/card/set/event/all.rb, line 101 def wrong_action actn return false if on_condition_applies?(nil, actn) "on: #{actn} method #{method} called on #{action}" end
wrong_stage(opts)
click to toggle source
# File lib/card/set/event/all.rb, line 91 def wrong_stage opts return false if director.stage_ok? opts if !stage "phase method #{method} called outside of event phases" else "#{opts.inspect} method #{method} called in stage #{stage}" end end