Class: Artisan::Callbacks
- Inherits:
-
Object
- Object
- Artisan::Callbacks
- Defined in:
- lib/artisan/callbacks.rb
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
readonly
Returns the value of attribute callbacks.
Class Method Summary collapse
Instance Method Summary collapse
- #call(name, *args) ⇒ Object
-
#initialize ⇒ Callbacks
constructor
A new instance of Callbacks.
- #on(name, &block) ⇒ Object
Constructor Details
#initialize ⇒ Callbacks
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
#callbacks ⇒ Object (readonly)
Returns the value of attribute callbacks.
3 4 5 |
# File 'lib/artisan/callbacks.rb', line 3 def callbacks @callbacks end |
Class Method Details
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 |