Class: DataMapper::Types::Yaml

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

Class Method Summary collapse

Class Method Details

.dump(value, property) ⇒ Object



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

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



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

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



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

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