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

Inherits:
Column
  • Object
show all
Defined in:
activerecord/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

Methods included from ActiveSupport::Concern

#append_features, #class_methods, extended, #included, #prepend_features, #prepended

Constructor Details

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

Returns a new instance of Column.


9
10
11
12
13
# File 'activerecord/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?


51
52
53
54
55
# File 'activerecord/lib/active_record/connection_adapters/postgresql/column.rb', line 51

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

#arrayObject Also known as: array?


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

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

#encode_with(coder) ⇒ Object


46
47
48
49
# File 'activerecord/lib/active_record/connection_adapters/postgresql/column.rb', line 46

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

#enum?Boolean

Returns:

  • (Boolean)

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

def enum?
  type == :enum
end

#has_default?Boolean

Returns:

  • (Boolean)

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

def has_default?
  super && !virtual?
end

#hashObject


58
59
60
61
62
# File 'activerecord/lib/active_record/connection_adapters/postgresql/column.rb', line 58

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

#init_with(coder) ⇒ Object


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

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

#serial?Boolean

Returns:

  • (Boolean)

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

def serial?
  @serial
end

#sql_typeObject


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

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

#virtual?Boolean

Returns:

  • (Boolean)

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

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