thirtythirty 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/thirtythirty.rb +8 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/classes.rb +17 -0
- data/spec/thirtythirty_spec.rb +43 -21
- data/thirtythirty.gemspec +1 -1
- metadata +5 -11
- data/spec/support/compressed.rb +0 -4
- data/spec/support/thirtythirty_base.rb +0 -3
- data/spec/support/tree.rb +0 -4
- data/spec/support/uncompressed.rb +0 -3
data/lib/thirtythirty.rb
CHANGED
@@ -7,7 +7,7 @@ module Thirtythirty
|
|
7
7
|
send :include, InstanceMethods
|
8
8
|
@marshalled_attributes = []
|
9
9
|
end
|
10
|
-
@marshalled_attributes = (@marshalled_attributes.map | attributes.flatten.map(&:to_sym).uniq)
|
10
|
+
@marshalled_attributes = (@marshalled_attributes.map | attributes.flatten.map(&:to_sym).uniq)
|
11
11
|
end
|
12
12
|
|
13
13
|
# Activates marshalling for the given attributes and generates getters - you have to implement setters yourself!
|
@@ -34,7 +34,13 @@ private
|
|
34
34
|
|
35
35
|
module ClassMethods
|
36
36
|
|
37
|
-
|
37
|
+
def marshalled_attributes
|
38
|
+
((superclass.respond_to?(:marshalled_attributes) ? superclass.marshalled_attributes : []) + (@marshalled_attributes || [])).uniq.freeze
|
39
|
+
end
|
40
|
+
|
41
|
+
def marshalling_compression_level
|
42
|
+
@marshalling_compression_level || (superclass.respond_to?(:marshalling_compression_level) ? superclass.marshalling_compression_level : nil)
|
43
|
+
end
|
38
44
|
|
39
45
|
protected
|
40
46
|
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
class ThirtythirtyBase
|
2
|
+
extend Thirtythirty
|
3
|
+
end
|
4
|
+
|
5
|
+
class ThirtythirtyTree < ThirtythirtyBase
|
6
|
+
marshalled_accessor :persistent, :parent, :children
|
7
|
+
attr_accessor :transient
|
8
|
+
end
|
9
|
+
|
10
|
+
class Uncompressed < ThirtythirtyBase
|
11
|
+
marshalled_accessor :persistent
|
12
|
+
end
|
13
|
+
|
14
|
+
class Compressed < ThirtythirtyBase
|
15
|
+
marshal_with_compression
|
16
|
+
marshalled_accessor :persistent
|
17
|
+
end
|
data/spec/thirtythirty_spec.rb
CHANGED
@@ -154,49 +154,47 @@ describe Thirtythirty do
|
|
154
154
|
|
155
155
|
describe "marshalling (#_dump/._load)" do
|
156
156
|
|
157
|
-
|
158
|
-
@obj = ThirtythirtyTree.new
|
159
|
-
end
|
157
|
+
subject { ThirtythirtyTree.new }
|
160
158
|
|
161
159
|
it "should dump a string" do
|
162
|
-
Marshal.dump(
|
160
|
+
Marshal.dump(subject).should be_a(String)
|
163
161
|
end
|
164
162
|
|
165
163
|
it "should restore a ThirtythirtyTree" do
|
166
|
-
Marshal.load(Marshal.dump(
|
164
|
+
Marshal.load(Marshal.dump(subject)).should be_a(ThirtythirtyTree)
|
167
165
|
end
|
168
166
|
|
169
167
|
it "should dump/restore marshalled attributes" do
|
170
|
-
|
171
|
-
restored = Marshal.load(Marshal.dump(
|
168
|
+
subject.persistent = "data"
|
169
|
+
restored = Marshal.load(Marshal.dump(subject))
|
172
170
|
restored.persistent.should == "data"
|
173
171
|
end
|
174
172
|
|
175
173
|
it "should not dump/restore unmarshalled attributes" do
|
176
|
-
|
177
|
-
restored = Marshal.load(Marshal.dump(
|
174
|
+
subject.transient = "data"
|
175
|
+
restored = Marshal.load(Marshal.dump(subject))
|
178
176
|
restored.transient.should be_nil
|
179
177
|
end
|
180
178
|
|
181
179
|
context "with a single relation" do
|
182
180
|
|
183
181
|
before do
|
184
|
-
|
182
|
+
subject.parent = ThirtythirtyTree.new
|
185
183
|
end
|
186
184
|
|
187
185
|
it "should restore a ThirtythirtyTree" do
|
188
|
-
Marshal.load(Marshal.dump(
|
186
|
+
Marshal.load(Marshal.dump(subject)).parent.should be_a(ThirtythirtyTree)
|
189
187
|
end
|
190
188
|
|
191
189
|
it "should dump/restore marshalled attributes" do
|
192
|
-
|
193
|
-
restored = Marshal.load(Marshal.dump(
|
190
|
+
subject.parent.persistent = "data"
|
191
|
+
restored = Marshal.load(Marshal.dump(subject))
|
194
192
|
restored.parent.persistent.should == "data"
|
195
193
|
end
|
196
194
|
|
197
195
|
it "should not dump/restore unmarshalled attributes" do
|
198
|
-
|
199
|
-
restored = Marshal.load(Marshal.dump(
|
196
|
+
subject.parent.transient = "data"
|
197
|
+
restored = Marshal.load(Marshal.dump(subject))
|
200
198
|
restored.parent.transient.should be_nil
|
201
199
|
end
|
202
200
|
|
@@ -205,25 +203,25 @@ describe Thirtythirty do
|
|
205
203
|
context "with a collection relation" do
|
206
204
|
|
207
205
|
before do
|
208
|
-
|
206
|
+
subject.children = [ThirtythirtyTree.new]
|
209
207
|
end
|
210
208
|
|
211
209
|
it "should restore an array of ThirtythirtyTrees" do
|
212
|
-
children = Marshal.load(Marshal.dump(
|
210
|
+
children = Marshal.load(Marshal.dump(subject)).children
|
213
211
|
children.should be_a(Array)
|
214
212
|
children.size.should == 1
|
215
213
|
children.first.should be_a(ThirtythirtyTree)
|
216
214
|
end
|
217
215
|
|
218
216
|
it "should dump/restore marshalled attributes" do
|
219
|
-
|
220
|
-
restored = Marshal.load(Marshal.dump(
|
217
|
+
subject.children.first.persistent = "data"
|
218
|
+
restored = Marshal.load(Marshal.dump(subject))
|
221
219
|
restored.children.first.persistent.should == "data"
|
222
220
|
end
|
223
221
|
|
224
222
|
it "should not dump/restore unmarshalled attributes" do
|
225
|
-
|
226
|
-
restored = Marshal.load(Marshal.dump(
|
223
|
+
subject.children.first.transient = "data"
|
224
|
+
restored = Marshal.load(Marshal.dump(subject))
|
227
225
|
restored.children.first.transient.should be_nil
|
228
226
|
end
|
229
227
|
|
@@ -249,4 +247,28 @@ describe Thirtythirty do
|
|
249
247
|
|
250
248
|
end
|
251
249
|
|
250
|
+
describe "inheritance" do
|
251
|
+
|
252
|
+
it "should have the same marshalled attributes as the parent" do
|
253
|
+
Class.new(ThirtythirtyTree).marshalled_attributes.should == ThirtythirtyTree.marshalled_attributes
|
254
|
+
end
|
255
|
+
|
256
|
+
it "should be able to add it's own marshalled attributes" do
|
257
|
+
Class.new(ThirtythirtyTree) do
|
258
|
+
marshalled_accessor :another_persistent
|
259
|
+
end.marshalled_attributes.should == ThirtythirtyTree.marshalled_attributes + [:another_persistent]
|
260
|
+
end
|
261
|
+
|
262
|
+
it "should have the same compression level as the parent" do
|
263
|
+
Class.new(Compressed).marshalling_compression_level.should == Compressed.marshalling_compression_level
|
264
|
+
end
|
265
|
+
|
266
|
+
it "should be able to set it's own compression level" do
|
267
|
+
Class.new(Uncompressed) do
|
268
|
+
marshal_with_compression Zlib::BEST_COMPRESSION
|
269
|
+
end.marshalling_compression_level.should == Zlib::BEST_COMPRESSION
|
270
|
+
end
|
271
|
+
|
272
|
+
end
|
273
|
+
|
252
274
|
end
|
data/thirtythirty.gemspec
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thirtythirty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Benjamin Behr
|
@@ -69,10 +69,7 @@ files:
|
|
69
69
|
- Rakefile
|
70
70
|
- lib/thirtythirty.rb
|
71
71
|
- spec/spec_helper.rb
|
72
|
-
- spec/support/
|
73
|
-
- spec/support/thirtythirty_base.rb
|
74
|
-
- spec/support/tree.rb
|
75
|
-
- spec/support/uncompressed.rb
|
72
|
+
- spec/support/classes.rb
|
76
73
|
- spec/thirtythirty_spec.rb
|
77
74
|
- thirtythirty.gemspec
|
78
75
|
has_rdoc: true
|
@@ -111,8 +108,5 @@ specification_version: 3
|
|
111
108
|
summary: Marshalling customization
|
112
109
|
test_files:
|
113
110
|
- spec/spec_helper.rb
|
114
|
-
- spec/support/
|
115
|
-
- spec/support/thirtythirty_base.rb
|
116
|
-
- spec/support/tree.rb
|
117
|
-
- spec/support/uncompressed.rb
|
111
|
+
- spec/support/classes.rb
|
118
112
|
- spec/thirtythirty_spec.rb
|
data/spec/support/compressed.rb
DELETED
data/spec/support/tree.rb
DELETED