Class: GridCLI::Hooker

Inherits:
Object
  • Object
show all
Defined in:
lib/gridcli/hooks.rb

Instance Method Summary collapse

Constructor Details

#initializeHooker

Returns a new instance of Hooker.



3
4
5
# File 'lib/gridcli/hooks.rb', line 3

def initialize
  @hooks = {}
end

Instance Method Details

#invoke(name, arg = nil) ⇒ Object



11
12
13
# File 'lib/gridcli/hooks.rb', line 11

def invoke(name, arg=nil)
  @hooks.fetch(name, []).inject(arg) { |params,proc| proc.call(params) }
end

#register(name, &method) ⇒ Object



7
8
9
# File 'lib/gridcli/hooks.rb', line 7

def register(name, &method)
  @hooks[name] = @hooks.fetch(name, []) + [method]
end