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.
7 8 9 10 |
# File 'lib/inkling/routing.rb', line 7 def initialize(type, prefix = nil) @type = type @prefix = prefix end |
Instance Attribute Details
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/inkling/routing.rb', line 5 def type @type end |
Instance Method Details
#matches?(request) ⇒ Boolean
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/inkling/routing.rb', line 12 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 |