Class: QbertBot::Router
- Inherits:
-
Object
- Object
- QbertBot::Router
- Defined in:
- lib/qbert_bot/router.rb
Instance Attribute Summary collapse
-
#bind ⇒ Object
readonly
Returns the value of attribute bind.
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #exec_route(method, request, params) ⇒ Object
- #get(path, &block) ⇒ Object
-
#initialize(conf) ⇒ Router
constructor
A new instance of Router.
- #post(path, &block) ⇒ Object
Constructor Details
#initialize(conf) ⇒ Router
Returns a new instance of Router.
7 8 9 10 11 12 |
# File 'lib/qbert_bot/router.rb', line 7 def initialize(conf) @routes = [] @bind = conf['bind'] @port = conf['port'] @endpoint = conf['endpoint'] end |
Instance Attribute Details
#bind ⇒ Object (readonly)
Returns the value of attribute bind.
5 6 7 |
# File 'lib/qbert_bot/router.rb', line 5 def bind @bind end |
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/qbert_bot/router.rb', line 5 def endpoint @endpoint end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
5 6 7 |
# File 'lib/qbert_bot/router.rb', line 5 def port @port end |
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
5 6 7 |
# File 'lib/qbert_bot/router.rb', line 5 def routes @routes end |
Instance Method Details
#exec_route(method, request, params) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/qbert_bot/router.rb', line 22 def exec_route(method, request, params) @routes.each do |route| next unless route.method == method next unless match = request.path_info.match(route.path) return route.proc.call(request, params, match) end return 'no route' end |
#get(path, &block) ⇒ Object
14 15 16 |
# File 'lib/qbert_bot/router.rb', line 14 def get(path, &block) add_route(:get, path, &block) end |
#post(path, &block) ⇒ Object
18 19 20 |
# File 'lib/qbert_bot/router.rb', line 18 def post(path, &block) add_route(:post, path, &block) end |