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

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

Direct Known Subclasses

Component, Migration, Operation, Relation

Instance Method Summary collapse

Methods inherited from Command

#app, #inflector, inherited, #measure, #run_command

Methods inherited from Hanami::CLI::Command

#inflector, new

Constructor Details

#initialize(fs:, out:) ⇒ Command

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

Since:

  • 2.2.0



24
25
26
27
# File 'lib/hanami/cli/commands/app/generate/command.rb', line 24

def initialize(fs:, out:, **)
  super
  @generator = generator_class.new(fs:, inflector:, out:)
end

Instance Method Details

#call(name:, slice: nil, **opts) ⇒ 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.

Raises:

Since:

  • 2.2.0



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/hanami/cli/commands/app/generate/command.rb', line 38

def call(name:, slice: nil, **opts)
  slice ||= detect_slice_from_cwd

  if slice.nil?
    generator.call(
      key: name,
      namespace: app.namespace,
      base_path: "app",
      **opts,
    )
    return
  end

  slice_root = slice.respond_to?(:root) ? slice.root : detect_slice_root(slice)
  raise MissingSliceError.new(slice) unless fs.exist?(slice_root)

  generator.call(
    key: name,
    namespace: slice,
    base_path: slice_root,
    **opts,
  )
end

#generator_classObject

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



31
32
33
34
# File 'lib/hanami/cli/commands/app/generate/command.rb', line 31

def generator_class
  # Must be implemented by subclasses, with initialize method that takes:
  # fs:, out:
end