Class: ActiveRecord::ConnectionAdapters::Column

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

Overview

An abstract definition of a column in a table.

Defined Under Namespace

Modules: Format

Constant Summary

FALSE_VALUES =
[false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil) ⇒ Column

Instantiates a new column in the table.

name is the column's name, such as supplier_id in supplier_id int(11). 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.



25
26
27
28
29
30
31
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 25

def initialize(name, default,  = nil, null = true, default_function = nil)
  @name = name
   = 
  @null = null
  @default = default
  @default_function = default_function
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default



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

def default
  @default
end

#default_functionObject (readonly)

Returns the value of attribute default_function



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

def default_function
  @default_function
end

#nameObject (readonly)

Returns the value of attribute name



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

def name
  @name
end

#nullObject (readonly)

Returns the value of attribute null



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

def null
  @null
end

#sql_type_metadataObject (readonly)

Returns the value of attribute sql_type_metadata



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

def 
  
end

Instance Method Details

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



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

def ==(other)
  other.is_a?(Column) &&
    attributes_for_hash == other.attributes_for_hash
end

#has_default?Boolean

Returns:

  • (Boolean)


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

def has_default?
  !default.nil?
end

#hashObject



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

def hash
  attributes_for_hash.hash
end

#human_nameObject

Returns the human name of the column name.

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


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

def human_name
  Base.human_attribute_name(@name)
end