Class: Rivulet::Routing::Mapper
- Inherits:
-
Object
- Object
- Rivulet::Routing::Mapper
- Includes:
- Enumerable
- Defined in:
- lib/rivulet/routing/mapper.rb
Instance Method Summary collapse
- #build_callable(to) ⇒ Object
- #draw(&block) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(routes, prefix: '', scopes: []) ⇒ Mapper
constructor
A new instance of Mapper.
- #scope(name, &block) ⇒ Object
Constructor Details
#initialize(routes, prefix: '', scopes: []) ⇒ Mapper
Returns a new instance of Mapper.
10 11 12 13 14 |
# File 'lib/rivulet/routing/mapper.rb', line 10 def initialize(routes, prefix: '', scopes: []) @routes = routes @prefix = prefix @scopes = scopes end |
Instance Method Details
#build_callable(to) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rivulet/routing/mapper.rb', line 51 def build_callable(to) case to when String handler, action = to.split('#') when Hash handler, action = to.values_at(:to, :action) else raise 'Cannot parse route handler' end ->(input) { ::Handlers[handler].send(action, input) } end |
#draw(&block) ⇒ Object
39 40 41 |
# File 'lib/rivulet/routing/mapper.rb', line 39 def draw(&block) instance_eval(&block) end |
#each(&block) ⇒ Object
6 7 8 |
# File 'lib/rivulet/routing/mapper.rb', line 6 def each(&block) @routes.each(&block) end |