Class: Walle::Robot::Router::Route
- Inherits:
-
Object
- Object
- Walle::Robot::Router::Route
- Defined in:
- lib/walle/robot/router/route.rb
Defined Under Namespace
Classes: Direct, Mutator, Prefix
Constant Summary collapse
- MUTATORS =
[Direct, Prefix]
Instance Attribute Summary collapse
-
#controller ⇒ Object
(also: #cntrl)
readonly
Returns the value of attribute controller.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(controller:, regexp: nil, **options) ⇒ Route
constructor
A new instance of Route.
- #match?(env) ⇒ Boolean
Constructor Details
#initialize(controller:, regexp: nil, **options) ⇒ Route
Returns a new instance of Route.
51 52 53 54 55 |
# File 'lib/walle/robot/router/route.rb', line 51 def initialize(controller:, regexp: nil, **) @controller = controller = @regexp = regexp end |
Instance Attribute Details
#controller ⇒ Object (readonly) Also known as: cntrl
Returns the value of attribute controller.
6 7 8 |
# File 'lib/walle/robot/router/route.rb', line 6 def controller @controller end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/walle/robot/router/route.rb', line 6 def end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
6 7 8 |
# File 'lib/walle/robot/router/route.rb', line 6 def regexp @regexp end |
Instance Method Details
#call(env) ⇒ Object
62 63 64 65 66 |
# File 'lib/walle/robot/router/route.rb', line 62 def call(env) expr = final_regexp(env) env.matches = expr.match(env.data.text) if expr cntrl.respond_to?(:call) ? cntrl.call(env) : cntrl.new(env).call end |
#match?(env) ⇒ Boolean
57 58 59 60 |
# File 'lib/walle/robot/router/route.rb', line 57 def match?(env) expr = final_regexp(env) !!expr.match(env.data.text) end |