Class: ActiveRecord::ConnectionAdapters::Column
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::Column
- Defined in:
- lib/active_record/connection_adapters/column.rb
Overview
An abstract definition of a column in a table.
Direct Known Subclasses
Defined Under Namespace
Modules: Format
Constant Summary collapse
- TRUE_VALUES =
[true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON'].to_set
- FALSE_VALUES =
[false, 0, '0', 'f', 'F', 'false', 'FALSE', 'off', 'OFF'].to_set
Instance Attribute Summary collapse
-
#cast_type ⇒ Object
readonly
Returns the value of attribute cast_type.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#default_function ⇒ Object
readonly
Returns the value of attribute default_function.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#null ⇒ Object
readonly
Returns the value of attribute null.
-
#sql_type ⇒ Object
readonly
Returns the value of attribute sql_type.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #has_default? ⇒ Boolean
- #hash ⇒ Object
-
#human_name ⇒ Object
Returns the human name of the column name.
-
#initialize(name, default, cast_type, sql_type = nil, null = true) ⇒ Column
constructor
Instantiates a new column in the table.
- #with_type(type) ⇒ Object
Constructor Details
#initialize(name, default, cast_type, sql_type = nil, null = true) ⇒ 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'
. cast_type
is the object used for type casting and type information. sql_type
is used to extract the column’s length, if necessary. For example 60
in company_name varchar(60)
. It will be mapped to one of the standard Rails SQL types in the type
attribute. null
determines if this column allows NULL
values.
33 34 35 36 37 38 39 40 |
# File 'lib/active_record/connection_adapters/column.rb', line 33 def initialize(name, default, cast_type, sql_type = nil, null = true) @name = name @cast_type = cast_type @sql_type = sql_type @null = null @default = default @default_function = nil end |
Instance Attribute Details
#cast_type ⇒ Object (readonly)
Returns the value of attribute cast_type.
16 17 18 |
# File 'lib/active_record/connection_adapters/column.rb', line 16 def cast_type @cast_type end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
16 17 18 |
# File 'lib/active_record/connection_adapters/column.rb', line 16 def default @default end |
#default_function ⇒ Object (readonly)
Returns the value of attribute default_function.
16 17 18 |
# File 'lib/active_record/connection_adapters/column.rb', line 16 def default_function @default_function end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/active_record/connection_adapters/column.rb', line 16 def name @name end |
#null ⇒ Object (readonly)
Returns the value of attribute null.
16 17 18 |
# File 'lib/active_record/connection_adapters/column.rb', line 16 def null @null end |
#sql_type ⇒ Object (readonly)
Returns the value of attribute sql_type.
16 17 18 |
# File 'lib/active_record/connection_adapters/column.rb', line 16 def sql_type @sql_type end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
60 61 62 63 64 65 66 67 |
# File 'lib/active_record/connection_adapters/column.rb', line 60 def ==(other) other.name == name && other.default == default && other.cast_type == cast_type && other.sql_type == sql_type && other.null == null && other.default_function == default_function end |
#has_default? ⇒ Boolean
42 43 44 |
# File 'lib/active_record/connection_adapters/column.rb', line 42 def has_default? !default.nil? end |
#hash ⇒ Object
70 71 72 |
# File 'lib/active_record/connection_adapters/column.rb', line 70 def hash attributes_for_hash.hash end |
#human_name ⇒ Object
Returns the human name of the column name.
Examples
Column.new('sales_stage', ...).human_name # => 'Sales stage'
50 51 52 |
# File 'lib/active_record/connection_adapters/column.rb', line 50 def human_name Base.human_attribute_name(@name) end |
#with_type(type) ⇒ Object
54 55 56 57 58 |
# File 'lib/active_record/connection_adapters/column.rb', line 54 def with_type(type) dup.tap do |clone| clone.instance_variable_set('@cast_type', type) end end |