Class: ROM::SQL::Postgres::Types::ArrayTypes Private

Inherits:
Object
  • Object
show all
Defined in:
lib/rom/sql/extensions/postgres/types/array_types.rb

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_write_type, base_read_type) ⇒ ArrayTypes

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 ArrayTypes.


19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rom/sql/extensions/postgres/types/array_types.rb', line 19

def initialize(base_write_type, base_read_type)
  @elements = {}
  @base_write_type = base_write_type
  @base_read_type = base_read_type
  @constructor = proc { |db_type, member|
    if member
      -> arr { Sequel.pg_array(arr.map { |v| member[v] }, db_type) }
    else
      -> arr { Sequel.pg_array(arr, db_type) }
    end
  }
end

Instance Attribute Details

#base_read_typeObject (readonly)

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.


17
18
19
# File 'lib/rom/sql/extensions/postgres/types/array_types.rb', line 17

def base_read_type
  @base_read_type
end

#base_write_typeObject (readonly)

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.


15
16
17
# File 'lib/rom/sql/extensions/postgres/types/array_types.rb', line 15

def base_write_type
  @base_write_type
end

#constructorObject (readonly)

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.


13
14
15
# File 'lib/rom/sql/extensions/postgres/types/array_types.rb', line 13

def constructor
  @constructor
end

#elementsObject (readonly)

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.


11
12
13
# File 'lib/rom/sql/extensions/postgres/types/array_types.rb', line 11

def elements
  @elements
end

Instance Method Details

#[](db_type, member_type = nil) ⇒ 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
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/rom/sql/extensions/postgres/types/array_types.rb', line 32

def [](db_type, member_type = nil)
  elements.fetch(db_type) do
    name = "#{db_type}[]"

    write_type = build_write_type(db_type, member_type)
    read_type = build_read_type(db_type, member_type)

    array_type = Types.Type(name, write_type).meta(type: db_type, read: read_type)

    register_extension(array_type)

    elements[db_type] = array_type
  end
end