Class: Inkling::Routing::TypeConstraint
- Inherits:
-
Object
- Object
- Inkling::Routing::TypeConstraint
- Defined in:
- lib/inkling/routing.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(type, prefix = nil) ⇒ TypeConstraint
constructor
A new instance of TypeConstraint.
- #matches?(request) ⇒ Boolean
Constructor Details
#initialize(type, prefix = nil) ⇒ TypeConstraint
Returns a new instance of TypeConstraint.
6 7 8 9 |
# File 'lib/inkling/routing.rb', line 6 def initialize(type, prefix = nil) @type = type @prefix = prefix end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/inkling/routing.rb', line 4 def type @type end |
Instance Method Details
#matches?(request) ⇒ Boolean
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/inkling/routing.rb', line 11 def matches?(request) path = @prefix.nil? ? request.path : request.path.gsub(@prefix, "") matching_path = Inkling::Path.find_by_slug(path) if matching_path result = matching_path.content.is_a? @type.constantize request.params[:id] = matching_path.content.id result else false end end |