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)


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

def custom?
  true
end

#dump(value) ⇒ Object



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

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

#load(value) ⇒ Object



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

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



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

def typecast(value)
  value
end