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.
371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/rufus/sixjo.rb', line 371 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
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 |
# File 'lib/rufus/sixjo.rb', line 385 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 |