Class: Coach::Router
- Inherits:
-
Object
- Object
- Coach::Router
- Defined in:
- lib/coach/router.rb
Constant Summary collapse
- ACTION_TRAITS =
{ index: { method: :get }, show: { method: :get, url: ':id' }, create: { method: :post }, update: { method: :put, url: ':id' }, destroy: { method: :delete, url: ':id' } }.each_value(&:freeze).freeze
Instance Method Summary collapse
- #draw(routes, base: nil, as: nil, constraints: nil, actions: []) ⇒ Object
-
#initialize(mapper) ⇒ Router
constructor
A new instance of Router.
- #match(url, **args) ⇒ Object
Constructor Details
#initialize(mapper) ⇒ Router
Returns a new instance of Router.
14 15 16 |
# File 'lib/coach/router.rb', line 14 def initialize(mapper) @mapper = mapper end |
Instance Method Details
#draw(routes, base: nil, as: nil, constraints: nil, actions: []) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/coach/router.rb', line 18 def draw(routes, base: nil, as: nil, constraints: nil, actions: []) action_traits(actions).each do |action, traits| route = routes.const_get(camel(action)) match(action_url(base, traits), to: Handler.new(route), via: traits[:method], as: as, constraints: constraints) end end |
#match(url, **args) ⇒ Object
29 30 31 |
# File 'lib/coach/router.rb', line 29 def match(url, **args) @mapper.match(url, args) end |