Class: DataMapper::Mappings::Column
- Inherits:
-
Object
- Object
- DataMapper::Mappings::Column
- Defined in:
- lib/data_mapper/mappings/column.rb
Overview
TODO: There are of course many more options to add here. Ordinal, Length/Size, Nullability are just a few.
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #column_name ⇒ Object
-
#initialize(database, name, type, options = {}) ⇒ Column
constructor
A new instance of Column.
- #inspect ⇒ Object
- #instance_variable_name ⇒ Object
- #key? ⇒ Boolean
- #lazy=(value) ⇒ Object
-
#lazy? ⇒ Boolean
Determines if the field should be lazy loaded.
- #nullable? ⇒ Boolean
- #size ⇒ Object
- #to_s ⇒ Object
- #to_sql ⇒ Object
- #to_sym ⇒ Object
- #type_cast_value(value) ⇒ Object
Constructor Details
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/data_mapper/mappings/column.rb', line 8 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/data_mapper/mappings/column.rb', line 8 def @options end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/data_mapper/mappings/column.rb', line 8 def type @type end |
Instance Method Details
#column_name ⇒ Object
50 51 52 |
# File 'lib/data_mapper/mappings/column.rb', line 50 def column_name @column_name || (@column_name = (@options.has_key?(:column) ? @options[:column].to_s : name.to_s.gsub(/\?$/, '')).freeze) end |
#inspect ⇒ Object
71 72 73 |
# File 'lib/data_mapper/mappings/column.rb', line 71 def inspect "#<%s:0x%x @name=%s, @type=%s, @options=%s>" % [self.class.name, (object_id * 2), to_sql, type.inspect, .inspect] end |
#instance_variable_name ⇒ Object
38 39 40 |
# File 'lib/data_mapper/mappings/column.rb', line 38 def instance_variable_name @instance_variable_name || (@instance_variable_name = "@#{@name.to_s.gsub(/\?$/, '')}".freeze) end |
#key? ⇒ Boolean
30 31 32 |
# File 'lib/data_mapper/mappings/column.rb', line 30 def key? @options[:key] || false end |
#lazy=(value) ⇒ Object
15 16 17 |
# File 'lib/data_mapper/mappings/column.rb', line 15 def lazy=(value) @options[:lazy] = value end |
#lazy? ⇒ Boolean
Determines if the field should be lazy loaded. You can set this explicitly, or accept the default, which is false for all but text fields.
22 23 24 |
# File 'lib/data_mapper/mappings/column.rb', line 22 def lazy? @options[:lazy] || (type == :text) end |
#nullable? ⇒ Boolean
26 27 28 |
# File 'lib/data_mapper/mappings/column.rb', line 26 def nullable? @options[:nullable] || true end |
#size ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/data_mapper/mappings/column.rb', line 58 def size @size || begin return @size = @options[:size] if @options.has_key?(:size) return @size = @options[:length] if @options.has_key?(:length) @size = case type when :integer then 4 when :string, :class then 50 else nil end end end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/data_mapper/mappings/column.rb', line 42 def to_s @name.to_s end |
#to_sql ⇒ Object
54 55 56 |
# File 'lib/data_mapper/mappings/column.rb', line 54 def to_sql @to_sql || (@to_sql = @database.quote_column_name(column_name).freeze) end |
#to_sym ⇒ Object
34 35 36 |
# File 'lib/data_mapper/mappings/column.rb', line 34 def to_sym @name end |
#type_cast_value(value) ⇒ Object
46 47 48 |
# File 'lib/data_mapper/mappings/column.rb', line 46 def type_cast_value(value) @database.type_cast_value(type, value) end |