Class: Hanami::Slice::Routing::Resolver Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/slice/routing/resolver.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.

Hanami app router endpoint resolver

This resolves endpoints objects from a slice container using the strings passed to to: as their container keys.

Since:

  • 2.0.0

API:

  • private

Constant Summary collapse

SLICE_ACTIONS_KEY_NAMESPACE =

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

API:

  • private

"actions"

Instance Method Summary collapse

Constructor Details

#initialize(slice:) ⇒ Resolver

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

Since:

  • 2.0.0

API:

  • private



19
20
21
# File 'lib/hanami/slice/routing/resolver.rb', line 19

def initialize(slice:)
  @slice = slice
end

Instance Method Details

#call(_path, endpoint) ⇒ 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

API:

  • private



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hanami/slice/routing/resolver.rb', line 37

def call(_path, endpoint)
  endpoint =
    case endpoint
    when String
      resolve_slice_action(endpoint)
    when Class
      endpoint.respond_to?(:call) ? endpoint : endpoint.new
    else
      endpoint
    end

  unless endpoint.respond_to?(:call)
    raise Routes::NotCallableEndpointError.new(endpoint)
  end

  endpoint
end

#find_slice(slice_name) ⇒ 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

API:

  • private



25
26
27
# File 'lib/hanami/slice/routing/resolver.rb', line 25

def find_slice(slice_name)
  slice.slices[slice_name]
end

#to_slice(slice_name) ⇒ 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

API:

  • private



31
32
33
# File 'lib/hanami/slice/routing/resolver.rb', line 31

def to_slice(slice_name)
  self.class.new(slice: find_slice(slice_name))
end