thirtythirty 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
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).freeze
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
- attr_reader :marshalled_attributes, :marshalling_compression_level
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
@@ -2,5 +2,4 @@ require 'rubygems'
2
2
  require 'bundler'
3
3
  Bundler.require(:default, :development)
4
4
 
5
- require File.expand_path '../support/thirtythirty_base.rb', __FILE__
6
5
  Dir[File.expand_path '../support/*.rb', __FILE__].each {|f| require f}
@@ -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
@@ -154,49 +154,47 @@ describe Thirtythirty do
154
154
 
155
155
  describe "marshalling (#_dump/._load)" do
156
156
 
157
- before do
158
- @obj = ThirtythirtyTree.new
159
- end
157
+ subject { ThirtythirtyTree.new }
160
158
 
161
159
  it "should dump a string" do
162
- Marshal.dump(@obj).should be_a(String)
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(@obj)).should be_a(ThirtythirtyTree)
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
- @obj.persistent = "data"
171
- restored = Marshal.load(Marshal.dump(@obj))
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
- @obj.transient = "data"
177
- restored = Marshal.load(Marshal.dump(@obj))
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
- @obj.parent = ThirtythirtyTree.new
182
+ subject.parent = ThirtythirtyTree.new
185
183
  end
186
184
 
187
185
  it "should restore a ThirtythirtyTree" do
188
- Marshal.load(Marshal.dump(@obj)).parent.should be_a(ThirtythirtyTree)
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
- @obj.parent.persistent = "data"
193
- restored = Marshal.load(Marshal.dump(@obj))
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
- @obj.parent.transient = "data"
199
- restored = Marshal.load(Marshal.dump(@obj))
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
- @obj.children = [ThirtythirtyTree.new]
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(@obj)).children
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
- @obj.children.first.persistent = "data"
220
- restored = Marshal.load(Marshal.dump(@obj))
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
- @obj.children.first.transient = "data"
226
- restored = Marshal.load(Marshal.dump(@obj))
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
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = "thirtythirty"
4
- s.version = "0.0.5"
4
+ s.version = "0.0.6"
5
5
  s.date = Time.now
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Benjamin Behr", "Thomas Jachmann"]
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: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
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/compressed.rb
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/compressed.rb
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
@@ -1,4 +0,0 @@
1
- class Compressed < ThirtythirtyBase
2
- marshal_with_compression
3
- marshalled_accessor :persistent
4
- end
@@ -1,3 +0,0 @@
1
- class ThirtythirtyBase
2
- extend Thirtythirty
3
- end
data/spec/support/tree.rb DELETED
@@ -1,4 +0,0 @@
1
- class ThirtythirtyTree < ThirtythirtyBase
2
- marshalled_accessor :persistent, :parent, :children
3
- attr_accessor :transient
4
- end
@@ -1,3 +0,0 @@
1
- class Uncompressed < ThirtythirtyBase
2
- marshalled_accessor :persistent
3
- end