Module: Snails::RouteTable

Defined in:
runtime/snails/route_dsl.rbs,
runtime/snails/route_dsl.rb

Class Method Summary collapse

Class Method Details

.delete(path, controller, action = :destroy) ⇒ ActionDispatch::Router::Route

a DELETE row, defaulting to the destruction action.

Examples:

delete("/me/account", Api::Me::AccountController)

Parameters:

  • path (String) —

    the path pattern, e.g. "/me/account"

  • controller (Class) —

    the controller class the row dispatches to

  • action (Symbol) (defaults to: :destroy) —

    the action, when it breaks the convention

Returns:



62
# File 'runtime/snails/route_dsl.rb', line 62

def self.delete: (String path, Class controller, ?Symbol action) -> ActionDispatch::Router::Route

.get(path, controller, action = :index) ⇒ ActionDispatch::Router::Route

a GET row, defaulting to the collection action.

Examples:

get("/servers", Api::ServersController)

Parameters:

  • path (String) —

    the path pattern, e.g. "/servers"

  • controller (Class) —

    the controller class the row dispatches to

  • action (Symbol) (defaults to: :index) —

    the action, when it breaks the convention (e.g. :show)

Returns:



26
# File 'runtime/snails/route_dsl.rb', line 26

def self.get: (String path, Class controller, ?Symbol action) -> ActionDispatch::Router::Route

.post(path, controller, action = :create) ⇒ ActionDispatch::Router::Route

a POST row, defaulting to the creation action.

Examples:

post("/login", Api::LoginController)

Parameters:

  • path (String) —

    the path pattern, e.g. "/login"

  • controller (Class) —

    the controller class the row dispatches to

  • action (Symbol) (defaults to: :create) —

    the action, when it breaks the convention

Returns:



38
# File 'runtime/snails/route_dsl.rb', line 38

def self.post: (String path, Class controller, ?Symbol action) -> ActionDispatch::Router::Route

.put(path, controller, action = :update) ⇒ ActionDispatch::Router::Route

a PUT row, defaulting to the update action.

Examples:

put("/account/password", Api::PasswordsController)

Parameters:

  • path (String) —

    the path pattern, e.g. "/account/password"

  • controller (Class) —

    the controller class the row dispatches to

  • action (Symbol) (defaults to: :update) —

    the action, when it breaks the convention

Returns:



50
# File 'runtime/snails/route_dsl.rb', line 50

def self.put: (String path, Class controller, ?Symbol action) -> ActionDispatch::Router::Route

.resources(path, controller, format = nil, only = nil) ⇒ Array<ActionDispatch::Router::Route>

the five RESTful rows of a resource as Array[Route]: index/create on the collection path, show/update/destroy on path/:id, collection rows before member rows. The caller concatenates the result into its table; first-match order is preserved exactly as declared.

Examples:

resources("/posts", Api::PostsController, :json)
resources("/devices", Api::DevicesController, :json, [:create, :show])

Parameters:

  • path (String) —

    the collection path as written — a nested resource's parent segments are path text ("/posts/:post_id/ comments"); member rows append "/:id"

  • controller (Class) —

    the controller class every row dispatches to — matched.controller.new

  • format (Symbol, nil) (defaults to: nil) —

    the route-forced format on every row (nil = infer from path)

  • only (Array[Symbol], nil) (defaults to: nil) —

    the actions to keep, e.g. [:create, :show] — nil keeps all five. Rows come out in REST order regardless of the order named

Returns:

Raises:

  • (ArgumentError) —

    only names something outside the five RESTful actions — a typo would otherwise silently drop the row



87
# File 'runtime/snails/route_dsl.rb', line 87

def self.resources: (String path, Class controller, ?Symbol? format, ?Array[Symbol]? only) -> Array[ActionDispatch::Router::Route]