Class: Hanami::Extensions::Action::NameInferrer Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/extensions/action/name_inferrer.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.

Infers an action's name (e.g. posts.show) from its class name relative to its slice namespace.

Since:

  • 2.0.0

Class Method Summary collapse

Class Method Details

.call(action_class_name:, slice:) ⇒ String?

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 the inferred name, or nil if action_class_name is nil.

Examples:

NameInferrer.call(action_class_name: "Main::Actions::Posts::Show", slice: Main::Slice)
# => "posts.show"

Parameters:

  • action_class_name (String, nil)

    the action class name

  • slice (Hanami::Slice)

    the slice the action belongs to

Returns:

  • (String, nil)

    the inferred name, or nil if action_class_name is nil

Since:

  • 2.0.0



20
21
22
23
24
25
26
27
28
29
# File 'lib/hanami/extensions/action/name_inferrer.rb', line 20

def call(action_class_name:, slice:)
  return nil unless action_class_name

  slice
    .inflector
    .underscore(action_class_name)
    .sub(%r{^#{slice.slice_name.path}#{PATH_DELIMITER}}, "")
    .sub(%r{^#{slice.config.actions.name_inference_base}#{PATH_DELIMITER}}, "")
    .gsub("/", CONTAINER_KEY_DELIMITER)
end