Class: Hanami::Slice::Router::ResourceBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/slice/router.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Builds RESTful routes for a resource

Since:

  • 2.0.0

Constant Summary collapse

ROUTE_OPTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0

{
  index: {method: :get},
  new: {method: :get, path_suffix: "/new", name_prefix: "new"},
  create: {method: :post},
  show: {method: :get, path_suffix: "/:id"},
  edit: {method: :get, path_suffix: "/:id/edit", name_prefix: "edit"},
  update: {method: :patch, path_suffix: "/:id"},
  destroy: {method: :delete, path_suffix: "/:id"}
}.freeze
PLURAL_ACTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0

i[index new create show edit update destroy].freeze
SINGULAR_ACTIONS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0

(PLURAL_ACTIONS - i[index]).freeze

Instance Method Summary collapse

Constructor Details

#initialize(name:, type:, resource_scope:, options:, inflector:) ⇒ ResourceBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ResourceBuilder.

Since:

  • 2.0.0



170
171
172
173
174
175
176
177
178
# File 'lib/hanami/slice/router.rb', line 170

def initialize(name:, type:, resource_scope:, options:, inflector:)
  @name = name
  @type = type
  @resource_scope = resource_scope
  @options = options
  @inflector = inflector

  @path = options[:path] || name.to_s
end

Instance Method Details

#add_routes(router) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



187
188
189
190
191
# File 'lib/hanami/slice/router.rb', line 187

def add_routes(router)
  actions.each do |action|
    add_route(router, action, ROUTE_OPTIONS.fetch(action))
  end
end

#scope(router, &block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



180
181
182
183
184
185
# File 'lib/hanami/slice/router.rb', line 180

def scope(router, &block)
  @resource_scope.push(@name)
  router.scope(scope_path, as: scope_name, &block)
ensure
  @resource_scope.pop
end