Method: Hanami::Slice::ViewNameInferrer.call

Defined in:
lib/hanami/slice/view_name_inferrer.rb

.call(action_class_name:, slice:) ⇒ Array<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 an array of container keys for views matching the given action.

Also provides alternative view keys for common RESTful actions.

Examples:

ViewNameInferrer.call(action_name: "Main::Actions::Posts::Create", slice: Main::Slice)
# => ["views.posts.create", "views.posts.new"]

Parameters:

  • action_class_name (String)

    action class name

  • slice (Hanami::Slice, Hanami::Application)

    Hanami slice containing the action

Returns:

  • (Array<string>)

    array of paired view container keys

Since:

  • 2.0.0



30
31
32
33
34
35
36
37
38
39
# File 'lib/hanami/slice/view_name_inferrer.rb', line 30

def call(action_class_name:, slice:)
  action_key_base = slice.config.actions.name_inference_base
  view_key_base = slice.config.actions.view_name_inference_base

  action_name_key = action_name_key(action_class_name, slice, action_key_base)

  view_key = [view_key_base, action_name_key].compact.join(CONTAINER_KEY_DELIMITER)

  [view_key, alternative_view_key(view_key)].compact
end