baccigalupi-aqua 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Aqua.gemspec +2 -2
- data/README.rdoc +10 -2
- data/VERSION +1 -1
- data/doc/custom.css +16 -1
- data/lib/aqua/object/pack.rb +23 -12
- data/lib/aqua/object/unpack.rb +12 -5
- data/spec/object/pack_spec.rb +102 -74
- data/spec/object/unpack_spec.rb +26 -4
- metadata +3 -4
data/Aqua.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{aqua}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kane Baccigalupi"]
|
12
|
-
s.date = %q{2009-08-
|
12
|
+
s.date = %q{2009-08-25}
|
13
13
|
s.description = %q{Even with ORMs like ActiveRecord, DataMapper which ease the pain of relational data storage, considerable developer effort goes into wrangling Ruby objects into their databases. Document-oriented databases have made it possible to store nested data structures that easily map to Ruby objects. Aqua (http://github.com/baccigalupi/aqua) is a new Ruby library that aims to painlessly persists objects, allowing developers to focus more on object oriented code and less on storage. Currently Aqua is in pre-alpha testing, with the following big things left to implement: A data query DSL and implementation; Support of all objects in the Standard Library; Class and code storage to allow the sharing and persistence of classes with their data.}
|
14
14
|
s.email = %q{baccigalupi@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/README.rdoc
CHANGED
@@ -12,7 +12,7 @@ Currently Aqua is in pre-alpha testing, with the following big things left to im
|
|
12
12
|
* Object keys, including symbols for hash-like objects
|
13
13
|
* Data storage amenity add-ons including: validation, callbacks, AR-styled syntax, and properties that automate some of the object typing, validation, and searchability option.
|
14
14
|
|
15
|
-
Aqua aims to be lean and modular, in addition to transparent. Currently it weighs in at 1000 lines of code with half of that for the CouchDB storage engine.
|
15
|
+
Aqua aims to be lean and modular, in addition to transparent. Currently it weighs in at 1000 lines of code with half of that for the CouchDB storage engine.
|
16
16
|
|
17
17
|
== Usage
|
18
18
|
|
@@ -67,7 +67,9 @@ Currently, Aqua uses CouchDB for its storage. Make sure you have CouchDB install
|
|
67
67
|
user.reload # retrieves the latest saved version of the object
|
68
68
|
u = User.load( user.id ) # returns your persisted user object, like you just added water!
|
69
69
|
puts u.inspect
|
70
|
-
# #<User:0x1a16480 @name=["Kane", "Baccigalupi"], @created_at=Fri Aug 21 12:07:39 -0700 2009, @_store=nil, @username="kane", @dob=#<Date: 4881157/2,0,2299161>, @id="c664770982b92e9fa802e0ed664a9846">
|
70
|
+
# #<User:0x1a16480 @name=["Kane", "Baccigalupi"], @created_at=Fri Aug 21 12:07:39 -0700 2009, @_store=nil, @username="kane", @dob=#<Date: 4881157/2,0,2299161>, @id="c664770982b92e9fa802e0ed664a9846">
|
71
|
+
|
72
|
+
# woot!
|
71
73
|
|
72
74
|
== Installation
|
73
75
|
|
@@ -76,6 +78,12 @@ Aqua is so young that it hasn't made it over to the established land of rubyforg
|
|
76
78
|
gem sources -a http://gems.github.com
|
77
79
|
sudo gem install baccigalupi-aqua
|
78
80
|
|
81
|
+
== More Info
|
82
|
+
|
83
|
+
Twitter: rubyaqua
|
84
|
+
|
85
|
+
Rdocs: http://ruby-aqua.org
|
86
|
+
|
79
87
|
== Contributing
|
80
88
|
|
81
89
|
Bug fixes and features are welcome.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.2
|
data/doc/custom.css
CHANGED
@@ -1 +1,16 @@
|
|
1
|
-
/* Override this stylesheet in your templates directory with any extra declarations */
|
1
|
+
/* Override this stylesheet in your templates directory with any extra declarations */
|
2
|
+
body {
|
3
|
+
font-family: Trebuchet, 'Trebuchet MS', Verdana, Arial, sans-serif;
|
4
|
+
font-size: 11pt; line-height: 1.5;
|
5
|
+
}
|
6
|
+
a { color: #069;}
|
7
|
+
a:visited { color: #444;}
|
8
|
+
|
9
|
+
.section.module h1.title, .section.class h1.title, .section.readme h1 {
|
10
|
+
background-color: #09C; color: white; border-width: 0px;
|
11
|
+
}
|
12
|
+
.section.readme h1 { margin:0 0 7px -7px; }
|
13
|
+
|
14
|
+
h2 { background-color: #a2e3f9; color:#000000; padding-left: 7px; }
|
15
|
+
.readme h2 { margin:0 0 7px -7px; }
|
16
|
+
|
data/lib/aqua/object/pack.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This module is responsible for packing objects into Storage Objects
|
2
2
|
# The Storage Object is expected to be a Mash-Like thing (Hash with indifferent access).
|
3
|
-
# It is the job of the storage engine to convert the Mash into the actual storage
|
3
|
+
# It is the job of the storage engine to convert the Mash into the actual storage ivars.
|
4
4
|
module Aqua::Pack
|
5
5
|
|
6
6
|
def self.included( klass )
|
@@ -68,6 +68,7 @@ module Aqua::Pack
|
|
68
68
|
self.__pack.id = @id if @id
|
69
69
|
self.__pack[:_rev] = _rev if _rev
|
70
70
|
self.__pack[:class] = class_name
|
71
|
+
self.__pack[:keys] = []
|
71
72
|
_pack_properties
|
72
73
|
_pack_singletons
|
73
74
|
__pack
|
@@ -136,9 +137,9 @@ module Aqua::Pack
|
|
136
137
|
# Examines each ivar and converts it to a hash, array, string combo
|
137
138
|
# @api private
|
138
139
|
def _pack_properties
|
139
|
-
self.__pack[:
|
140
|
+
self.__pack[:ivars] = _pack_ivars( self )
|
140
141
|
initializations = _pack_initializations( self )
|
141
|
-
self.__pack[:
|
142
|
+
self.__pack[:init] = initializations unless initializations.empty?
|
142
143
|
end
|
143
144
|
|
144
145
|
def _pack_initializations( obj )
|
@@ -178,26 +179,27 @@ module Aqua::Pack
|
|
178
179
|
if klass == String
|
179
180
|
obj
|
180
181
|
elsif [TrueClass, FalseClass].include?( klass )
|
181
|
-
{ 'class' => klass.to_s, '
|
182
|
+
{ 'class' => klass.to_s, 'init' => obj.to_s }
|
182
183
|
elsif [Time, Date, Fixnum, Bignum, Float ].include?( klass )
|
183
184
|
{
|
184
185
|
'class' => klass.to_s,
|
185
|
-
'
|
186
|
+
'init' => obj.to_s
|
186
187
|
}
|
187
188
|
elsif klass == Rational
|
188
189
|
{
|
189
190
|
'class' => klass.to_s,
|
190
|
-
'
|
191
|
+
'init' => obj.to_s.match(/(\d*)\/(\d*)/).to_a.slice(1,2)
|
191
192
|
}
|
192
193
|
else # a more complex object, including an array or a hash like thing
|
193
194
|
return_hash = {}
|
194
|
-
if obj.aquatic?
|
195
|
+
if obj.aquatic?
|
196
|
+
# TODO distinguish between internal storage, stubbing and external (obj.aquatic? && obj._embed_me == true)
|
195
197
|
return_hash = obj._pack
|
196
198
|
elsif !obj.aquatic?
|
197
199
|
initialization = _pack_initializations( obj )
|
198
|
-
return_hash['
|
200
|
+
return_hash['init'] = initialization unless initialization.empty?
|
199
201
|
data = _pack_ivars( obj )
|
200
|
-
return_hash['
|
202
|
+
return_hash['ivars'] = data unless data.empty?
|
201
203
|
return_hash['class'] = klass.to_s
|
202
204
|
# TODO: distinguish between internal storage, stubbing and external (obj.aquatic? && obj._embed_me == true)
|
203
205
|
# elsif obj._embed_me.class == Hash
|
@@ -216,9 +218,18 @@ module Aqua::Pack
|
|
216
218
|
# @api private
|
217
219
|
def _pack_hash( hash )
|
218
220
|
return_hash = {}
|
219
|
-
hash.each do |
|
220
|
-
|
221
|
-
|
221
|
+
hash.each do |raw_key, value|
|
222
|
+
key_class = raw_key.class
|
223
|
+
if key_class == Symbol
|
224
|
+
key = ":#{raw_key.to_s}"
|
225
|
+
elsif key_class == String
|
226
|
+
key = raw_key
|
227
|
+
else
|
228
|
+
index = self.__pack[:keys].length
|
229
|
+
self.__pack[:keys] << _pack_object( raw_key )
|
230
|
+
key = "/OBJECT_#{index}"
|
231
|
+
end
|
232
|
+
return_hash[key] = _pack_object( value )
|
222
233
|
end
|
223
234
|
return_hash
|
224
235
|
end
|
data/lib/aqua/object/unpack.rb
CHANGED
@@ -59,7 +59,7 @@ module Aqua::Unpack
|
|
59
59
|
if init = _unpack_initialization( _store )
|
60
60
|
replace( init )
|
61
61
|
end
|
62
|
-
if ivars = _store[:
|
62
|
+
if ivars = _store[:ivars]
|
63
63
|
_unpack_ivars( self, ivars )
|
64
64
|
end
|
65
65
|
end
|
@@ -80,7 +80,7 @@ module Aqua::Unpack
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def _unpack_initialization( obj )
|
83
|
-
if init = obj[:
|
83
|
+
if init = obj[:init]
|
84
84
|
init_class = init.class
|
85
85
|
if init_class == String
|
86
86
|
init
|
@@ -103,8 +103,15 @@ module Aqua::Unpack
|
|
103
103
|
|
104
104
|
def _unpack_hash( obj )
|
105
105
|
hash = {}
|
106
|
-
obj.each do |
|
107
|
-
value = _unpack_object( value ) unless value.class == String
|
106
|
+
obj.each do |raw_key, value|
|
107
|
+
value = _unpack_object( value ) unless value.class == String
|
108
|
+
if raw_key.match(/\A(:)/)
|
109
|
+
key = raw_key.gsub($1, '').to_sym
|
110
|
+
elsif raw_key.match(/\A\/OBJECT_(\d*)\z/)
|
111
|
+
key = _unpack_object( self._store[:keys][$1.to_i] )
|
112
|
+
else
|
113
|
+
key = raw_key
|
114
|
+
end
|
108
115
|
hash[key] = value
|
109
116
|
end
|
110
117
|
hash
|
@@ -177,7 +184,7 @@ module Aqua::Unpack
|
|
177
184
|
end
|
178
185
|
|
179
186
|
# add the ivars
|
180
|
-
if ivars = store_pack['
|
187
|
+
if ivars = store_pack['ivars']
|
181
188
|
ivars.delete('@table') if obj_class.ancestors.include?( OpenStruct )
|
182
189
|
_unpack_ivars( return_object, ivars )
|
183
190
|
end
|
data/spec/object/pack_spec.rb
CHANGED
@@ -17,6 +17,11 @@ describe Aqua::Pack do
|
|
17
17
|
:log => @log,
|
18
18
|
:password => 'my secret!'
|
19
19
|
)
|
20
|
+
|
21
|
+
def pack_grab_bag( value )
|
22
|
+
@user.grab_bag = value
|
23
|
+
@user._pack[:ivars][:@grab_bag]
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
describe 'packing classes' do
|
@@ -57,7 +62,7 @@ describe Aqua::Pack do
|
|
57
62
|
|
58
63
|
it 'should not pack hidden variables' do
|
59
64
|
@pack = @user._pack
|
60
|
-
@pack[:
|
65
|
+
@pack[:ivars].keys.should_not include("@password")
|
61
66
|
end
|
62
67
|
end
|
63
68
|
|
@@ -87,25 +92,26 @@ describe Aqua::Pack do
|
|
87
92
|
end
|
88
93
|
|
89
94
|
describe 'instance variables, ' do
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
95
|
+
describe 'hashes'
|
96
|
+
it 'should be in a hash-like object with the key :ivars' do
|
97
|
+
@pack[:ivars].should_not be_nil
|
98
|
+
@pack[:ivars].should respond_to(:keys)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should save symbol keys differently that string keys' do
|
102
|
+
@user.name = {:first => 'Kane', 'last' => 'Baccigalupi'}
|
103
|
+
pack = @user._pack
|
104
|
+
pack[:ivars][:@name][:init].keys.sort.should == [':first', 'last']
|
105
|
+
end
|
94
106
|
|
95
|
-
describe 'basic
|
107
|
+
describe 'basic ivars types' do
|
96
108
|
it 'should pack strings as strings' do
|
97
|
-
@pack[:
|
109
|
+
@pack[:ivars][:@username].should == 'kane'
|
98
110
|
end
|
99
111
|
|
100
|
-
it 'should pack an array of strings as a hash with the :class "Array" and :
|
101
|
-
@pack[:
|
112
|
+
it 'should pack an array of strings as a hash with the :class "Array" and :init as the original array' do
|
113
|
+
@pack[:ivars][:@name].should == {'class' => 'Array', 'init' => ['Kane', 'Baccigalupi']}
|
102
114
|
end
|
103
|
-
|
104
|
-
it 'should pack an hash containing only strings/symbols for keys and values, with an initialization value that is that hash and a class key' do
|
105
|
-
@user.name = {:first => 'Kane', :last => 'Baccigalupi'}
|
106
|
-
pack = @user._pack
|
107
|
-
pack[:data][:@name].should == {'class' => 'Hash', 'initialization' => {'first' => 'Kane', 'last' => 'Baccigalupi'} }
|
108
|
-
end
|
109
115
|
end
|
110
116
|
|
111
117
|
describe 'objects: ' do
|
@@ -114,14 +120,14 @@ describe Aqua::Pack do
|
|
114
120
|
|
115
121
|
describe 'Time' do
|
116
122
|
it 'should save as a hash with the class and to_s as the value' do
|
117
|
-
time_hash = @pack[:
|
123
|
+
time_hash = @pack[:ivars][:@created_at]
|
118
124
|
time_hash['class'].should == 'Time'
|
119
|
-
time_hash['
|
125
|
+
time_hash['init'].class.should == String
|
120
126
|
end
|
121
127
|
|
122
128
|
it 'the value should be reconstitutable with Time.parse' do
|
123
129
|
# comparing times directly never works for me. It is probably a micro second issue or something
|
124
|
-
@time.to_s.should == Time.parse( @pack[:
|
130
|
+
@time.to_s.should == Time.parse( @pack[:ivars][:@created_at]['init'] ).to_s
|
125
131
|
end
|
126
132
|
end
|
127
133
|
|
@@ -129,57 +135,79 @@ describe Aqua::Pack do
|
|
129
135
|
it 'should save as a hash with only the class' do
|
130
136
|
@user.grab_bag = true
|
131
137
|
pack = @user._pack
|
132
|
-
pack[:
|
138
|
+
pack[:ivars][:@grab_bag].should == {'class' => 'TrueClass', 'init' => 'true'}
|
133
139
|
|
134
140
|
@user.grab_bag = false
|
135
141
|
pack = @user._pack
|
136
|
-
pack[:
|
142
|
+
pack[:ivars][:@grab_bag].should == {'class' => 'FalseClass', 'init' => 'false'}
|
137
143
|
end
|
138
144
|
end
|
139
145
|
|
140
146
|
describe 'Date' do
|
141
147
|
it 'should save as a hash with the class and to_s as the value' do
|
142
|
-
time_hash = @pack[:
|
148
|
+
time_hash = @pack[:ivars][:@dob]
|
143
149
|
time_hash['class'].should == 'Date'
|
144
|
-
time_hash['
|
150
|
+
time_hash['init'].class.should == String
|
145
151
|
end
|
146
152
|
|
147
153
|
it 'the value should be reconstitutable with Date.parse' do
|
148
|
-
@date.should == Date.parse( @pack[:
|
154
|
+
@date.should == Date.parse( @pack[:ivars][:@dob]['init'] )
|
149
155
|
end
|
150
156
|
end
|
151
157
|
|
152
158
|
describe 'Numbers' do
|
153
|
-
def pack_grab_bag( value )
|
154
|
-
@user.grab_bag = value
|
155
|
-
@user._pack[:data][:@grab_bag]
|
156
|
-
end
|
157
|
-
|
158
159
|
it 'should pack Fixnums with correct class and value' do
|
159
160
|
pack = pack_grab_bag( 42 )
|
160
161
|
pack[:class].should == 'Fixnum'
|
161
|
-
pack[:
|
162
|
+
pack[:init].should == '42'
|
162
163
|
end
|
163
164
|
|
164
165
|
it 'should pack Bignums with correct class and value' do
|
165
166
|
pack = pack_grab_bag( 123456789123456789 )
|
166
167
|
pack[:class].should == 'Bignum'
|
167
|
-
pack[:
|
168
|
+
pack[:init].should == '123456789123456789'
|
168
169
|
end
|
169
170
|
|
170
171
|
it 'should pack Floats with correct class and value' do
|
171
172
|
pack = pack_grab_bag( 3.2 )
|
172
173
|
pack[:class].should == 'Float'
|
173
|
-
pack[:
|
174
|
+
pack[:init].should == '3.2'
|
174
175
|
end
|
175
176
|
|
176
177
|
it 'should pack Rationals with the correct class and values' do
|
177
178
|
pack = pack_grab_bag( Rational( 1, 17 ) )
|
178
179
|
pack[:class].should == 'Rational'
|
179
|
-
pack[:
|
180
|
+
pack[:init].should == ['1', '17']
|
180
181
|
end
|
181
182
|
|
182
|
-
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe 'hashes with object as keys' do
|
186
|
+
it 'should pack an hash containing only strings/symbols for keys and values, with an init value that is that hash and a class key' do
|
187
|
+
@user.name = {'first' => 'Kane', 'last' => 'Baccigalupi'}
|
188
|
+
pack = @user._pack
|
189
|
+
pack[:ivars][:@name].should == {'class' => 'Hash', 'init' => {'first' => 'Kane', 'last' => 'Baccigalupi'} }
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should pack a numeric object key' do
|
193
|
+
pack = pack_grab_bag( {1 => 'first', 2 => 'second'} )
|
194
|
+
keys = pack[:init].keys
|
195
|
+
keys.should include( '/OBJECT_0', '/OBJECT_1' )
|
196
|
+
user_pack = @user.instance_variable_get("@__pack")
|
197
|
+
user_pack[:keys].size.should == 2
|
198
|
+
user_pack[:keys].first['class'].should == 'Fixnum'
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should pack a more complex object as a key' do
|
202
|
+
struct = OpenStruct.new( :gerbil => true )
|
203
|
+
pack = pack_grab_bag( { struct => 'first'} )
|
204
|
+
keys = pack[:init].keys
|
205
|
+
keys.should include( '/OBJECT_0' )
|
206
|
+
user_pack = @user.instance_variable_get("@__pack")
|
207
|
+
user_pack[:keys].size.should == 1
|
208
|
+
user_pack[:keys].first['class'].should == 'OpenStruct'
|
209
|
+
end
|
210
|
+
end
|
183
211
|
|
184
212
|
describe 'embeddable aquatic' do
|
185
213
|
it 'aquatic objects should have packing instructions in the form of #_embed_me' do
|
@@ -191,10 +219,10 @@ describe Aqua::Pack do
|
|
191
219
|
User.configure_aqua( :embed => false )
|
192
220
|
end
|
193
221
|
|
194
|
-
it 'should save their
|
195
|
-
@pack[:
|
196
|
-
@pack[:
|
197
|
-
@pack[:
|
222
|
+
it 'should save their ivars correctly' do
|
223
|
+
@pack[:ivars][:@log].keys.sort.should == ['class', 'ivars', 'keys']
|
224
|
+
@pack[:ivars][:@log]['ivars'].keys.should == ['@created_at', '@message']
|
225
|
+
@pack[:ivars][:@log]['ivars']['@message'].should == "Hello World! This is a log entry"
|
198
226
|
end
|
199
227
|
|
200
228
|
it 'should correctly pack Array derivatives' do
|
@@ -205,10 +233,10 @@ describe Aqua::Pack do
|
|
205
233
|
arrayish = Arrayed['a', 'b', 'c', 'd']
|
206
234
|
arrayish.my_accessor = 'Newt'
|
207
235
|
pack = arrayish._pack
|
208
|
-
pack.keys.sort.should == ['class', '
|
209
|
-
pack['
|
210
|
-
pack['
|
211
|
-
pack['
|
236
|
+
pack.keys.sort.should == ['class', 'init', 'ivars', 'keys']
|
237
|
+
pack['init'].class.should == Array
|
238
|
+
pack['init'].should == ['a', 'b', 'c', 'd']
|
239
|
+
pack['ivars']['@my_accessor'].should == 'Newt'
|
212
240
|
end
|
213
241
|
|
214
242
|
it 'should correctly pack Hash derivative' do
|
@@ -220,10 +248,10 @@ describe Aqua::Pack do
|
|
220
248
|
hashish['1'] = '2'
|
221
249
|
hashish.my_accessor = 'Newt'
|
222
250
|
pack = hashish._pack
|
223
|
-
pack.keys.sort.should == ['class', '
|
224
|
-
pack['
|
225
|
-
pack['
|
226
|
-
pack['
|
251
|
+
pack.keys.sort.should == ['class', 'init', 'ivars', 'keys']
|
252
|
+
pack['init'].class.should == HashWithIndifferentAccess
|
253
|
+
pack['init'].should == {'1' => '2'}
|
254
|
+
pack['ivars']['@my_accessor'].should == 'Newt'
|
227
255
|
end
|
228
256
|
|
229
257
|
end
|
@@ -247,25 +275,25 @@ describe Aqua::Pack do
|
|
247
275
|
before(:each) do
|
248
276
|
@user.grab_bag = @struct
|
249
277
|
pack = @user._pack
|
250
|
-
@grab_bag = pack[:
|
278
|
+
@grab_bag = pack[:ivars][:@grab_bag]
|
251
279
|
end
|
252
280
|
|
253
281
|
it 'the key "class" should map to "OpenStruct"' do
|
254
282
|
@grab_bag['class'].should == 'OpenStruct'
|
255
283
|
end
|
256
284
|
|
257
|
-
it 'the key "
|
258
|
-
@grab_bag['
|
285
|
+
it 'the key "ivars" should have the keys "@table"' do
|
286
|
+
@grab_bag['ivars'].keys.should == ['@table']
|
259
287
|
end
|
260
288
|
|
261
289
|
it 'should initialize with the @table instance variable' do
|
262
|
-
init_keys = @grab_bag['
|
263
|
-
init_keys.should include('cat')
|
264
|
-
init_keys.should include('disaster')
|
265
|
-
init_keys.should include('gerbil')
|
266
|
-
@grab_bag['
|
267
|
-
@grab_bag['
|
268
|
-
@grab_bag['
|
290
|
+
init_keys = @grab_bag['init'].keys
|
291
|
+
init_keys.should include(':cat')
|
292
|
+
init_keys.should include(':disaster')
|
293
|
+
init_keys.should include(':gerbil')
|
294
|
+
@grab_bag['init'][':gerbil'].should == {'class' => 'TrueClass', 'init' => 'true'}
|
295
|
+
@grab_bag['init'][':cat'].should == 'yup, that too!'
|
296
|
+
@grab_bag['init'][':disaster'].should == {'class' => 'Array', 'init' => ['pow', 'blame', 'chase', 'spew']}
|
269
297
|
end
|
270
298
|
end
|
271
299
|
|
@@ -273,15 +301,15 @@ describe Aqua::Pack do
|
|
273
301
|
before(:each) do
|
274
302
|
@user.grab_bag = @grounded
|
275
303
|
pack = @user._pack
|
276
|
-
@grab_bag = pack[:
|
304
|
+
@grab_bag = pack[:ivars][:@grab_bag]
|
277
305
|
end
|
278
306
|
|
279
307
|
it 'the key "class" should map correctly to the class name' do
|
280
308
|
@grab_bag['class'].should == 'Grounded'
|
281
309
|
end
|
282
310
|
|
283
|
-
it 'should have
|
284
|
-
keys = @grab_bag[:
|
311
|
+
it 'should have ivars keys for all the ivars' do
|
312
|
+
keys = @grab_bag[:ivars].keys
|
285
313
|
keys.should include('@openly_structured')
|
286
314
|
keys.should include('@hash_up')
|
287
315
|
keys.should include('@arraynged')
|
@@ -289,7 +317,7 @@ describe Aqua::Pack do
|
|
289
317
|
|
290
318
|
it 'should correctly display the nested OpenStruct' do
|
291
319
|
user_2 = User.new(:grab_bag => @struct) # this has already been tested in the set above
|
292
|
-
user_2._pack[:
|
320
|
+
user_2._pack[:ivars][:@grab_bag].should == @grab_bag[:ivars][:@openly_structured]
|
293
321
|
end
|
294
322
|
end
|
295
323
|
|
@@ -305,7 +333,7 @@ describe Aqua::Pack do
|
|
305
333
|
@strange_array.udder # sets an instance variable
|
306
334
|
@user.grab_bag = @strange_array
|
307
335
|
pack = @user._pack
|
308
|
-
@grab_bag = pack[:
|
336
|
+
@grab_bag = pack[:ivars][:@grab_bag]
|
309
337
|
end
|
310
338
|
|
311
339
|
it 'should correctly map the class name' do
|
@@ -313,19 +341,19 @@ describe Aqua::Pack do
|
|
313
341
|
end
|
314
342
|
|
315
343
|
it 'should store the instance variables' do
|
316
|
-
@grab_bag[:
|
344
|
+
@grab_bag[:ivars].keys.should == ['@udder']
|
317
345
|
end
|
318
346
|
|
319
347
|
it 'should store the simple array values' do
|
320
|
-
@grab_bag[:
|
321
|
-
@grab_bag[:
|
322
|
-
@grab_bag[:
|
323
|
-
@grab_bag[:
|
348
|
+
@grab_bag[:init].should_not be_nil
|
349
|
+
@grab_bag[:init].class.should == Array
|
350
|
+
@grab_bag[:init].should include('cat')
|
351
|
+
@grab_bag[:init].should include('octopus')
|
324
352
|
end
|
325
353
|
|
326
354
|
it 'should store the more complex array values correctly' do
|
327
355
|
user_2 = User.new(:grab_bag => @struct) # this has already been tested in the set above
|
328
|
-
user_2._pack[:
|
356
|
+
user_2._pack[:ivars][:@grab_bag].should == @grab_bag[:init].last
|
329
357
|
end
|
330
358
|
end
|
331
359
|
|
@@ -345,7 +373,7 @@ describe Aqua::Pack do
|
|
345
373
|
@hash_derivative.yum # sets an instance variable
|
346
374
|
@user.grab_bag = @hash_derivative
|
347
375
|
pack = @user._pack
|
348
|
-
@grab_bag = pack[:
|
376
|
+
@grab_bag = pack[:ivars][:@grab_bag]
|
349
377
|
end
|
350
378
|
|
351
379
|
it 'should correctly map the class name' do
|
@@ -353,21 +381,21 @@ describe Aqua::Pack do
|
|
353
381
|
end
|
354
382
|
|
355
383
|
it 'should store the instance variables' do
|
356
|
-
@grab_bag[:
|
384
|
+
@grab_bag[:ivars].keys.should == ['@yum']
|
357
385
|
end
|
358
386
|
|
359
387
|
it 'should store the simple hash values' do
|
360
|
-
@grab_bag[:
|
361
|
-
@grab_bag[:
|
388
|
+
@grab_bag[:init].should_not be_nil
|
389
|
+
@grab_bag[:init].class.should == HashWithIndifferentAccess
|
362
390
|
|
363
|
-
@grab_bag[:
|
364
|
-
@grab_bag[:
|
365
|
-
@grab_bag[:
|
391
|
+
@grab_bag[:init].keys.should include('ingredients')
|
392
|
+
@grab_bag[:init].keys.should include('healthometer')
|
393
|
+
@grab_bag[:init].keys.should include('random_struct')
|
366
394
|
end
|
367
395
|
|
368
396
|
it 'should store the more complex hash values correctly' do
|
369
397
|
user_2 = User.new(:grab_bag => @struct) # this has already been tested in the set above
|
370
|
-
user_2._pack[:
|
398
|
+
user_2._pack[:ivars][:@grab_bag].should == @grab_bag[:init][:random_struct]
|
371
399
|
end
|
372
400
|
end
|
373
401
|
end
|
data/spec/object/unpack_spec.rb
CHANGED
@@ -36,7 +36,7 @@ describe Aqua::Unpack do
|
|
36
36
|
end
|
37
37
|
|
38
38
|
describe 'unpacking to a new object' do
|
39
|
-
describe '
|
39
|
+
describe 'init' do
|
40
40
|
it 'should initialize an Aquatic object' do
|
41
41
|
user = User.load( @user.id )
|
42
42
|
user.class.should == User
|
@@ -59,7 +59,7 @@ describe Aqua::Unpack do
|
|
59
59
|
arrayish_2.class.should == Arrayed
|
60
60
|
end
|
61
61
|
|
62
|
-
it 'should load
|
62
|
+
it 'should load init values into an aquatic Array derivative' do
|
63
63
|
arrayish_2 = Arrayed.load( @id )
|
64
64
|
arrayish_2.first.should == 'a'
|
65
65
|
end
|
@@ -82,7 +82,7 @@ describe Aqua::Unpack do
|
|
82
82
|
Hashed.load( @id ).class.should == Hashed
|
83
83
|
end
|
84
84
|
|
85
|
-
it 'should load
|
85
|
+
it 'should load init values into an aquatic Hash derivative' do
|
86
86
|
hashish = Hashed.load( @id )
|
87
87
|
hashish['1'].should == '2'
|
88
88
|
end
|
@@ -188,7 +188,29 @@ describe Aqua::Unpack do
|
|
188
188
|
@user.commit!
|
189
189
|
user = User.load(@user.id)
|
190
190
|
user.grab_bag.should == @user.grab_bag
|
191
|
-
end
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should unpack symbol keys differently than unpacking string keys' do
|
194
|
+
@user.grab_bag = {'first' => '1', :second => '2'}
|
195
|
+
@user.commit!
|
196
|
+
user = User.load(@user.id)
|
197
|
+
user.grab_bag.keys.should include('first', :second)
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'should unpack a numeric object key' do
|
201
|
+
@user.grab_bag = {1 => 'first', 2 => 'second'}
|
202
|
+
@user.commit!
|
203
|
+
user = User.load(@user.id)
|
204
|
+
user.grab_bag.keys.should include( 1, 2 )
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'should unpack a more complex object as a key' do
|
208
|
+
struct = OpenStruct.new( :gerbil => true )
|
209
|
+
@user.grab_bag = { struct => 'first' }
|
210
|
+
@user.commit!
|
211
|
+
user = User.load(@user.id)
|
212
|
+
user.grab_bag.keys.should include( struct )
|
213
|
+
end
|
192
214
|
|
193
215
|
it 'should unpack a Hash with non-string values' do
|
194
216
|
@user.grab_bag = {'1' => 2}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: baccigalupi-aqua
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kane Baccigalupi
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -114,7 +114,6 @@ files:
|
|
114
114
|
- utils/console
|
115
115
|
has_rdoc: true
|
116
116
|
homepage: http://github.com/baccigalupi/aqua
|
117
|
-
licenses:
|
118
117
|
post_install_message:
|
119
118
|
rdoc_options:
|
120
119
|
- --charset=UTF-8
|
@@ -135,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
134
|
requirements: []
|
136
135
|
|
137
136
|
rubyforge_project:
|
138
|
-
rubygems_version: 1.
|
137
|
+
rubygems_version: 1.2.0
|
139
138
|
signing_key:
|
140
139
|
specification_version: 2
|
141
140
|
summary: "Aqua: A Ruby Object Database ... just add water (and CouchDB)"
|