Class: Apitizer::Routing::Map
- Inherits:
-
Object
- Object
- Apitizer::Routing::Map
- Extended by:
- Forwardable
- Defined in:
- lib/apitizer/routing/map.rb
Instance Method Summary collapse
- #define(&block) ⇒ Object
- #define_resources(name, options, &block) ⇒ Object
-
#initialize(&block) ⇒ Map
constructor
A new instance of Map.
- #trace(action, *arguments) ⇒ Object
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, , &block) parent = .delete(:parent) || @root child = Node::Collection.new(name, ) parent.append(child) return unless block_given? proxy = Proxy.new(self, parent: child) proxy.instance_eval(&block) end |
#trace(action, *arguments) ⇒ Object
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 |