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

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

"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



21
22
23
# File 'lib/hanami/slice/routing/resolver.rb', line 21

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



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

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



27
28
29
# File 'lib/hanami/slice/routing/resolver.rb', line 27

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



33
34
35
# File 'lib/hanami/slice/routing/resolver.rb', line 33

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