Module: Xot::Invoker

Defined in:
lib/xot/invoker.rb

Instance Method Summary collapse

Instance Method Details

#add_handler(handler) ⇒ Object



20
21
22
23
24
# File 'lib/xot/invoker.rb', line 20

def add_handler(handler)
  return unless handler
  a = self.handlers true
  a.push handler unless a.include? handler
end

#handlers(create = false) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/xot/invoker.rb', line 12

def handlers(create = false)
  if create
    @handlers ||= []
  else
    @handlers ? @handlers : []
  end
end

#initializeObject



9
10
# File 'lib/xot/invoker.rb', line 9

def initialize()
end

#invoke(name, attributes = {}, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/xot/invoker.rb', line 31

def invoke(name, attributes = {}, options = {})
  only     = options[:only]
  only     = [only] if only && !only.kind_of?(Array)
  handlers = only ? only : @handlers
  return unless handlers

  handlers.each do |handler|
    handler.send name, OpenStruct.new(attributes) if handler.respond_to? name
  end
end

#remove_handler(handler) ⇒ Object



26
27
28
29
# File 'lib/xot/invoker.rb', line 26

def remove_handler(handler)
  return unless handler
  self.handlers.delete handler
end