Class: Rutter::Routes

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/rutter/routes.rb

Overview

Routes URL builder.

Examples:

router = Rutter.new(base: "http://rutter.org") do
  get "/login", to: "sessions#new", as: :login
  get "/books/:id", to: "books#show", as: :book
end.freeze

routes = Rutter::Routes.new(router)

routes.
  # => "/login"
routes.(return_to: "/")
  # => "/login?return_to=/"
routes.book_path(id: 82)
  # => "/books/82"

routes.
  # => "http://rutter.org/login"
routes.(return_to: "/")
  # => "http://rutter.org/login?return_to=/"
routes.book_url(id: 82)
  # => "http://rutter.org/books/82"

See Also:

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, **args) ⇒ Object (protected)



56
57
58
59
60
61
# File 'lib/rutter/routes.rb', line 56

def method_missing(method_name, **args)
  named_route, type = method_name.to_s.split(/\_(path|url)\z/)
  return super unless type

  @router.public_send(type, named_route.to_sym, **args)
end