Class: Rack::Routing::Route
- Inherits:
-
Object
- Object
- Rack::Routing::Route
- Defined in:
- lib/rack/route.rb
Instance Method Summary collapse
-
#initialize(path) ⇒ Route
constructor
A new instance of Route.
- #match?(parts) ⇒ Boolean
- #param_indexes ⇒ Object
- #params_for(parts) ⇒ Object
- #routing_method ⇒ Object
- #to_s ⇒ Object
Constructor Details
Instance Method Details
#match?(parts) ⇒ Boolean
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rack/route.rb', line 8 def match? parts return false unless parts.count == @my_parts.count # HEAD request matches #GET route if parts.first.to_s.upcase.to_sym == :HEAD parts[ 0 ] = :GET end indexes = ( 0..@my_parts.count - 1 ).to_a param_indexes.each{| i | indexes.delete i } indexes.all? do |i| parts[ i ].to_s == @my_parts[ i ] end end |
#param_indexes ⇒ Object
43 44 45 |
# File 'lib/rack/route.rb', line 43 def param_indexes @my_parts.map.with_index{ | p,i | i if p[ 0 ] == ':' }.compact end |
#params_for(parts) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/rack/route.rb', line 25 def params_for parts return {} unless param_indexes arr = param_indexes.map{| i | [ @my_parts[ i ].sub( /\A:/, '' ).to_sym, parts[ i ]]} arr.to_h end |
#routing_method ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/rack/route.rb', line 33 def routing_method return "#{ @my_parts[ 0 ].downcase }_root".to_sym if @my_parts.count == 1 @my_parts.reject{ |p| p[ 0 ] == ':' } .map( &:downcase ) .map{| p | p.gsub( '-', '_' )} .join( '_' ) .to_sym end |
#to_s ⇒ Object
47 48 49 |
# File 'lib/rack/route.rb', line 47 def to_s "#{ self.class } @my_parts:#{ @my_parts } count:#{ @my_parts.count }" end |