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.



16
17
18
19
20
21
22
# File 'lib/rom/sql/type_dsl.rb', line 16

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

Instance Attribute Details

#definitionObject (readonly)



9
10
11
# File 'lib/rom/sql/type_dsl.rb', line 9

def definition
  @definition
end

#input_constructorObject (readonly)



11
12
13
# File 'lib/rom/sql/type_dsl.rb', line 11

def input_constructor
  @input_constructor
end

#output_constructorObject (readonly)



13
14
15
# File 'lib/rom/sql/type_dsl.rb', line 13

def output_constructor
  @output_constructor
end

Instance Method Details

#callObject

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.



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

def call(&)
  instance_exec(&)

  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.



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

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.



38
39
40
# File 'lib/rom/sql/type_dsl.rb', line 38

def output(&block)
  @output_constructor = block
end