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.



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

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)



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

def input_constructor
  @input_constructor
end

#output_constructorObject (readonly)



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

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.



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

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.



29
30
31
# File 'lib/rom/sql/type_dsl.rb', line 29

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.



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

def output(&block)
  @output_constructor = block
end