Class: Coach::Router

Inherits:
Object
  • Object
show all
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

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(namespace, base: nil, as: nil, constraints: nil, actions: []) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/coach/router.rb', line 20

def draw(namespace, base: nil, as: nil, constraints: nil, actions: [])
  action_traits(actions).each do |action, traits|
    handler = build_handler(namespace, action)
    match(action_url(base, traits),
          to: handler,
          via: traits[:method],
          as: as,
          constraints: constraints)
  end
end

#match(url, **args) ⇒ Object



31
32
33
# File 'lib/coach/router.rb', line 31

def match(url, **args)
  @mapper.match(url, args)
end