Class: Rack::Router::Route
- Inherits:
-
Object
- Object
- Rack::Router::Route
- Defined in:
- lib/rack/router/route.rb
Instance Attribute Summary collapse
-
#accept ⇒ Object
readonly
Returns the value of attribute accept.
-
#constraint ⇒ Object
readonly
Returns the value of attribute constraint.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#http_method ⇒ Object
readonly
Returns the value of attribute http_method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#path_parts ⇒ Object
readonly
Returns the value of attribute path_parts.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
-
#initialize(http_method:, path:, value:, constraint: nil, content_type: nil, accept: nil) ⇒ Route
constructor
A new instance of Route.
- #path_hash(request_path) ⇒ Object
- #print_route ⇒ Object
Constructor Details
#initialize(http_method:, path:, value:, constraint: nil, content_type: nil, accept: nil) ⇒ Route
Returns a new instance of Route.
14 15 16 17 18 19 20 21 22 |
# File 'lib/rack/router/route.rb', line 14 def initialize(http_method:, path:, value:, constraint: nil, content_type: nil, accept: nil) @http_method = http_method.to_s.upcase @path = path @value = value @constraint = constraint @content_type = content_type ? Array.wrap(content_type) : nil @accept = accept ? Array.wrap(accept) : nil @path_parts = calculate_path_parts end |
Instance Attribute Details
#accept ⇒ Object (readonly)
Returns the value of attribute accept.
12 13 14 |
# File 'lib/rack/router/route.rb', line 12 def accept @accept end |
#constraint ⇒ Object (readonly)
Returns the value of attribute constraint.
12 13 14 |
# File 'lib/rack/router/route.rb', line 12 def constraint @constraint end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
12 13 14 |
# File 'lib/rack/router/route.rb', line 12 def content_type @content_type end |
#http_method ⇒ Object (readonly)
Returns the value of attribute http_method.
12 13 14 |
# File 'lib/rack/router/route.rb', line 12 def http_method @http_method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
12 13 14 |
# File 'lib/rack/router/route.rb', line 12 def path @path end |
#path_parts ⇒ Object (readonly)
Returns the value of attribute path_parts.
12 13 14 |
# File 'lib/rack/router/route.rb', line 12 def path_parts @path_parts end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
12 13 14 |
# File 'lib/rack/router/route.rb', line 12 def value @value end |
Instance Method Details
#path_hash(request_path) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/rack/router/route.rb', line 24 def path_hash(request_path) request_path = request_path.to_s.gsub(/\..*\z/, '') request_path_parts = request_path.split('/').reject(&:empty?) pairs = path.split('/').map.with_index do |part, idx| next if part[0] != ':' [part[1..-1].to_sym, request_path_parts[idx]] end pairs.reject(&:nil?).to_h end |
#print_route ⇒ Object
34 35 36 37 38 39 |
# File 'lib/rack/router/route.rb', line 34 def print_route str = "\t#{http_method} \t/#{path}" str += "\tcontent_type=[#{content_type.join(',')}]" unless content_type.nil? str += "\taccept=[#{content_type.join(',')}]" unless accept.nil? str end |