Class: Hanami::Routing::Resource::Action Private

Inherits:
Object
  • Object
show all
Includes:
Utils::ClassAttribute
Defined in:
lib/hanami/routing/resource/action.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.

Action for RESTful resource

See Also:

Since:

  • 0.1.0

Constant Summary collapse

NESTED_ROUTES_SEPARATOR =

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.

Nested routes separator

Since:

  • 0.4.0

'/'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router, options = {}, resource = nil, &blk) ⇒ Action

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.

Initialize an action

Parameters:

Since:

  • 0.1.0


70
71
72
73
74
75
# File 'lib/hanami/routing/resource/action.rb', line 70

def initialize(router, options = {}, resource = nil, &blk)
  @router = router
  @options = options
  @resource = resource
  generate(&blk)
end

Class Method Details

.generate(router, action, options = {}, resource = nil) ⇒ 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.

Generate an action for the given router

Parameters:

Since:

  • 0.1.0


56
57
58
# File 'lib/hanami/routing/resource/action.rb', line 56

def self.generate(router, action, options = {}, resource = nil)
  class_for(action).new(router, options, resource)
end

Instance Method Details

#generate(&blk) ⇒ 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.

Generate an action for the given router

Parameters:

  • blk (Proc)

Since:

  • 0.1.0


84
85
86
87
# File 'lib/hanami/routing/resource/action.rb', line 84

def generate(&blk)
  @router.send verb, path, to: endpoint, as: as
  instance_eval(&blk) if block_given?
end

#namespaceObject

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.

Namespace

Since:

  • 0.2.0


112
113
114
# File 'lib/hanami/routing/resource/action.rb', line 112

def namespace
  @namespace ||= Utils::PathPrefix.new @options[:namespace]
end

#resource_nameString

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.

Resource name

Examples:

require 'hanami/router'

Hanami::Router.new do
  resource 'identity'
end

# 'identity' is the name passed in the @options

Returns:

  • (String)

Since:

  • 0.1.0


104
105
106
# File 'lib/hanami/routing/resource/action.rb', line 104

def resource_name
  @resource_name ||= @options[:name].to_s
end