Class: Kontrol::Route
- Inherits:
-
Object
- Object
- Kontrol::Route
- Defined in:
- lib/kontrol/route.rb
Instance Attribute Summary collapse
-
#block ⇒ Object
Returns the value of attribute block.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#pattern ⇒ Object
Returns the value of attribute pattern.
Instance Method Summary collapse
- #generate(*args) ⇒ Object
-
#initialize(name, pattern, options, block) ⇒ Route
constructor
A new instance of Route.
- #recognize(request) ⇒ Object
Constructor Details
#initialize(name, pattern, options, block) ⇒ Route
Returns a new instance of Route.
6 7 8 9 10 11 12 13 |
# File 'lib/kontrol/route.rb', line 6 def initialize(name, pattern, , block) @name = name @pattern = pattern @block = block @options = || {} @format = pattern.gsub(/\(.*?\)/, '%s') @regexp = /^#{pattern}/ end |
Instance Attribute Details
#block ⇒ Object
Returns the value of attribute block.
4 5 6 |
# File 'lib/kontrol/route.rb', line 4 def block @block end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/kontrol/route.rb', line 4 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/kontrol/route.rb', line 4 def @options end |
#pattern ⇒ Object
Returns the value of attribute pattern.
4 5 6 |
# File 'lib/kontrol/route.rb', line 4 def pattern @pattern end |
Instance Method Details
#generate(*args) ⇒ Object
22 23 24 25 26 |
# File 'lib/kontrol/route.rb', line 22 def generate(*args) @format % args.map { |arg| arg.respond_to?(:to_param) ? arg.to_param : arg.to_s } end |
#recognize(request) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/kontrol/route.rb', line 15 def recognize(request) match = request.path_info.match(@regexp) valid = @options.all? { |key, val| request.send(key).match(val) } return match if match and valid end |