Sha256: 27451f154f5b4c218085731c7c907f3de18d6043cf04598c96d109b4f5777995

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

Contents

# frozen_string_literal: true

module ROM
  module SQL
    # Type DSL used by Types.define method
    #
    # @api public
    class TypeDSL
      attr_reader :definition

      attr_reader :input_constructor

      attr_reader :output_constructor

      # @api private
      def initialize(value_type)
        if value_type.class < ::Dry::Types::Type
          @definition = value_type
        else
          @definition = ::ROM::SQL::Types.Nominal(value_type)
        end
      end

      # @api private
      def call(&)
        instance_exec(&)

        definition.constructor(input_constructor)
          .meta(read: definition.constructor(output_constructor))
      end

      # @api private
      def input(&block)
        @input_constructor = block
      end

      # @api private
      def output(&block)
        @output_constructor = block
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rom-sql-3.7.0 lib/rom/sql/type_dsl.rb