Sha256: b8a0f959cb9992c4515701702e946bf406aef3d47a834ca4050a35c41d32f322

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module Hanami
  module CLI
    module Commands
      module App
        module Generate
          # @since 2.2.0
          # @api private
          class Relation < Command
            argument :name, required: true, desc: "Relation name"
            option :gateway, desc: "Generate relation for gateway"

            example [
              %(books               (MyApp::Relation::Book)),
              %(books/drafts        (MyApp::Relations::Books::Drafts)),
              %(books --slice=admin (Admin::Relations::Books)),
              %(books --slice=admin --gateway=extra (Admin::Relations::Books)),
            ]

            # @since 2.2.0
            # @api private
            def generator_class
              Generators::App::Relation
            end

            def call(name:, slice: nil, gateway: nil)
              if slice
                generator.call(
                  key: name,
                  namespace: slice,
                  base_path: fs.join("slices", inflector.underscore(slice)),
                  gateway: gateway
                )
              else
                generator.call(
                  key: name,
                  namespace: app.namespace,
                  base_path: "app",
                  gateway: gateway
                )
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hanami-cli-2.2.1 lib/hanami/cli/commands/app/generate/relation.rb
hanami-cli-2.2.0 lib/hanami/cli/commands/app/generate/relation.rb