Class: Hanami::Slice::Router::ResourceBuilder Private
- Inherits:
-
Object
- Object
- Hanami::Slice::Router::ResourceBuilder
- 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
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.
{ 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.
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.
(PLURAL_ACTIONS - i[index]).freeze
Instance Method Summary collapse
- #add_routes(router) ⇒ Object private
-
#initialize(name:, type:, resource_scope:, options:, inflector:) ⇒ ResourceBuilder
constructor
private
A new instance of ResourceBuilder.
- #scope(router, &block) ⇒ Object private
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.
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 = @inflector = inflector @path = [: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.
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.
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 |