Sha256: 76b5b0826631454db80e5e0833f0d3d471c77fbe93f7948cbb44e75daeac5137

Contents?: true

Size: 820 Bytes

Versions: 3

Compression:

Stored size: 820 Bytes

Contents

module ROM
  module SQL
    # Type DSL used by Types.define method
    #
    # @api public
    class TypeDSL
      attr_reader :definition, :input_constructor, :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(&block)
        instance_exec(&block)

        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

3 entries across 3 versions & 1 rubygems

Version Path
rom-sql-3.1.0 lib/rom/sql/type_dsl.rb
rom-sql-3.0.1 lib/rom/sql/type_dsl.rb
rom-sql-3.0.0 lib/rom/sql/type_dsl.rb