Sha256: d056b33f2161ebd8de633aa5e4cea741182094c091c908b2a3f755c0d4210645

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require "dry/inflector"
require "dry/files"
require "shellwords"
require_relative "../../../naming"
require_relative "../../../errors"

module Hanami
  module CLI
    module Commands
      module App
        module Generate
          # @since 2.2.0
          # @api private
          class Command < App::Command
            option :slice, required: false, desc: "Slice name"

            attr_reader :generator
            private :generator

            # @since 2.2.0
            # @api private
            def initialize(
              fs:,
              inflector:,
              **opts
            )
              super
              @generator = generator_class.new(fs: fs, inflector: inflector, out: out)
            end

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

            # @since 2.2.0
            # @api private
            def call(name:, slice: nil, **)
              if slice
                generator.call(
                  key: name,
                  namespace: slice,
                  base_path: fs.join("slices", inflector.underscore(slice))
                )
              else
                generator.call(
                  key: name,
                  namespace: app.namespace,
                  base_path: "app"
                )
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hanami-cli-2.2.1 lib/hanami/cli/commands/app/generate/command.rb
hanami-cli-2.2.0 lib/hanami/cli/commands/app/generate/command.rb
hanami-cli-2.2.0.rc1 lib/hanami/cli/commands/app/generate/command.rb
hanami-cli-2.2.0.beta2 lib/hanami/cli/commands/app/generate/command.rb