Class: Newark::Route
- Inherits:
-
Object
- Object
- Newark::Route
- Defined in:
- lib/newark/route.rb
Defined Under Namespace
Classes: Constraint
Constant Summary collapse
- PARAM_MATCHER =
/:(?<param>[^\/]*)/.freeze
- PARAM_SUB =
/:[^\/]*/.freeze
- PATH_MATCHER =
/\*(?<path>.*)/.freeze
- PATH_SUB =
/\*.*/.freeze
Instance Attribute Summary collapse
-
#handler ⇒ Object
readonly
Returns the value of attribute handler.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(path, constraints, handler) ⇒ Route
constructor
A new instance of Route.
- #match?(request) ⇒ Boolean
Constructor Details
#initialize(path, constraints, handler) ⇒ Route
Returns a new instance of Route.
11 12 13 14 15 16 17 |
# File 'lib/newark/route.rb', line 11 def initialize(path, constraints, handler) fail ArgumentError, 'You must define a route handler' if handler.nil? @constraints = Constraint.load(constraints) @handler = handler @path = path_matcher(path) end |
Instance Attribute Details
#handler ⇒ Object (readonly)
Returns the value of attribute handler.
9 10 11 |
# File 'lib/newark/route.rb', line 9 def handler @handler end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
9 10 11 |
# File 'lib/newark/route.rb', line 9 def params @params end |
Instance Method Details
#match?(request) ⇒ Boolean
19 20 21 22 23 24 |
# File 'lib/newark/route.rb', line 19 def match?(request) path_data = path_match?(request) if path_data && constraints_match?(request) @params = Hash[ path_data.names.zip( path_data.captures ) ] end end |