Class: StoreSchema::Converter
- Inherits:
-
Object
- Object
- StoreSchema::Converter
- Defined in:
- lib/store_schema/converter.rb
Defined Under Namespace
Classes: Base, Boolean, DateTime, Float, Integer, String
Constant Summary collapse
- MAPPING =
Returns a mapping between the configuration block and the converter classes.
{ string: String, integer: Integer, float: Float, datetime: DateTime, boolean: Boolean }
Instance Attribute Summary collapse
- #type ⇒ Symbol readonly
- #value ⇒ Object readonly
Instance Method Summary collapse
-
#from_db ⇒ Object
Converts #value from a database-storable value to a Ruby-type value.
-
#initialize(value, type) ⇒ Converter
constructor
A new instance of Converter.
-
#to_db ⇒ String
Converts #value from a Ruby-type value to a database-storable value.
Constructor Details
#initialize(value, type) ⇒ Converter
Returns a new instance of Converter.
30 31 32 33 |
# File 'lib/store_schema/converter.rb', line 30 def initialize(value, type) @value = value @type = type end |
Instance Attribute Details
#type ⇒ Symbol (readonly)
25 26 27 |
# File 'lib/store_schema/converter.rb', line 25 def type @type end |
#value ⇒ Object (readonly)
21 22 23 |
# File 'lib/store_schema/converter.rb', line 21 def value @value end |
Instance Method Details
#from_db ⇒ Object
Converts #value from a database-storable value to a Ruby-type value.
47 48 49 |
# File 'lib/store_schema/converter.rb', line 47 def from_db MAPPING[type].new(value).from_db end |