Class: ActiveRecord::Properties::Property
- Inherits:
-
Object
- Object
- ActiveRecord::Properties::Property
- Defined in:
- lib/ar_properties/property.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#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.
-
#null ⇒ Object
readonly
Returns the value of attribute null.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(base, name, type, options = {}) ⇒ Property
constructor
A new instance of Property.
- #primary? ⇒ Boolean
- #sql_type ⇒ Object
- #to_column ⇒ Object
Constructor Details
#initialize(base, name, type, options = {}) ⇒ Property
Returns a new instance of Property.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/ar_properties/property.rb', line 4 def initialize(base, name, type, ={}) @name, @type, @base = name, type, base native = base.native_database_types @limit = .fetch(:limit) do native[type][:limit] if native[type].is_a?(Hash) end @precision = [:precision] @scale = [:scale] @default = [:default] @null = [:null] unless base.native_database_types.keys.include?(type.try(:to_sym)) raise PropertyError, "unknown type: #{type.inspect}" end end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
22 23 24 |
# File 'lib/ar_properties/property.rb', line 22 def base @base end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
22 23 24 |
# File 'lib/ar_properties/property.rb', line 22 def default @default end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
22 23 24 |
# File 'lib/ar_properties/property.rb', line 22 def limit @limit end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/ar_properties/property.rb', line 22 def name @name end |
#null ⇒ Object (readonly)
Returns the value of attribute null.
22 23 24 |
# File 'lib/ar_properties/property.rb', line 22 def null @null end |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
22 23 24 |
# File 'lib/ar_properties/property.rb', line 22 def precision @precision end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
22 23 24 |
# File 'lib/ar_properties/property.rb', line 22 def scale @scale end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
22 23 24 |
# File 'lib/ar_properties/property.rb', line 22 def type @type end |
Instance Method Details
#primary? ⇒ Boolean
34 35 36 |
# File 'lib/ar_properties/property.rb', line 34 def primary? type.to_sym == :primary_key end |
#sql_type ⇒ Object
30 31 32 |
# File 'lib/ar_properties/property.rb', line 30 def sql_type base.type_to_sql(type.to_sym, limit, precision, scale) end |
#to_column ⇒ Object
24 25 26 27 28 |
# File 'lib/ar_properties/property.rb', line 24 def to_column ConnectionAdapters::Column.new(name.to_s, default.try(:to_s), sql_type, null).tap do |column| column.primary = primary? end end |