Class: ActiveRecord::ConnectionAdapters::PostgreSQL::Column

Inherits:
Column
  • Object
show all
Defined in:
lib/active_record/connection_adapters/postgresql/column.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from Column

#collation, #comment, #default, #default_function, #name, #null, #sql_type_metadata

Instance Method Summary collapse

Methods inherited from Column

#bigint?, #human_name

Methods included from Deduplicable

#deduplicate

Constructor Details

#initialize(serial: nil, generated: nil) ⇒ Column

Returns a new instance of Column.



11
12
13
14
15
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 11

def initialize(*, serial: nil, generated: nil, **)
  super
  @serial = serial
  @generated = generated
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



55
56
57
58
59
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 55

def ==(other)
  other.is_a?(Column) &&
    super &&
    serial? == other.serial?
end

#arrayObject Also known as: array?



30
31
32
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 30

def array
  .sql_type.end_with?("[]")
end

#encode_with(coder) ⇒ Object



49
50
51
52
53
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 49

def encode_with(coder)
  coder["serial"] = @serial
  coder["generated"] = @generated
  super
end

#enum?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 35

def enum?
  type == :enum
end

#has_default?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 26

def has_default?
  super && !virtual?
end

#hashObject



62
63
64
65
66
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 62

def hash
  Column.hash ^
    super.hash ^
    serial?.hash
end

#init_with(coder) ⇒ Object



43
44
45
46
47
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 43

def init_with(coder)
  @serial = coder["serial"]
  @generated = coder["generated"]
  super
end

#serial?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 17

def serial?
  @serial
end

#sql_typeObject



39
40
41
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 39

def sql_type
  super.delete_suffix("[]")
end

#virtual?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 21

def virtual?
  # We assume every generated column is virtual, no matter the concrete type
  @generated.present?
end