Class: Hanami::CLI::Commands::App::Generate::Action Private

Inherits:
Command show all
Defined in:
lib/hanami/cli/commands/app/generate/action.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

Constant Summary

Constants inherited from Command

Command::ACTION_SEPARATOR

Instance Method Summary collapse

Methods inherited from Command

#app, inherited, #measure, #run_command

Methods inherited from Hanami::CLI::Command

new

Constructor Details

#initialize(fs:, inflector:, naming: Naming.new(inflector: inflector), generator: Generators::App::Action.new(fs: fs, inflector: inflector), **opts) ⇒ Action

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

Since:

  • 2.0.0



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/hanami/cli/commands/app/generate/action.rb', line 73

def initialize(
  fs:, inflector:,
  naming: Naming.new(inflector: inflector),
  generator: Generators::App::Action.new(fs: fs, inflector: inflector),
  **opts
)
  super(fs: fs, inflector: inflector, **opts)

  @naming = naming
  @generator = generator
end

Instance Method Details

#call(name:, url: nil, http: nil, format: DEFAULT_FORMAT, skip_view: DEFAULT_SKIP_VIEW, skip_tests: DEFAULT_SKIP_TESTS, skip_route: DEFAULT_SKIP_ROUTE, slice: nil, context: nil) ⇒ 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



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/hanami/cli/commands/app/generate/action.rb', line 89

def call(
  name:,
  url: nil,
  http: nil,
  format: DEFAULT_FORMAT,
  skip_view: DEFAULT_SKIP_VIEW,
  skip_tests: DEFAULT_SKIP_TESTS, # rubocop:disable Lint/UnusedMethodArgument,
  skip_route: DEFAULT_SKIP_ROUTE,
  slice: nil,
  context: nil,
  **
)
  slice = inflector.underscore(Shellwords.shellescape(slice)) if slice
  name = naming.action_name(name)
  *controller, action = name.split(ACTION_SEPARATOR)

  if controller.empty?
    raise InvalidActionNameError.new(name)
  end

  generator.call(app.namespace, controller, action, url, http, format, skip_view, skip_route, slice, context: context)
end