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
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.
-
#table_name ⇒ Object
readonly
Returns the value of attribute table_name.
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, table_name = nil, default_function = nil, collation = nil, comment: nil) ⇒ Column
constructor
Instantiates a new column in the table.
Constructor Details
#initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, 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 int
. 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.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/active_record/connection_adapters/column.rb', line 16 def initialize(name, default, = nil, null = true, table_name = nil, default_function = nil, collation = nil, comment: nil) @name = name.freeze @table_name = table_name @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.
6 7 8 |
# File 'lib/active_record/connection_adapters/column.rb', line 6 def collation @collation end |
#comment ⇒ Object (readonly)
Returns the value of attribute comment.
6 7 8 |
# File 'lib/active_record/connection_adapters/column.rb', line 6 def comment @comment end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
6 7 8 |
# File 'lib/active_record/connection_adapters/column.rb', line 6 def default @default end |
#default_function ⇒ Object (readonly)
Returns the value of attribute default_function.
6 7 8 |
# File 'lib/active_record/connection_adapters/column.rb', line 6 def default_function @default_function end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/active_record/connection_adapters/column.rb', line 6 def name @name end |
#null ⇒ Object (readonly)
Returns the value of attribute null.
6 7 8 |
# File 'lib/active_record/connection_adapters/column.rb', line 6 def null @null end |
#sql_type_metadata ⇒ Object (readonly)
Returns the value of attribute sql_type_metadata.
6 7 8 |
# File 'lib/active_record/connection_adapters/column.rb', line 6 def @sql_type_metadata end |
#table_name ⇒ Object (readonly)
Returns the value of attribute table_name.
6 7 8 |
# File 'lib/active_record/connection_adapters/column.rb', line 6 def table_name @table_name end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
65 66 67 68 |
# File 'lib/active_record/connection_adapters/column.rb', line 65 def ==(other) other.is_a?(Column) && attributes_for_hash == other.attributes_for_hash end |
#bigint? ⇒ Boolean
31 32 33 |
# File 'lib/active_record/connection_adapters/column.rb', line 31 def bigint? /\Abigint\b/.match?(sql_type) end |
#encode_with(coder) ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/active_record/connection_adapters/column.rb', line 54 def encode_with(coder) coder["name"] = @name coder["table_name"] = @table_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
27 28 29 |
# File 'lib/active_record/connection_adapters/column.rb', line 27 def has_default? !default.nil? || default_function end |
#hash ⇒ Object
71 72 73 |
# File 'lib/active_record/connection_adapters/column.rb', line 71 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'
39 40 41 |
# File 'lib/active_record/connection_adapters/column.rb', line 39 def human_name Base.human_attribute_name(@name) end |
#init_with(coder) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_record/connection_adapters/column.rb', line 43 def init_with(coder) @name = coder["name"] @table_name = coder["table_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 |