class Bezel::RouteBuilder
include DslScope
What a router's routes block runs on: it collects the routes. Paths
are joined to the enclosing scopes' (scope "/admin" then get "/users" is /admin/users), and route names to their prefixes.
b = Bezel::RouteBuilder.new
b.scope("/api", pipeline: :api, as: "api") do
resources "/users", Bezel::Controller, only: [:index, :show]
end
b.routes.map { |r| "#{r.method} #{r.pattern} #{r.name}" }
# => ["GET /api/users api_users", "GET /api/users/{id} api_user"]
Constants
ACTIONS: Array[Symbol]
The seven actions of resources, in order.
Class methods
def self.new -> Bezel::RouteBuilder
A builder with no routes.
def self.join(prefix: String, path: String) -> String
path under prefix: one / between them, / for nothing.
Methods
def routes -> Array[Bezel::Route]
The routes collected, in order.
def scope(path: String, *, pipeline: Symbol? = …, as: String? = …, &block: Bezel::RouteBuilder.() -> Void) -> Void
Routes the block declares under path, through pipeline (after the
enclosing scopes' pipelines) and with names prefixed by as and _.
def get(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void
A GET route to action of controller, named as (prefixed by the
scopes').
def post(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void
A POST route: #get.
def put(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void
A PUT route: #get.
def patch(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void
A PATCH route: #get.
def delete(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void
A DELETE route: #get.
def head(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void
A HEAD route (a GET route serves HEAD already): #get.
def options(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void
An OPTIONS route: #get.
def resources(path: String, controller: Type[Bezel::Controller], *, only: Array[Symbol] = …, except: Array[Symbol] = …) -> Void
The routes of a resource's actions (ACTIONS, or only: of them,
without except:), named by the path's last segment (/users:
users, user, new_user, edit_user):
| Action | Route | Name |
|---|---|---|
| index | GET /users | users |
| new | GET /users/new | new_user |
| create | POST /users | users |
| show | GET /users/{id} | user |
| edit | GET /users/{id}/edit | edit_user |
| update | PATCH and PUT /users/{id} | user |
| delete | DELETE /users/{id} | user |
def resources(path: String, controller: Type[Bezel::Controller], *, only: Array[Symbol] = …, except: Array[Symbol] = …, &block: Bezel::RouteBuilder.() -> Void) -> Void
The same, and the block's routes nested under one member
(resources "/posts", Posts do resources "/comments", Comments end:
/posts/{post_id}/comments, named post_comments).