Method: ActiveWindow::Application#dispatch

Defined in:
lib/active_window/application.rb

#dispatch(handler, event) ⇒ Object

dispatch a signal to the correct controller



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/active_window/application.rb', line 73

def dispatch(handler, event)
  controller_name,action = handler.to_s.split('.')
  unless controller_name and action
    return(error "cannot parse handler '%s'" % handler)
  end

  name = controller_name.to_sym 
  ctrl = controller[name]
  unless ctrl
    puts controller.inspect
    return(error "no controller '%s' defined" % controller_name.camelize)
  end
  
  unless ctrl.respond_to? action
    return(error "controller '%s' does not have a method '%s'" % [ctrl.class, action])
  end
  
  method = ctrl.method(action)
  #puts "calling %s.%s" % [controller_name.camelize, action]
  if method.arity == 0
    method.call
  else
    method.call(event)
  end
end