Class: Rufus::Sixjo::Route
- Inherits:
-
Object
- Object
- Rufus::Sixjo::Route
- Defined in:
- lib/rufus/sixjo.rb
Overview
Wrapping all the details about route.match?(path) hereā¦
Constant Summary collapse
- C_CHAR =
'[^/?:,&#\.]'
- R_PARAM =
capturing route params
/:(#{C_CHAR}+)/
- R_FORMAT =
capturing the resource/file format
/\.(#{C_CHAR}+)$/
Instance Method Summary collapse
-
#initialize(route, options) ⇒ Route
constructor
A new instance of Route.
- #match?(env) ⇒ Boolean
Constructor Details
#initialize(route, options) ⇒ Route
Returns a new instance of Route.
338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/rufus/sixjo.rb', line 338 def initialize (route, ) @param_keys = [] @regex = route.gsub(R_PARAM) do @param_keys << $1.to_sym "(#{C_CHAR}+)" # ready to capture param values end @regex = /^#{@regex}(?:\.(#{C_CHAR}+))?$/ # TODO : do something with the options :agent, :accept, ... end |
Instance Method Details
#match?(env) ⇒ Boolean
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/rufus/sixjo.rb', line 352 def match? (env) m = env['PATH_INFO'].match(@regex) return false unless m values = m.to_a[1..-1] params = @param_keys.zip(values).inject({}) { |r, (k, v)| r[k] = v; r } env['_ROUTE_PARAMS'] = params env['_FORMAT'] = values.last if values.length > @param_keys.length true end |