Class: Typekit::Routing::Node::Collection

Inherits:
Base
  • Object
show all
Defined in:
lib/typekit/routing/node/collection.rb

Instance Method Summary collapse

Methods inherited from Base

#append, #assemble

Constructor Details

#initialize(name, only: nil) ⇒ Collection

Returns a new instance of Collection.



5
6
7
8
9
10
11
# File 'lib/typekit/routing/node/collection.rb', line 5

def initialize(name, only: nil)
  @name = name
  @actions = only && Array(only) || Typekit.actions
  unless (@actions - Typekit.actions).empty?
    raise Error, 'Not supported'
  end
end

Instance Method Details

#match(name) ⇒ Object



13
14
15
# File 'lib/typekit/routing/node/collection.rb', line 13

def match(name)
  @name == name
end

#permitted?(request) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/typekit/routing/node/collection.rb', line 23

def permitted?(request)
  return false unless @actions.include?(request.action)

  id_present = request.path.last != @name
  member_action = Helper.member_action?(request.action)

  id_present == member_action
end

#process(request, path) ⇒ Object



17
18
19
20
21
# File 'lib/typekit/routing/node/collection.rb', line 17

def process(request, path)
  request << path.shift # @name
  return request if path.empty?
  request << path.shift # id
end