Class: ROM::SQL::TypeDSL

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/sql/type_dsl.rb

Overview

Type DSL used by Types.define method

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value_type) ⇒ TypeDSL

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TypeDSL.



10
11
12
13
14
15
16
# File 'lib/rom/sql/type_dsl.rb', line 10

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

Instance Attribute Details

#definitionObject (readonly)



7
8
9
# File 'lib/rom/sql/type_dsl.rb', line 7

def definition
  @definition
end

#input_constructorObject (readonly)



7
8
9
# File 'lib/rom/sql/type_dsl.rb', line 7

def input_constructor
  @input_constructor
end

#output_constructorObject (readonly)



7
8
9
# File 'lib/rom/sql/type_dsl.rb', line 7

def output_constructor
  @output_constructor
end

Instance Method Details

#call(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



19
20
21
22
23
24
# File 'lib/rom/sql/type_dsl.rb', line 19

def call(&block)
  instance_exec(&block)

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

#input(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
# File 'lib/rom/sql/type_dsl.rb', line 27

def input(&block)
  @input_constructor = block
end

#output(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



32
33
34
# File 'lib/rom/sql/type_dsl.rb', line 32

def output(&block)
  @output_constructor = block
end