Module: Xot::Invoker

Defined in:
lib/xot/invoker.rb

Instance Method Summary collapse

Instance Method Details

#add_handler(handler) ⇒ Object



23
24
25
26
27
# File 'lib/xot/invoker.rb', line 23

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

#handlers(create = false) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/xot/invoker.rb', line 15

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

#initializeObject



12
13
# File 'lib/xot/invoker.rb', line 12

def initialize()
end

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



34
35
36
37
38
39
40
41
42
43
# File 'lib/xot/invoker.rb', line 34

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



29
30
31
32
# File 'lib/xot/invoker.rb', line 29

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