Class: Inkling::Routing::TypeConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/inkling/routing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#typeObject

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

Returns:

  • (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