Sha256: cc8c50d1bee4d0148fad4d248723ac71d949942092d413764f62ab69bfa5fd5e

Contents?: true

Size: 1.16 KB

Versions: 4

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

require_relative "../constants"

module Hanami
  module CLI
    module Generators
      module App
        # @since 2.2.0
        # @api private
        class Operation
          # @since 2.2.0
          # @api private
          def initialize(fs:, inflector:, out: $stdout)
            @fs = fs
            @inflector = inflector
            @out = out
          end

          # @since 2.2.0
          # @api private
          def call(key:, namespace:, base_path:)
            RubyFileWriter.new(
              fs: fs,
              inflector: inflector,
            ).call(
              namespace: namespace,
              base_path: base_path,
              key: key,
              relative_parent_class: "Operation",
              body: ["def call", "end"],
            )

            unless key.match?(KEY_SEPARATOR)
              out.puts(
                "  Note: We generated a top-level operation. " \
                "To generate into a directory, add a namespace: `my_namespace.add_book`"
              )
            end
          end

          private

          attr_reader :fs, :inflector, :out
        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/generators/app/operation.rb
hanami-cli-2.2.0 lib/hanami/cli/generators/app/operation.rb
hanami-cli-2.2.0.rc1 lib/hanami/cli/generators/app/operation.rb
hanami-cli-2.2.0.beta2 lib/hanami/cli/generators/app/operation.rb