Class: Artisan::Callbacks

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCallbacks

Returns a new instance of Callbacks.



5
6
7
# File 'lib/artisan/callbacks.rb', line 5

def initialize
  @callbacks = Hash.new
end

Instance Attribute Details

#callbacksObject (readonly)

Returns the value of attribute callbacks.



3
4
5
# File 'lib/artisan/callbacks.rb', line 3

def callbacks
  @callbacks
end

Class Method Details

.build(&block) ⇒ Object



9
10
11
12
13
# File 'lib/artisan/callbacks.rb', line 9

def self.build(&block)
  builder = Callbacks.new
  block.call(builder)
  builder
end

Instance Method Details

#call(name, *args) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/artisan/callbacks.rb', line 19

def call(name, *args)
  unless @callbacks.has_key?(name)
    raise ArgumentError, "You are missing one of the expected callbacks. Missing: #{name} callback"
  end

  @callbacks[name].call(*args)
end

#on(name, &block) ⇒ Object



15
16
17
# File 'lib/artisan/callbacks.rb', line 15

def on(name, &block)
  @callbacks[name] = Proc.new(&block)
end