Class: ActiveRecord::ConnectionAdapters::Column
- Includes:
- Deduplicable
- Defined in:
- activerecord/lib/active_record/connection_adapters/column.rb
Overview
An abstract definition of a column in a table.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#collation ⇒ Object
readonly
Returns the value of attribute collation.
-
#comment ⇒ Object
readonly
Returns the value of attribute comment.
-
#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_metadata ⇒ Object
readonly
Returns the value of attribute sql_type_metadata.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #bigint? ⇒ Boolean
- #encode_with(coder) ⇒ Object
- #has_default? ⇒ Boolean
- #hash ⇒ Object
-
#human_name ⇒ Object
Returns the human name of the column name.
- #init_with(coder) ⇒ Object
-
#initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil) ⇒ Column
constructor
Instantiates a new column in the table.
Methods included from Deduplicable
Methods included from ActiveSupport::Concern
#append_features, #class_methods, extended, #included
Constructor Details
#initialize(name, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil) ⇒ Column
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.
20 21 22 23 24 25 26 27 28 |
# 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
#collation ⇒ Object (readonly)
Returns the value of attribute collation
10 11 12 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10 def collation @collation end |
#comment ⇒ Object (readonly)
Returns the value of attribute comment
10 11 12 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10 def comment @comment end |
#default ⇒ Object (readonly)
Returns the value of attribute default
10 11 12 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10 def default @default end |
#default_function ⇒ Object (readonly)
Returns the value of attribute default_function
10 11 12 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10 def default_function @default_function end |
#name ⇒ Object (readonly)
Returns the value of attribute name
10 11 12 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10 def name @name end |
#null ⇒ Object (readonly)
Returns the value of attribute null
10 11 12 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10 def null @null end |
#sql_type_metadata ⇒ Object (readonly)
Returns the value of attribute sql_type_metadata
10 11 12 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 10 def @sql_type_metadata end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
66 67 68 69 70 71 72 73 74 75 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 66 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 |
#bigint? ⇒ Boolean
34 35 36 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 34 def bigint? /\Abigint\b/.match?(sql_type) end |
#encode_with(coder) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# 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 |
#has_default? ⇒ Boolean
30 31 32 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 30 def has_default? !default.nil? || default_function end |
#hash ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 78 def hash Column.hash ^ name.hash ^ name.encoding.hash ^ default.hash ^ .hash ^ null.hash ^ default_function.hash ^ collation.hash ^ comment.hash end |
#human_name ⇒ Object
Returns the human name of the column name.
Examples
Column.new('sales_stage', ...).human_name # => 'Sales stage'
42 43 44 |
# File 'activerecord/lib/active_record/connection_adapters/column.rb', line 42 def human_name Base.human_attribute_name(@name) end |
#init_with(coder) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# 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 |