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

#auto_populated?, #bigint?, #human_name

Methods included from Deduplicable

#deduplicate

Constructor Details

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

Returns a new instance of Column.



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

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

Instance Method Details

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



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

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

#arrayObject Also known as: array?



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

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

#encode_with(coder) ⇒ Object



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

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

#enum?Boolean

Returns:

  • (Boolean)


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

def enum?
  type == :enum
end

#has_default?Boolean

Returns:

  • (Boolean)


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

def has_default?
  super && !virtual?
end

#hashObject



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

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

#init_with(coder) ⇒ Object



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

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

#serial?Boolean Also known as: auto_incremented_by_db?

Returns:

  • (Boolean)


15
16
17
# File 'lib/active_record/connection_adapters/postgresql/column.rb', line 15

def serial?
  @serial
end

#sql_typeObject



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

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

#virtual?Boolean

Returns:

  • (Boolean)


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

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