
Datamapper::Serialize#to_yaml appears broken in 0.9.10
Reported by Kevin Rea | January 29th, 2009 @ 01:51 AM
object = Producer.first()
YAML.dump(object)
results in error: undefined method []' for
#<StringIO:0x2b22d1b88688>
Attached is patch that fixes this (and fixes the missing explicit types from the YAML output).
Diff inline below as well:
--- a/dm-serializer/lib/dm-serializer/to_yaml.rb
+++ b/dm-serializer/lib/dm-serializer/to_yaml.rb
@@ -6,7 +6,7 @@ module DataMapper
#
# @return <YAML> a YAML representation of this Resource
def to_yaml(opts_or_emitter = {})
- if opts_or_emitter.is_a?(YAML::Syck::Emitter)
+ if not opts_or_emitter.is_a?(Hash)
emitter = opts_or_emitter
opts = {}
else
@@ -14,8 +14,8 @@ module DataMapper
opts = opts_or_emitter
end
- YAML::quick_emit(object_id,emitter) do |out|
- out.map(nil,to_yaml_style) do |map|
+ YAML::quick_emit(self,emitter) do |out|
+ out.map(taguri,to_yaml_style) do |map|
propset = properties_to_serialize(opts)
propset.each do |property|
value = send(property.name.to_sym)
@@ -37,7 +37,7 @@ module DataMapper
class Collection
def to_yaml(opts_or_emitter = {})
- if opts_or_emitter.is_a?(YAML::Syck::Emitter)
+ if not 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)
Comments and changes to this ticket
-
Kevin Rea January 29th, 2009 @ 06:11 PM
First patch file is incomplete second one includes fix for :
objects = Producer.all(:limit => 10) YAML.dump(objects)
I updated the inline diff to reflect this
-
Dan Kubb (dkubb) February 1st, 2009 @ 02:54 PM
- Assigned user set to Xavier Shay
-
Xavier Shay February 1st, 2009 @ 06:28 PM
- State changed from unconfirmed to accepted
-
Xavier Shay February 24th, 2009 @ 03:19 PM
Just tried to apply this and am getting a stack of failures if the form:
1) TypeError in 'DataMapper::Serialize#to_yaml serializes an array of extended objects' can't convert Symbol into String /Users/xavier/Code/dm-more/dm-serializer/spec/public/to_yaml_spec.rb:18:in `deserialize' /Users/xavier/Code/dm-more/dm-serializer/spec/spec_helper.rb:33:in `test' /Users/xavier/Code/dm-more/dm-serializer/spec/lib/serialization_method_shared_spec.rb:28:
It's possible this is a problem with the testing infrastructure, have not investigated as yet.
I have also added some specs to cover this behaviour. Specs are still required for explicit typing.
it 'should allow static YAML dumping' do object = Cow.create( :id => 89, :composite => 34, :name => 'Berta', :breed => 'Guernsey' ) result = @harness.deserialize(YAML.dump(object)) result['name'].should == 'Berta' end it 'should allow static YAML dumping of a collection' do object = Cow.create( :id => 89, :composite => 34, :name => 'Berta', :breed => 'Guernsey' ) result = @harness.deserialize(YAML.dump(Cow.all)) result[0]['name'].should == 'Berta' end
-
Kevin Rea February 25th, 2009 @ 12:31 AM
I apologize, I ran into the issue but neglected to upload the fix. I've attached the complete patch (0003--dm-serializer-Fix-problems-with-Datamapper-Serial.patch), and here's the complete diff inline:
--- a/dm-serializer/lib/dm-serializer/to_yaml.rb +++ b/dm-serializer/lib/dm-serializer/to_yaml.rb @@ -6,7 +6,7 @@ module DataMapper
# # @return <YAML> a YAML representation of this Resource def to_yaml(opts_or_emitter = {})
- if opts_or_emitter.is_a?(YAML::Syck::Emitter)
-
if not opts_or_emitter.is_a?(Hash)
emitter = opts_or_emitter opts = {}
opts = opts_or_emitter
-
YAML::quick_emit(object_id,emitter) do |out|
-
out.map(nil,to_yaml_style) do |map|
- YAML::quick_emit(self,emitter) do |out|
-
out.map(taguri,to_yaml_style) do |map| propset = properties_to_serialize(opts) propset.each do |property|
-
value = send(property.name.to_sym)
-
map.add(property.name, value.is_a?(Class) ? value.to_s : value)
-
value = send(property.name)
-
map.add(property.name.to_s, value.is_a?(Class) ? value.to_s : value) end # add methods (opts[:methods] || []).each do |meth|
class Collection
def to_yaml(opts_or_emitter = {})
- if opts_or_emitter.is_a?(YAML::Syck::Emitter)
- if not opts_or_emitter.is_a?(Hash)
to_a.to_yaml(opts_or_emitter)
# FIXME: Don't double handle the YAML (remove the YAML.load)
-
Xavier Shay March 5th, 2009 @ 05:18 PM
hrm still causing problems for me. I'll have to set aside some proper time to look at it.
-
-
-
Xavier Shay June 19th, 2009 @ 07:20 PM
Sorry, only the dumping bug is fixed. I have omitted the extra type information. This was not specced and no reason was provided for inclusion. Please resubmit a new ticket if this is still desired.
-
Dan Kubb (dkubb) June 23rd, 2009 @ 12:30 AM
- State changed from accepted to resolved
(from [ffe9f6baae8becfd4e7588ac158c2045c256d8e3]) [dm-serializer] Allow static YAML dumping of DM objects
[#792 state:resolved] http://github.com/datamapper/dm-more/commit/ffe9f6baae8becfd4e7588a...
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Tags
Referenced by
-
792 Datamapper::Serialize#to_yaml appears broken in 0.9.10 [#792 state:resolved] http://github.com/datamapper/dm-mo...