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, #generate_db?, #generate_route?, #humanized_slice_name, #javascript_erb_tag, #stylesheet_erb_tag, #underscored_slice_name

Methods inherited from Context

#bundled_assets?, #bundled_dry_monads?, #bundled_views?, #camelized_app_name, #ctx, #database_url, #generate_assets?, #generate_db?, #generate_mysql?, #generate_postgres?, #generate_sqlite?, #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



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

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



34
35
36
# File 'lib/hanami/cli/generators/app/action_context.rb', line 34

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



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

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



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

def module_controller_declaration
  controller.each_with_index.map do |token, i|
    "#{NESTED_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



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

def module_controller_end
  controller.each_with_index.map do |_, i|
    "#{NESTED_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



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

def module_controller_offset
  "#{NESTED_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



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

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



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

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



40
41
42
43
44
# File 'lib/hanami/cli/generators/app/action_context.rb', line 40

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