Class: Lydia::Route
- Inherits:
-
Object
- Object
- Lydia::Route
- Defined in:
- lib/lydia/route.rb
Constant Summary collapse
- WILDCARD_REGEX =
%r{\/\*(.*)}
- NAMED_SEGMENTS_REGEX =
%r{\/([^\/]*):([^:$\/]+)}
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#pattern ⇒ Object
readonly
Returns the value of attribute pattern.
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
Instance Method Summary collapse
-
#initialize(request_method, namespace, pattern, options = {}, &block) ⇒ Route
constructor
A new instance of Route.
- #match?(env) ⇒ Boolean
Constructor Details
#initialize(request_method, namespace, pattern, options = {}, &block) ⇒ Route
Returns a new instance of Route.
8 9 10 11 12 13 14 15 |
# File 'lib/lydia/route.rb', line 8 def initialize(request_method, namespace, pattern, = {}, &block) @request_method = request_method @namespace = namespace @pattern = pattern @options = @block = block @regexp = init_regexp end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
3 4 5 |
# File 'lib/lydia/route.rb', line 3 def block @block end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/lydia/route.rb', line 3 def namespace @namespace end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/lydia/route.rb', line 3 def @options end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
3 4 5 |
# File 'lib/lydia/route.rb', line 3 def params @params end |
#pattern ⇒ Object (readonly)
Returns the value of attribute pattern.
3 4 5 |
# File 'lib/lydia/route.rb', line 3 def pattern @pattern end |
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
3 4 5 |
# File 'lib/lydia/route.rb', line 3 def regexp @regexp end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
3 4 5 |
# File 'lib/lydia/route.rb', line 3 def request_method @request_method end |
Instance Method Details
#match?(env) ⇒ Boolean
17 18 19 20 21 22 23 |
# File 'lib/lydia/route.rb', line 17 def match?(env) match = @regexp.match((env['PATH_INFO']).to_s) if match && match.names.size @params = Hash[match.names.map(&:to_sym).zip(match.captures)] end match end |