ar-serialize-helpers 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
|
|
1
|
+
module ARSerializeHelpers
|
2
|
+
class Multiple
|
3
|
+
attr_accessor :serializers
|
4
|
+
|
5
|
+
# First defined is first to run when dumping. Last to run when loading.
|
6
|
+
def initialize *serializers
|
7
|
+
self.serializers = serializers
|
8
|
+
end
|
9
|
+
|
10
|
+
def dump obj
|
11
|
+
serializers.reduce(obj) { |obj, serializer| serializer.dump obj }
|
12
|
+
end
|
13
|
+
|
14
|
+
def load obj
|
15
|
+
serializers.reverse.reduce(obj) { |obj, serializer| serializer.load obj }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "ar-serialize-helpers/json"
|
3
|
+
require "ar-serialize-helpers/gzip"
|
4
|
+
require "ar-serialize-helpers/multiple"
|
5
|
+
|
6
|
+
describe ARSerializeHelpers::Multiple do
|
7
|
+
before do
|
8
|
+
@s1, @s2 = ARSerializeHelpers::JSON.new, ARSerializeHelpers::Gzip.new
|
9
|
+
@ms = ARSerializeHelpers::Multiple.new(@s1, @s2)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#initialize" do
|
13
|
+
it "should store the serializers passed in, in the right order" do
|
14
|
+
@ms.serializers.should be == [@s1, @s2]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#dump" do
|
19
|
+
it "should run through the serializers in order given" do
|
20
|
+
@s1.should_receive(:dump).with("my string").and_return(%{"json"})
|
21
|
+
@s2.should_receive(:dump).with(%{"json"}).and_return("gzip")
|
22
|
+
@ms.dump("my string").should be == "gzip"
|
23
|
+
end
|
24
|
+
it "should work with json & gzip properly" do
|
25
|
+
@result = @ms.dump({"my" => "hash"})
|
26
|
+
@result = ActiveSupport::Gzip.decompress(@result)
|
27
|
+
@result.should be == %({"my":"hash"})
|
28
|
+
JSON.parse(@result).should be == {"my" => "hash"}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#load" do
|
33
|
+
it "should run through the serializers in reverse order" do
|
34
|
+
@s2.should_receive(:load).with("gzip").and_return(%{"json"})
|
35
|
+
@s1.should_receive(:load).with(%{"json"}).and_return("my string")
|
36
|
+
@ms.load("gzip").should be == "my string"
|
37
|
+
end
|
38
|
+
it "should work with json & gzip correctly" do
|
39
|
+
@input = {"my" => "hash"}
|
40
|
+
@input = JSON.dump(@input)
|
41
|
+
@input = ActiveSupport::Gzip.compress(@input)
|
42
|
+
@result = @ms.load(@input)
|
43
|
+
@result.should be == {"my" => "hash"}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar-serialize-helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -78,10 +78,12 @@ files:
|
|
78
78
|
- lib/ar-serialize-helpers/gzip.rb
|
79
79
|
- lib/ar-serialize-helpers/integer.rb
|
80
80
|
- lib/ar-serialize-helpers/json.rb
|
81
|
+
- lib/ar-serialize-helpers/multiple.rb
|
81
82
|
- lib/ar-serialize-helpers/version.rb
|
82
83
|
- spec/ar-serialize-helpers/gzip_spec.rb
|
83
84
|
- spec/ar-serialize-helpers/integer_spec.rb
|
84
85
|
- spec/ar-serialize-helpers/json_spec.rb
|
86
|
+
- spec/ar-serialize-helpers/multiple_spec.rb
|
85
87
|
- spec/spec_helper.rb
|
86
88
|
homepage: http://github.com/EmberAds/ar-serialize-helpers
|
87
89
|
licenses: []
|
@@ -111,5 +113,6 @@ test_files:
|
|
111
113
|
- spec/ar-serialize-helpers/gzip_spec.rb
|
112
114
|
- spec/ar-serialize-helpers/integer_spec.rb
|
113
115
|
- spec/ar-serialize-helpers/json_spec.rb
|
116
|
+
- spec/ar-serialize-helpers/multiple_spec.rb
|
114
117
|
- spec/spec_helper.rb
|
115
118
|
has_rdoc:
|