Class: Walle::Robot::Definitions
- Inherits:
-
Object
- Object
- Walle::Robot::Definitions
- Includes:
- Middlewares::Helper
- Defined in:
- lib/walle/robot/definitions.rb
Defined Under Namespace
Classes: Stack
Constant Summary collapse
- EVENTS =
i{start hello close closed }
- METHODS =
EVENTS + i{use routes pattern}
Instance Attribute Summary collapse
-
#all_handlers ⇒ Object
readonly
Returns the value of attribute all_handlers.
Instance Method Summary collapse
- #apply_to(client) ⇒ Object
- #handlers(event = nil) ⇒ Object
-
#initialize ⇒ Definitions
constructor
A new instance of Definitions.
- #routes(&block) ⇒ Object
Methods included from Middlewares::Helper
Constructor Details
#initialize ⇒ Definitions
33 34 35 |
# File 'lib/walle/robot/definitions.rb', line 33 def initialize @all_handlers = Hash.new { |h, k| h[k] = [] } end |
Instance Attribute Details
#all_handlers ⇒ Object (readonly)
Returns the value of attribute all_handlers.
31 32 33 |
# File 'lib/walle/robot/definitions.rb', line 31 def all_handlers @all_handlers end |
Instance Method Details
#apply_to(client) ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/walle/robot/definitions.rb', line 48 def apply_to(client) all_handlers.each do |event, event_handlers| event_handlers.each do |handler| client.on(event) do |data| handle_event(environment(event, client, data), handler) end end end end |
#handlers(event = nil) ⇒ Object
58 59 60 61 |
# File 'lib/walle/robot/definitions.rb', line 58 def handlers(event = nil) return all_handlers[event] if event all_handlers.values.flatten.uniq end |
#routes(&block) ⇒ Object
43 44 45 46 |
# File 'lib/walle/robot/definitions.rb', line 43 def routes(&block) router = Router.new(&block) { |env| router.call(env) } end |