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"]

src/routes.qz:43

Constants

ACTIONS: Array[Symbol]

The seven actions of resources, in order.

src/routes.qz:58

Class methods

def self.new -> Bezel::RouteBuilder

A builder with no routes.

src/routes.qz:52

def self.join(prefix: String, path: String) -> String

path under prefix: one / between them, / for nothing.

src/routes.qz:186

Methods

def routes -> Array[Bezel::Route]

The routes collected, in order.

src/routes.qz:55

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 _.

src/routes.qz:62

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').

src/routes.qz:79

def post(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void

A POST route: #get.

src/routes.qz:81

def put(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void

A PUT route: #get.

src/routes.qz:83

def patch(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void

A PATCH route: #get.

src/routes.qz:85

def delete(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void

A DELETE route: #get.

src/routes.qz:87

def head(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void

A HEAD route (a GET route serves HEAD already): #get.

src/routes.qz:89

def options(path: String, controller: Type[Bezel::Controller], action: Symbol, *, as: String? = …) -> Void

An OPTIONS route: #get.

src/routes.qz:91

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):

ActionRouteName
indexGET /usersusers
newGET /users/newnew_user
createPOST /usersusers
showGET /users/{id}user
editGET /users/{id}/editedit_user
updatePATCH and PUT /users/{id}user
deleteDELETE /users/{id}user

src/routes.qz:106

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).

src/routes.qz:114