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.
16 17 18 |
# File 'lib/coach/router.rb', line 16 def initialize(mapper) @mapper = mapper end |
Instance Method Details
#draw(routes, base: nil, as: nil, constraints: nil, actions: []) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/coach/router.rb', line 20 def draw(routes, base: nil, as: nil, constraints: nil, actions: []) action_traits(actions).each do |action, traits| # Passing false to const_get prevents it searching ancestors until a # match is found. Without this, globally defined constants such as # `Process` will be picked up before consts that need to be autoloaded. route = routes.const_get(camel(action), false) match(action_url(base, traits), to: Handler.new(route), via: traits[:method], as: as, constraints: constraints) end end |
#match(url, **args) ⇒ Object
34 35 36 |
# File 'lib/coach/router.rb', line 34 def match(url, **args) @mapper.match(url, args) end |