Class: DataMapper::Property::Yaml

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

Direct Known Subclasses

CommaSeparatedList

Instance Method Summary collapse

Instance Method Details

#custom?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/dm-types/yaml.rb', line 7

def custom?
  true
end

#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.load(value)
  else
    raise ArgumentError.new("+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