Module: Arc::Casting

Included in:
DataStores::AbstractDataStore
Defined in:
lib/arc/casting.rb

Defined Under Namespace

Classes: CannotCastValueError

Constant Summary collapse

TYPES =
{ 
  integer:    'integer',
  int:        'integer',
  char:       'string' ,
  varchar:    'string' ,
  binary:     'binary' ,
  date:       'date'   ,
  datetime:   'time'   ,
  time:       'time'   ,
  bool:       'boolean',
  boolean:    'boolean', 
  bit:        'boolean',
  float:      'float'  ,
  text:       'string' ,
  bytea:      'binary' ,
  timestamp:  'timestamp',
  blob:       'binary'
}
CAST_METHODS =
Hash.new do |cast_methods, key|
  method = "cast_#{TYPES[key.to_sym]}"
  cast_methods[key] = method 
end

Instance Method Summary collapse

Instance Method Details

#cast(value, type) ⇒ Object



29
30
31
32
33
# File 'lib/arc/casting.rb', line 29

def cast value, type
  method = CAST_METHODS[type]
  return send method, value if respond_to? method, :include_private
  return cast_string value
end