Class: Atoms::Router
- Inherits:
-
Object
- Object
- Atoms::Router
- Defined in:
- lib/atoms.rb
Class Attribute Summary collapse
-
.endpoints ⇒ Object
Returns the value of attribute endpoints.
Instance Attribute Summary collapse
-
#routes ⇒ Object
Returns the value of attribute routes.
Class Method Summary collapse
- .add(endpoint) ⇒ Object
- .attach(c) ⇒ Object
- .config(&block) ⇒ Object
- .respond(header, data = {}) ⇒ Object
Class Attribute Details
.endpoints ⇒ Object
Returns the value of attribute endpoints.
23 24 25 |
# File 'lib/atoms.rb', line 23 def endpoints @endpoints end |
Instance Attribute Details
#routes ⇒ Object
Returns the value of attribute routes.
19 20 21 |
# File 'lib/atoms.rb', line 19 def routes @routes end |
Class Method Details
.add(endpoint) ⇒ Object
35 36 37 38 |
# File 'lib/atoms.rb', line 35 def add(endpoint) self.endpoints = [] unless self.endpoints self.endpoints << endpoint end |
.attach(c) ⇒ Object
31 32 33 |
# File 'lib/atoms.rb', line 31 def attach(c) @router.routes << c.new end |
.config(&block) ⇒ Object
25 26 27 28 29 |
# File 'lib/atoms.rb', line 25 def config(&block) @router = new @router.routes = [] instance_eval(&block) end |
.respond(header, data = {}) ⇒ Object
40 41 42 43 44 |
# File 'lib/atoms.rb', line 40 def respond(header, data = {}) index = endpoints.index{|e| e.header == header} endpoint = endpoints[index] if index endpoint.call(data) if endpoint # encode to rocket_amf and send back to server end |