Class: StoreSchema::Converter

Inherits:
Object
  • Object
show all
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.

Returns:

  • (Hash)

    a mapping between the configuration block and the converter classes.

{
  string: String,
  integer: Integer,
  float: Float,
  datetime: DateTime,
  boolean: Boolean
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, type) ⇒ Converter

Returns a new instance of Converter.

Parameters:

  • value (Object)

    any kind of value that should be stored

  • type (Symbol)

    the type of the value


30
31
32
33
# File 'lib/store_schema/converter.rb', line 30

def initialize(value, type)
  @value = value
  @type = type
end

Instance Attribute Details

#typeSymbol (readonly)

Returns:

  • (Symbol)

25
26
27
# File 'lib/store_schema/converter.rb', line 25

def type
  @type
end

#valueObject (readonly)

Returns:

  • (Object)

21
22
23
# File 'lib/store_schema/converter.rb', line 21

def value
  @value
end

Instance Method Details

#from_dbObject

Converts #value from a database-storable value to a Ruby-type value.

Returns:

  • (Object)

47
48
49
# File 'lib/store_schema/converter.rb', line 47

def from_db
  MAPPING[type].new(value).from_db
end

#to_dbString

Converts #value from a Ruby-type value to a database-storable value.

Returns:


39
40
41
# File 'lib/store_schema/converter.rb', line 39

def to_db
  MAPPING[type].new(value).to_db
end