Sha256: 3b969b07a408dbaa571dd4a6982f7804f28cd6b6d3a2cc093eb6ca827d3be342

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require_relative "../constants"

module Hanami
  module CLI
    module Generators
      module App
        # @since 2.2.0
        # @api private
        class Relation
          # @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:)
            schema_name = key.split(KEY_SEPARATOR).last

            RubyFileWriter.new(
              fs: fs,
              inflector: inflector,
            ).call(
              namespace: namespace,
              key: key,
              base_path: base_path,
              extra_namespace: "Relations",
              relative_parent_class: "DB::Relation",
              body: ["schema :#{schema_name}, infer: true"],
            )
          end

          private

          attr_reader :fs, :inflector, :out
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
hanami-cli-2.2.0.rc1 lib/hanami/cli/generators/app/relation.rb
hanami-cli-2.2.0.beta2 lib/hanami/cli/generators/app/relation.rb