Class: DataMapper::Types::Yaml

Inherits:
DataMapper::Type show all
Defined in:
lib/gems/dm-types-0.9.9/lib/dm-types/yaml.rb

Constant Summary

Constants inherited from DataMapper::Type

DataMapper::Type::PROPERTY_OPTIONS, DataMapper::Type::PROPERTY_OPTION_ALIASES

Class Method Summary collapse

Methods inherited from DataMapper::Type

bind, configure, inherited, options, primitive

Class Method Details

.dump(value, property) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/yaml.rb', line 19

def self.dump(value, property)
  if value.nil?
    nil
  elsif value.is_a?(String) && value =~ /^---/
    value
  else
    ::YAML.dump(value)
  end
end

.load(value, property) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/yaml.rb', line 9

def self.load(value, property)
  if value.nil?
    nil
  elsif value.is_a?(String)
    ::YAML.load(value)
  else
    raise ArgumentError.new("+value+ must be nil or a String")
  end
end

.typecast(value, property) ⇒ Object



29
30
31
32
# File 'lib/gems/dm-types-0.9.9/lib/dm-types/yaml.rb', line 29

def self.typecast(value, property)
  # No typecasting; leave values exactly as they're provided.
  value
end