Class: Hanami::CLI::Generators::App::ActionContext Private

Inherits:
SliceContext show all
Defined in:
lib/hanami/cli/generators/app/action_context.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.

Since:

  • 2.0.0

Instance Method Summary collapse

Methods inherited from SliceContext

#camelized_slice_name, #humanized_slice_name, #javascript_erb_tag, #stylesheet_erb_tag, #underscored_slice_name

Methods inherited from Context

#bundled_assets?, #bundled_views?, #camelized_app_name, #ctx, #generate_assets?, #hanami_assets_npm_package, #hanami_gem, #hanami_gem_version, #hanami_head?, #humanized_app_name, #ruby_omit_hash_values?, #underscored_app_name

Constructor Details

#initialize(inflector, app, slice, controller, action) ⇒ ActionContext

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

Since:

  • 2.0.0



17
18
19
20
21
# File 'lib/hanami/cli/generators/app/action_context.rb', line 17

def initialize(inflector, app, slice, controller, action)
  @controller = controller
  @action = action
  super(inflector, app, slice, nil)
end

Instance Method Details

#camelized_action_nameObject

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/cli/generators/app/action_context.rb', line 33

def camelized_action_name
  inflector.camelize(action)
end

#camelized_controller_nameObject

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



25
26
27
28
29
# File 'lib/hanami/cli/generators/app/action_context.rb', line 25

def camelized_controller_name
  controller.map do |token|
    inflector.camelize(token)
  end.join(NAMESPACE_SEPARATOR)
end

#module_controller_declarationObject

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



53
54
55
56
57
# File 'lib/hanami/cli/generators/app/action_context.rb', line 53

def module_controller_declaration
  controller.each_with_index.map do |token, i|
    "#{OFFSET}#{INDENTATION * i}module #{inflector.camelize(token)}"
  end.join($/)
end

#module_controller_endObject

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



61
62
63
64
65
# File 'lib/hanami/cli/generators/app/action_context.rb', line 61

def module_controller_end
  controller.each_with_index.map do |_, i|
    "#{OFFSET}#{INDENTATION * i}end"
  end.reverse.join($/)
end

#module_controller_offsetObject

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



69
70
71
# File 'lib/hanami/cli/generators/app/action_context.rb', line 69

def module_controller_offset
  "#{OFFSET}#{INDENTATION * controller.count}"
end

#template_pathObject

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



75
76
77
78
# File 'lib/hanami/cli/generators/app/action_context.rb', line 75

def template_path
  Dry::Files::Path["slices", underscored_slice_name, "templates", *underscored_controller_name,
                   "#{underscored_action_name}.html.erb"]
end

#underscored_action_nameObject

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



47
48
49
# File 'lib/hanami/cli/generators/app/action_context.rb', line 47

def underscored_action_name
  inflector.underscore(action)
end

#underscored_controller_nameObject

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
# File 'lib/hanami/cli/generators/app/action_context.rb', line 39

def underscored_controller_name
  controller.map do |token|
    inflector.underscore(token)
  end
end