Class: FixtureKit::Callbacks

Inherits:
Object
  • Object
show all
Defined in:
lib/fixture_kit/callbacks.rb

Constant Summary collapse

EVENTS =
[
  :cache_save,
  :cache_saved,
  :cache_mount,
  :cache_mounted
].freeze

Instance Method Summary collapse

Constructor Details

#initializeCallbacks

Returns a new instance of Callbacks.



12
13
14
# File 'lib/fixture_kit/callbacks.rb', line 12

def initialize
  @callbacks = Hash.new { |hash, key| hash[key] = [] }
end

Instance Method Details

#register(event, &block) ⇒ Object



16
17
18
19
20
# File 'lib/fixture_kit/callbacks.rb', line 16

def register(event, &block)
  validate_event!(event)
  @callbacks[event] << block if block
  @callbacks[event]
end

#run(event, *args) ⇒ Object



22
23
24
25
26
27
# File 'lib/fixture_kit/callbacks.rb', line 22

def run(event, *args)
  validate_event!(event)
  @callbacks[event].each do |callback|
    callback.call(*args)
  end
end