lib/dm-serializer/to_yaml.rb in dm-serializer-0.9.11 vs lib/dm-serializer/to_yaml.rb in dm-serializer-0.10.0
- old
+ new
@@ -4,22 +4,21 @@
module Serialize
# Serialize a Resource to YAML
#
# @return <YAML> a YAML representation of this Resource
def to_yaml(opts_or_emitter = {})
- if opts_or_emitter.is_a?(YAML::Syck::Emitter)
+ if !opts_or_emitter.is_a?(Hash)
emitter = opts_or_emitter
opts = {}
else
emitter = {}
opts = opts_or_emitter
end
YAML::quick_emit(object_id,emitter) do |out|
out.map(nil,to_yaml_style) do |map|
- propset = properties_to_serialize(opts)
- propset.each do |property|
+ properties_to_serialize(opts).each do |property|
value = send(property.name.to_sym)
map.add(property.name, value.is_a?(Class) ? value.to_s : value)
end
# add methods
(opts[:methods] || []).each do |meth|
@@ -35,14 +34,26 @@
end
end
class Collection
def to_yaml(opts_or_emitter = {})
- if opts_or_emitter.is_a?(YAML::Syck::Emitter)
+ if !opts_or_emitter.is_a?(Hash)
to_a.to_yaml(opts_or_emitter)
else
# FIXME: Don't double handle the YAML (remove the YAML.load)
to_a.collect {|x| YAML.load(x.to_yaml(opts_or_emitter)) }.to_yaml
end
end
+ end
+
+ if Serialize::Support.dm_validations_loaded?
+
+ module Validate
+ class ValidationErrors
+ def to_yaml(*args)
+ errors.to_hash.to_yaml(*args)
+ end
+ end
+ end
+
end
end