Class: DataMapper::Property::Yaml

Inherits:
Text
  • Object
show all
Includes:
DirtyMinder
Defined in:
lib/dm-types/yaml.rb

Direct Known Subclasses

CommaSeparatedList

Instance Method Summary collapse

Methods included from DirtyMinder

#set!

Instance Method Details

#dump(value) ⇒ Object



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

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

#load(value) ⇒ Object



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

def load(value)
  if value.nil?
    nil
  elsif value.is_a?(::String)
    ::YAML.safe_load(value)
  else
    raise ArgumentError, '+value+ of a property of YAML type must be nil or a String'
  end
end

#typecast(value) ⇒ Object



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

def typecast(value)
  value
end