123456789_123456789_123456789_123456789_123456789_

Class: ActiveRecord::ConnectionAdapters::Column

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
self, Deduplicable
Inherits: Object
Defined in: activerecord/lib/active_record/connection_adapters/column.rb

Overview

An abstract definition of a column in a table.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Deduplicable - Included

Constructor Details

.new(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil) ⇒ Column

This method is for internal use only.

Instantiates a new column in the table.

#name is the column’s name, such as supplier_id in supplier_id bigint. #default is the type-casted default value, such as new in sales_stage varchar(20) default 'new'. #sql_type_metadata is various information about the type of the column #null determines if this column allows NULL values.

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 20

def initialize(name, default,  = nil, null = true, default_function = nil, collation: nil, comment: nil, **)
  @name = name.freeze
  @sql_type_metadata = 
  @null = null
  @default = default
  @default_function = default_function
  @collation = collation
  @comment = comment
end

Instance Attribute Details

#auto_incremented_by_db?Boolean (readonly)

This method is for internal use only.

whether the column is auto-populated by the database using a sequence

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 67

def auto_incremented_by_db?
  false
end

#auto_populated?Boolean (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 71

def auto_populated?
  auto_incremented_by_db? || default_function
end

#bigint?Boolean (readonly)

This method is for internal use only.
[ GitHub ]

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

def bigint?
  /\Abigint\b/.match?(sql_type)
end

#collation (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10

attr_reader :name, :default, :, :null, :default_function, :collation, :comment

#comment (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10

attr_reader :name, :default, :, :null, :default_function, :collation, :comment

#default (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10

attr_reader :name, :default, :, :null, :default_function, :collation, :comment

#default_function (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10

attr_reader :name, :default, :, :null, :default_function, :collation, :comment

#has_default?Boolean (readonly)

This method is for internal use only.
[ GitHub ]

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

def has_default?
  !default.nil? || default_function
end

#limit (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 12

delegate :precision, :scale, :limit, :type, :sql_type, to: :, allow_nil: true

#name (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10

attr_reader :name, :default, :, :null, :default_function, :collation, :comment

#null (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10

attr_reader :name, :default, :, :null, :default_function, :collation, :comment

#precision (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 12

delegate :precision, :scale, :limit, :type, :sql_type, to: :, allow_nil: true

#scale (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 12

delegate :precision, :scale, :limit, :type, :sql_type, to: :, allow_nil: true

#sql_type (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 12

delegate :precision, :scale, :limit, :type, :sql_type, to: :, allow_nil: true

#sql_type_metadata (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10

attr_reader :name, :default, :, :null, :default_function, :collation, :comment

#type (readonly)

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 12

delegate :precision, :scale, :limit, :type, :sql_type, to: :, allow_nil: true

#virtual?Boolean (readonly)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 99

def virtual?
  false
end

Instance Method Details

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

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 75

def ==(other)
  other.is_a?(Column) &&
    name == other.name &&
    default == other.default &&
     == other. &&
    null == other.null &&
    default_function == other.default_function &&
    collation == other.collation &&
    comment == other.comment
end

#deduplicated (private)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 104

def deduplicated
  @name = -name
  @sql_type_metadata = .deduplicate if 
  @default = -default if default
  @default_function = -default_function if default_function
  @collation = -collation if collation
  @comment = -comment if comment
  super
end

#encode_with(coder)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 56

def encode_with(coder)
  coder["name"] = @name
  coder["sql_type_metadata"] = @sql_type_metadata
  coder["null"] = @null
  coder["default"] = @default
  coder["default_function"] = @default_function
  coder["collation"] = @collation
  coder["comment"] = @comment
end

#eql?(other)

This method is for internal use only.

Alias for #==.

[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 85

alias :eql? :==

#hash

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 87

def hash
  Column.hash ^
    name.hash ^
    name.encoding.hash ^
    default.hash ^
    .hash ^
    null.hash ^
    default_function.hash ^
    collation.hash ^
    comment.hash
end

#human_name

This method is for internal use only.

Returns the human name of the column name.

Examples
Column.new('sales_stage', ...).human_name # => 'Sales stage'
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 42

def human_name
  Base.human_attribute_name(@name)
end

#init_with(coder)

This method is for internal use only.
[ GitHub ]

  
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 46

def init_with(coder)
  @name = coder["name"]
  @sql_type_metadata = coder["sql_type_metadata"]
  @null = coder["null"]
  @default = coder["default"]
  @default_function = coder["default_function"]
  @collation = coder["collation"]
  @comment = coder["comment"]
end