Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement marshaling methods to avoid issue with serializing mutex #392

Merged
merged 1 commit into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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