Module: Card::Set::Event::Callbacks

Included in:
Card::Set::Event
Defined in:
card/lib/card/set/event/callbacks.rb

Instance Method Summary collapse

Instance Method Details

#set_event_callback(object_method, kind) ⇒ Object



13
14
15
16
17
18
19
20
# File 'card/lib/card/set/event/callbacks.rb', line 13

def set_event_callback object_method, kind
  valid_event_callback kind, object_method do
    Card.class_exec(self) do |event|
      set_callback object_method, kind, event.name,
                   prepend: true, if: proc { |c| c.event_applies?(event) }
    end
  end
end

#set_event_callbacksObject



5
6
7
8
9
10
11
# File 'card/lib/card/set/event/callbacks.rb', line 5

def set_event_callbacks
  %i[before after around].each do |kind|
    next unless (object_method = @opts.delete kind)

    set_event_callback object_method, kind
  end
end

#valid_event_callback(kind, method) ⇒ Object



22
23
24
25
26
# File 'card/lib/card/set/event/callbacks.rb', line 22

def valid_event_callback kind, method
  yield
rescue NoMethodError
  raise "invalid event callback: `#{kind}: #{method}`"
end