Skip to content

Commit 37e08df

Browse files
cjcolvargkellogg
authored andcommitted
Implement marshaling methods to avoid issue with serializing mutex
1 parent 02340e8 commit 37e08df

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

lib/rdf/model/uri.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,26 @@ def request_uri
12631263
return res
12641264
end
12651265

1266+
##
1267+
# Dump of data needed to reconsitute this object using Marshal.load
1268+
# This override is needed to avoid serializing @mutex.
1269+
#
1270+
# @param [Integer] level The maximum depth of objects to dump.
1271+
# @return [String] The dump of data needed to reconsitute this object.
1272+
def _dump(level)
1273+
value
1274+
end
1275+
1276+
##
1277+
# Load dumped data to reconsitute marshaled object
1278+
# This override is needed to avoid serializing @mutex.
1279+
#
1280+
# @param [String] data The dump of data needed to reconsitute this object.
1281+
# @return [RDF::URI] The reconsituted object.
1282+
def self._load(data)
1283+
new(data)
1284+
end
1285+
12661286
private
12671287

12681288
##

spec/model_uri_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -983,4 +983,17 @@
983983
end
984984
end
985985
end
986+
987+
describe 'marshaling' do
988+
subject { RDF::URI("http://example/") }
989+
990+
it "marshals them" do
991+
marshaled = Marshal.dump(subject)
992+
loaded = Marshal.load(marshaled)
993+
994+
expect(loaded).to eq subject
995+
# It should have a mutex
996+
expect { loaded.freeze }.not_to raise_error
997+
end
998+
end
986999
end

0 commit comments

Comments
 (0)