Class: BBServer::Route
- Inherits:
-
Object
- Object
- BBServer::Route
- Defined in:
- lib/bbserver/route.rb
Instance Attribute Summary collapse
-
#handler_proc ⇒ Object
readonly
Returns the value of attribute handler_proc.
-
#middlewares ⇒ Object
readonly
Returns the value of attribute middlewares.
Class Method Summary collapse
Instance Method Summary collapse
- #any? ⇒ Boolean
- #call(&block) ⇒ Object
-
#initialize(method: nil, path: nil, middlewares: [], any: false) ⇒ Route
constructor
A new instance of Route.
- #method ⇒ Object
- #path ⇒ Object
- #use(&block) ⇒ Object
Constructor Details
#initialize(method: nil, path: nil, middlewares: [], any: false) ⇒ Route
Returns a new instance of Route.
11 12 13 14 15 16 17 18 |
# File 'lib/bbserver/route.rb', line 11 def initialize(method: nil, path: nil, middlewares: [], any: false) raise ArgumentError, "Method and Path are required for non-ANY routes" unless any || (method && path) @method = method @path = path @middlewares = middlewares @any = any end |
Instance Attribute Details
#handler_proc ⇒ Object (readonly)
Returns the value of attribute handler_proc.
5 6 7 |
# File 'lib/bbserver/route.rb', line 5 def handler_proc @handler_proc end |
#middlewares ⇒ Object (readonly)
Returns the value of attribute middlewares.
5 6 7 |
# File 'lib/bbserver/route.rb', line 5 def middlewares @middlewares end |
Class Method Details
.any(middlewares = []) ⇒ Object
7 8 9 |
# File 'lib/bbserver/route.rb', line 7 def self.any(middlewares = []) new(method: nil, path: nil, middlewares: middlewares, any: true) end |
Instance Method Details
#any? ⇒ Boolean
30 31 32 |
# File 'lib/bbserver/route.rb', line 30 def any? @any end |
#call(&block) ⇒ Object
39 40 41 |
# File 'lib/bbserver/route.rb', line 39 def call(&block) @handler_proc = block end |
#method ⇒ Object
20 21 22 23 |
# File 'lib/bbserver/route.rb', line 20 def method raise RuntimeError, "Method is not defined for this route" if @method.nil? @method end |
#path ⇒ Object
25 26 27 28 |
# File 'lib/bbserver/route.rb', line 25 def path raise RuntimeError, "Path is not defined for this route" if @path.nil? @path end |
#use(&block) ⇒ Object
34 35 36 37 |
# File 'lib/bbserver/route.rb', line 34 def use(&block) @middlewares << block self end |