Class: Apitizer::Routing::Map

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/apitizer/routing/map.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Map

Returns a new instance of Map.



8
9
10
11
# File 'lib/apitizer/routing/map.rb', line 8

def initialize(&block)
  @root = Node::Root.new
  define(&block) if block_given?
end

Instance Method Details

#define(&block) ⇒ Object



19
20
21
22
# File 'lib/apitizer/routing/map.rb', line 19

def define(&block)
  proxy = Proxy.new(self)
  proxy.instance_eval(&block)
end

#define_resources(name, options, &block) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/apitizer/routing/map.rb', line 24

def define_resources(name, options, &block)
  parent = options.delete(:parent) || @root
  child = Node::Collection.new(name, options)
  parent.append(child)
  return unless block_given?
  proxy = Proxy.new(self, parent: child)
  proxy.instance_eval(&block)
end

#trace(action, *arguments) ⇒ Object

Raises:



13
14
15
16
17
# File 'lib/apitizer/routing/map.rb', line 13

def trace(action, *arguments)
  path = @root.trace(*arguments) or raise Error, 'Not found'
  raise Error, 'Not permitted' unless path.permit?(action)
  path
end