Skip to content

Commit

Permalink
Implement marshaling methods to avoid issue with serializing mutex
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcolvar authored and gkellogg committed Jan 24, 2019
1 parent 02340e8 commit 37e08df
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
20 changes: 20 additions & 0 deletions lib/rdf/model/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,26 @@ def request_uri
return res
end

##
# Dump of data needed to reconsitute this object using Marshal.load
# This override is needed to avoid serializing @mutex.
#
# @param [Integer] level The maximum depth of objects to dump.
# @return [String] The dump of data needed to reconsitute this object.
def _dump(level)
value
end

##
# Load dumped data to reconsitute marshaled object
# This override is needed to avoid serializing @mutex.
#
# @param [String] data The dump of data needed to reconsitute this object.
# @return [RDF::URI] The reconsituted object.
def self._load(data)
new(data)
end

private

##
Expand Down
13 changes: 13 additions & 0 deletions spec/model_uri_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -983,4 +983,17 @@
end
end
end

describe 'marshaling' do
subject { RDF::URI("http://example/") }

it "marshals them" do
marshaled = Marshal.dump(subject)
loaded = Marshal.load(marshaled)

expect(loaded).to eq subject
# It should have a mutex
expect { loaded.freeze }.not_to raise_error
end
end
end

0 comments on commit 37e08df

Please sign in to comment.