Class: ActiveRecord::ConnectionAdapters::Column
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::Column
- Defined in:
- lib/active_record/connection_adapters/abstract_adapter.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #human_name ⇒ Object
-
#initialize(name, default, sql_type = nil) ⇒ Column
constructor
The name should contain the name of the column, such as “name” in “name varchar(250)” The default should contain the type-casted default of the column, such as 1 in “count int(11) DEFAULT 1” The type parameter should either contain :integer, :float, :datetime, :date, :text, or :string The sql_type is just used for extracting the limit, such as 10 in “varchar(10)”.
- #klass ⇒ Object
- #type_cast(value) ⇒ Object
Constructor Details
#initialize(name, default, sql_type = nil) ⇒ Column
The name should contain the name of the column, such as “name” in “name varchar(250)” The default should contain the type-casted default of the column, such as 1 in “count int(11) DEFAULT 1” The type parameter should either contain :integer, :float, :datetime, :date, :text, or :string The sql_type is just used for extracting the limit, such as 10 in “varchar(10)”
140 141 142 143 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 140 def initialize(name, default, sql_type = nil) @name, @default, @type = name, default, simplified_type(sql_type) @limit = extract_limit(sql_type) unless sql_type.nil? end |
Instance Attribute Details
#default ⇒ Object (readonly)
Returns the value of attribute default.
135 136 137 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 135 def default @default end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
135 136 137 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 135 def limit @limit end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
135 136 137 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 135 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
135 136 137 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 135 def type @type end |
Instance Method Details
#human_name ⇒ Object
174 175 176 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 174 def human_name Base.human_attribute_name(@name) end |
#klass ⇒ Object
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 149 def klass case type when :integer then Fixnum when :float then Float when :datetime then Time when :date then Date when :text, :string then String when :boolean then Object end end |
#type_cast(value) ⇒ Object
160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/active_record/connection_adapters/abstract_adapter.rb', line 160 def type_cast(value) if value.nil? then return nil end case type when :string then value when :text then value when :integer then value.to_i when :float then value.to_f when :datetime then string_to_time(value) when :date then string_to_date(value) when :boolean then (value == "t" or value == true ? true : false) else value end end |