Class: ActiveRecord::TypedStore::Field
- Inherits:
-
Object
- Object
- ActiveRecord::TypedStore::Field
- Defined in:
- lib/active_record/typed_store/field.rb
Instance Attribute Summary collapse
-
#accessor ⇒ Object
readonly
Returns the value of attribute accessor.
-
#array ⇒ Object
readonly
Returns the value of attribute array.
-
#blank ⇒ Object
readonly
Returns the value of attribute blank.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#null ⇒ Object
readonly
Returns the value of attribute null.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#type_sym ⇒ Object
readonly
Returns the value of attribute type_sym.
Instance Method Summary collapse
- #cast(value) ⇒ Object
- #has_default? ⇒ Boolean
-
#initialize(name, type, options = {}) ⇒ Field
constructor
A new instance of Field.
Constructor Details
#initialize(name, type, options = {}) ⇒ Field
Returns a new instance of Field.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/active_record/typed_store/field.rb', line 7 def initialize(name, type, ={}) = .slice(:scale, :limit, :precision) @type = lookup_type(type, ) @type_sym = type @accessor = .fetch(:accessor, true) @name = name if .key?(:default) @default = extract_default([:default]) end @null = .fetch(:null, true) @blank = .fetch(:blank, true) @array = .fetch(:array, false) end |
Instance Attribute Details
#accessor ⇒ Object (readonly)
Returns the value of attribute accessor.
5 6 7 |
# File 'lib/active_record/typed_store/field.rb', line 5 def accessor @accessor end |
#array ⇒ Object (readonly)
Returns the value of attribute array.
5 6 7 |
# File 'lib/active_record/typed_store/field.rb', line 5 def array @array end |
#blank ⇒ Object (readonly)
Returns the value of attribute blank.
5 6 7 |
# File 'lib/active_record/typed_store/field.rb', line 5 def blank @blank end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
5 6 7 |
# File 'lib/active_record/typed_store/field.rb', line 5 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/active_record/typed_store/field.rb', line 5 def name @name end |
#null ⇒ Object (readonly)
Returns the value of attribute null.
5 6 7 |
# File 'lib/active_record/typed_store/field.rb', line 5 def null @null end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
5 6 7 |
# File 'lib/active_record/typed_store/field.rb', line 5 def type @type end |
#type_sym ⇒ Object (readonly)
Returns the value of attribute type_sym.
5 6 7 |
# File 'lib/active_record/typed_store/field.rb', line 5 def type_sym @type_sym end |
Instance Method Details
#cast(value) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/active_record/typed_store/field.rb', line 26 def cast(value) casted_value = type_cast(value) if !blank casted_value = default if casted_value.blank? elsif !null casted_value = default if casted_value.nil? end casted_value end |
#has_default? ⇒ Boolean
22 23 24 |
# File 'lib/active_record/typed_store/field.rb', line 22 def has_default? defined?(@default) end |