rod 0.6.2 → 0.6.3
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/.travis.yml +1 -0
- data/README.rdoc +10 -9
- data/Rakefile +15 -5
- data/changelog.txt +18 -0
- data/features/append.feature +0 -2
- data/features/basic.feature +7 -7
- data/features/collection_proxy.feature +140 -0
- data/features/flat_indexing.feature +9 -8
- data/features/{fred.feature → persistence.feature} +5 -8
- data/features/{assoc_indexing.feature → relationship_indexing.feature} +36 -0
- data/features/segmented_indexing.feature +6 -6
- data/features/steps/collection_proxy.rb +89 -0
- data/features/steps/model.rb +15 -3
- data/features/steps/rod.rb +1 -1
- data/features/support/mocha.rb +16 -0
- data/features/update.feature +263 -0
- data/lib/rod.rb +10 -2
- data/lib/rod/abstract_database.rb +49 -111
- data/lib/rod/abstract_model.rb +26 -6
- data/lib/rod/collection_proxy.rb +235 -34
- data/lib/rod/constants.rb +1 -1
- data/lib/rod/database.rb +5 -6
- data/lib/rod/exception.rb +1 -1
- data/lib/rod/index/base.rb +97 -0
- data/lib/rod/index/flat_index.rb +72 -0
- data/lib/rod/index/segmented_index.rb +100 -0
- data/lib/rod/model.rb +172 -185
- data/lib/rod/reference_updater.rb +85 -0
- data/lib/rod/utils.rb +29 -0
- data/rod.gemspec +4 -1
- data/tests/migration_create.rb +33 -12
- data/tests/migration_migrate.rb +24 -7
- data/tests/migration_model1.rb +5 -0
- data/tests/migration_model2.rb +36 -0
- data/tests/migration_verify.rb +49 -42
- data/tests/missing_class_create.rb +21 -0
- data/tests/missing_class_verify.rb +20 -0
- data/tests/properties_order_create.rb +16 -0
- data/tests/properties_order_verify.rb +17 -0
- data/tests/unit/abstract_database.rb +13 -0
- data/tests/unit/model_tests.rb +3 -3
- data/utils/convert_index.rb +1 -1
- metadata +62 -18
- data/lib/rod/segmented_index.rb +0 -85
@@ -0,0 +1,16 @@
|
|
1
|
+
$:.unshift("lib")
|
2
|
+
require 'rod'
|
3
|
+
|
4
|
+
class User < Rod::Model
|
5
|
+
database_class Rod::Database
|
6
|
+
field :name, :string
|
7
|
+
field :surname, :string
|
8
|
+
end
|
9
|
+
|
10
|
+
Rod::Database.development_mode = true
|
11
|
+
|
12
|
+
Rod::Database.instance.create_database("tmp/properties_order")
|
13
|
+
user = User.new(:name => "John",:surname => "Smith")
|
14
|
+
user.store
|
15
|
+
Rod::Database.instance.close_database
|
16
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
$:.unshift("lib")
|
2
|
+
require 'rod'
|
3
|
+
require 'rspec/expectations'
|
4
|
+
include RSpec::Matchers
|
5
|
+
|
6
|
+
# This class have properties in oposite order as the class in the
|
7
|
+
# properties_order_create file.
|
8
|
+
class User < Rod::Model
|
9
|
+
database_class Rod::Database
|
10
|
+
field :surname, :string
|
11
|
+
field :name, :string
|
12
|
+
end
|
13
|
+
|
14
|
+
Rod::Database.development_mode = true
|
15
|
+
|
16
|
+
(lambda {Rod::Database.instance.open_database("tmp/properties_order")}).
|
17
|
+
should raise_error(Rod::IncompatibleVersion)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
$:.unshift("lib")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'rod'
|
4
|
+
|
5
|
+
class AbstractDatabaseTest < Test::Unit::TestCase
|
6
|
+
def test_canonicalize_path
|
7
|
+
db = Rod::AbstractDatabase.instance
|
8
|
+
path = "/abc"
|
9
|
+
assert_equal(db.send(:canonicalize_path,path),path + "/")
|
10
|
+
path = "/abc/"
|
11
|
+
assert_equal(db.send(:canonicalize_path,path),path)
|
12
|
+
end
|
13
|
+
end
|
data/tests/unit/model_tests.rb
CHANGED
@@ -13,7 +13,7 @@ module RodTest
|
|
13
13
|
|
14
14
|
class AStruct < Model
|
15
15
|
field :a1, :integer
|
16
|
-
field :a2, :ulong, :index =>
|
16
|
+
field :a2, :ulong, :index => :flat
|
17
17
|
has_many :b_structs, :class_name => "RodTest::BStruct"
|
18
18
|
|
19
19
|
def to_s
|
@@ -51,7 +51,7 @@ module RodTest
|
|
51
51
|
assert AStruct.fields[:a2].has_key?(:type)
|
52
52
|
assert AStruct.fields[:a2][:type] == :ulong
|
53
53
|
assert AStruct.fields[:a2].has_key?(:index)
|
54
|
-
assert AStruct.fields[:a2][:index] ==
|
54
|
+
assert AStruct.fields[:a2][:index] == :flat
|
55
55
|
|
56
56
|
assert AStruct.fields.has_key?("rod_id")
|
57
57
|
|
@@ -81,7 +81,7 @@ module RodTest
|
|
81
81
|
|
82
82
|
assert a1.b_structs_count == a1.b_structs.count
|
83
83
|
a1.b_structs = [b1, b2]
|
84
|
-
assert a1.b_structs == [b1, b2]
|
84
|
+
assert a1.b_structs.to_a == [b1, b2]
|
85
85
|
assert a1.b_structs_count == a1.b_structs.count
|
86
86
|
|
87
87
|
b1.b = "tead-only database"
|
data/utils/convert_index.rb
CHANGED
@@ -25,7 +25,7 @@ klass = class_name.split("::").inject(Object) do |mod,name|
|
|
25
25
|
klass
|
26
26
|
end
|
27
27
|
end
|
28
|
-
index =
|
28
|
+
index = class_name.constantize.index_for(property,{:index => :flat})
|
29
29
|
klass.instance_variable_set("@#{property}_index",index)
|
30
30
|
db.write_index(klass,property,{:index => :segmented, :convert => true})
|
31
31
|
#Rod::Database.instance.close_database
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: rod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.6.
|
5
|
+
version: 0.6.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Aleksander Pohl
|
@@ -10,8 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
14
|
-
default_executable:
|
13
|
+
date: 2011-09-09 00:00:00 Z
|
15
14
|
dependencies:
|
16
15
|
- !ruby/object:Gem::Dependency
|
17
16
|
name: RubyInline
|
@@ -21,7 +20,7 @@ dependencies:
|
|
21
20
|
requirements:
|
22
21
|
- - ">="
|
23
22
|
- !ruby/object:Gem::Version
|
24
|
-
version: 3.
|
23
|
+
version: 3.10.0
|
25
24
|
- - <
|
26
25
|
- !ruby/object:Gem::Version
|
27
26
|
version: 4.0.0
|
@@ -56,9 +55,23 @@ dependencies:
|
|
56
55
|
type: :runtime
|
57
56
|
version_requirements: *id003
|
58
57
|
- !ruby/object:Gem::Dependency
|
59
|
-
name:
|
58
|
+
name: bsearch
|
60
59
|
prerelease: false
|
61
60
|
requirement: &id004 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: 1.5.0
|
66
|
+
- - <
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 1.6.0
|
69
|
+
type: :runtime
|
70
|
+
version_requirements: *id004
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: mocha
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
62
75
|
none: false
|
63
76
|
requirements:
|
64
77
|
- - ">="
|
@@ -68,22 +81,22 @@ dependencies:
|
|
68
81
|
- !ruby/object:Gem::Version
|
69
82
|
version: 1.0.0
|
70
83
|
type: :development
|
71
|
-
version_requirements: *
|
84
|
+
version_requirements: *id005
|
72
85
|
- !ruby/object:Gem::Dependency
|
73
86
|
name: cucumber
|
74
87
|
prerelease: false
|
75
|
-
requirement: &
|
88
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
76
89
|
none: false
|
77
90
|
requirements:
|
78
91
|
- - ~>
|
79
92
|
- !ruby/object:Gem::Version
|
80
93
|
version: 1.0.0
|
81
94
|
type: :development
|
82
|
-
version_requirements: *
|
95
|
+
version_requirements: *id006
|
83
96
|
- !ruby/object:Gem::Dependency
|
84
97
|
name: rspec
|
85
98
|
prerelease: false
|
86
|
-
requirement: &
|
99
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
87
100
|
none: false
|
88
101
|
requirements:
|
89
102
|
- - ">="
|
@@ -93,7 +106,21 @@ dependencies:
|
|
93
106
|
- !ruby/object:Gem::Version
|
94
107
|
version: 2.3.0
|
95
108
|
type: :development
|
96
|
-
version_requirements: *
|
109
|
+
version_requirements: *id007
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: rake
|
112
|
+
prerelease: false
|
113
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 0.9.0
|
119
|
+
- - <
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: 1.0.0
|
122
|
+
type: :development
|
123
|
+
version_requirements: *id008
|
97
124
|
description: Ruby object database is designed for large amount of data, whose structure rarely changes.
|
98
125
|
email:
|
99
126
|
- apohllo@o2.pl
|
@@ -105,24 +132,29 @@ extra_rdoc_files: []
|
|
105
132
|
|
106
133
|
files:
|
107
134
|
- .gitignore
|
135
|
+
- .travis.yml
|
108
136
|
- Gemfile
|
109
137
|
- README.rdoc
|
110
138
|
- Rakefile
|
111
139
|
- changelog.txt
|
112
140
|
- contributors.txt
|
113
141
|
- features/append.feature
|
114
|
-
- features/assoc_indexing.feature
|
115
142
|
- features/basic.feature
|
116
143
|
- features/collection.feature
|
144
|
+
- features/collection_proxy.feature
|
117
145
|
- features/flat_indexing.feature
|
118
|
-
- features/fred.feature
|
119
146
|
- features/inheritence.feature
|
120
147
|
- features/muliple_db.feature
|
148
|
+
- features/persistence.feature
|
149
|
+
- features/relationship_indexing.feature
|
121
150
|
- features/relationships.feature
|
122
151
|
- features/segmented_indexing.feature
|
152
|
+
- features/steps/collection_proxy.rb
|
123
153
|
- features/steps/model.rb
|
124
154
|
- features/steps/rod.rb
|
125
155
|
- features/steps/test_helper.rb
|
156
|
+
- features/support/mocha.rb
|
157
|
+
- features/update.feature
|
126
158
|
- lib/rod.rb
|
127
159
|
- lib/rod/abstract_database.rb
|
128
160
|
- lib/rod/abstract_model.rb
|
@@ -131,11 +163,15 @@ files:
|
|
131
163
|
- lib/rod/constants.rb
|
132
164
|
- lib/rod/database.rb
|
133
165
|
- lib/rod/exception.rb
|
166
|
+
- lib/rod/index/base.rb
|
167
|
+
- lib/rod/index/flat_index.rb
|
168
|
+
- lib/rod/index/segmented_index.rb
|
134
169
|
- lib/rod/join_element.rb
|
135
170
|
- lib/rod/model.rb
|
136
|
-
- lib/rod/
|
171
|
+
- lib/rod/reference_updater.rb
|
137
172
|
- lib/rod/string_element.rb
|
138
173
|
- lib/rod/string_ex.rb
|
174
|
+
- lib/rod/utils.rb
|
139
175
|
- rod.gemspec
|
140
176
|
- tests/check_strings.rb
|
141
177
|
- tests/class_compatibility_create.rb
|
@@ -153,16 +189,20 @@ files:
|
|
153
189
|
- tests/migration_model1.rb
|
154
190
|
- tests/migration_model2.rb
|
155
191
|
- tests/migration_verify.rb
|
192
|
+
- tests/missing_class_create.rb
|
193
|
+
- tests/missing_class_verify.rb
|
156
194
|
- tests/mock_tests.rb
|
195
|
+
- tests/properties_order_create.rb
|
196
|
+
- tests/properties_order_verify.rb
|
157
197
|
- tests/read_on_create.rb
|
158
198
|
- tests/save_struct.rb
|
159
199
|
- tests/structures.rb
|
200
|
+
- tests/unit/abstract_database.rb
|
160
201
|
- tests/unit/database.rb
|
161
202
|
- tests/unit/model.rb
|
162
203
|
- tests/unit/model_tests.rb
|
163
204
|
- tests/validate_read_on_create.rb
|
164
205
|
- utils/convert_index.rb
|
165
|
-
has_rdoc: true
|
166
206
|
homepage: http://github.com/apohllo/rod
|
167
207
|
licenses: []
|
168
208
|
|
@@ -177,7 +217,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
177
217
|
requirements:
|
178
218
|
- - ">="
|
179
219
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
220
|
+
version: 1.9.2
|
181
221
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
182
222
|
none: false
|
183
223
|
requirements:
|
@@ -187,21 +227,25 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
187
227
|
requirements: []
|
188
228
|
|
189
229
|
rubyforge_project: rod
|
190
|
-
rubygems_version: 1.5
|
230
|
+
rubygems_version: 1.8.5
|
191
231
|
signing_key:
|
192
232
|
specification_version: 3
|
193
233
|
summary: Ruby object database
|
194
234
|
test_files:
|
195
235
|
- features/append.feature
|
196
|
-
- features/assoc_indexing.feature
|
197
236
|
- features/basic.feature
|
198
237
|
- features/collection.feature
|
238
|
+
- features/collection_proxy.feature
|
199
239
|
- features/flat_indexing.feature
|
200
|
-
- features/fred.feature
|
201
240
|
- features/inheritence.feature
|
202
241
|
- features/muliple_db.feature
|
242
|
+
- features/persistence.feature
|
243
|
+
- features/relationship_indexing.feature
|
203
244
|
- features/relationships.feature
|
204
245
|
- features/segmented_indexing.feature
|
246
|
+
- features/steps/collection_proxy.rb
|
205
247
|
- features/steps/model.rb
|
206
248
|
- features/steps/rod.rb
|
207
249
|
- features/steps/test_helper.rb
|
250
|
+
- features/support/mocha.rb
|
251
|
+
- features/update.feature
|
data/lib/rod/segmented_index.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
module Rod
|
2
|
-
# Class implementing segmented index, i.e. an index which allows for
|
3
|
-
# lazy loading of its pieces.
|
4
|
-
class SegmentedIndex
|
5
|
-
# Creats the index with given +path+ and number of buckets (+buckets_count+).
|
6
|
-
def initialize(path,buckets_count=1001)
|
7
|
-
@path = path
|
8
|
-
@buckets_count = buckets_count
|
9
|
-
@buckets_ceil = Math::log2(buckets_count).ceil
|
10
|
-
@buckets = {}
|
11
|
-
end
|
12
|
-
|
13
|
-
# Stores the index at @path. Assumes the path exists.
|
14
|
-
def save
|
15
|
-
unless File.exist?(@path)
|
16
|
-
Dir.mkdir(@path)
|
17
|
-
end
|
18
|
-
@buckets.each do |bucket_number,hash|
|
19
|
-
File.open(path_for(bucket_number),"w") do |out|
|
20
|
-
out.puts(Marshal.dump(hash))
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# Return value for the key.
|
26
|
-
def [](key)
|
27
|
-
bucket_number = bucket_for(key)
|
28
|
-
load_bucket(bucket_number) unless @buckets[bucket_number]
|
29
|
-
@buckets[bucket_number][key]
|
30
|
-
end
|
31
|
-
|
32
|
-
# Set the value for the key.
|
33
|
-
def []=(key,value)
|
34
|
-
bucket_number = bucket_for(key)
|
35
|
-
load_bucket(bucket_number) unless @buckets[bucket_number]
|
36
|
-
@buckets[bucket_number][key] = value
|
37
|
-
end
|
38
|
-
|
39
|
-
def each
|
40
|
-
if block_given?
|
41
|
-
@buckets.each do |bucket_number,hash|
|
42
|
-
hash.each do |key,value|
|
43
|
-
yield key, value
|
44
|
-
end
|
45
|
-
end
|
46
|
-
else
|
47
|
-
enum_for(:each)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
def bucket_for(key)
|
53
|
-
case key
|
54
|
-
when NilClass
|
55
|
-
1 % @buckets_count
|
56
|
-
when TrueClass
|
57
|
-
2 % @buckets_count
|
58
|
-
when FalseClass
|
59
|
-
3 % @buckets_count
|
60
|
-
when String
|
61
|
-
key.sum(@buckets_ceil) % @buckets_count
|
62
|
-
when Integer
|
63
|
-
key % @buckets_count
|
64
|
-
when Float
|
65
|
-
(key.numerator - key.denominator) % @buckets_count
|
66
|
-
else
|
67
|
-
raise RodException.new("Object of type '#{key.class}' not supported as a key of segmented index!")
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def path_for(bucket_number)
|
72
|
-
"#{@path}#{bucket_number}.idx"
|
73
|
-
end
|
74
|
-
|
75
|
-
def load_bucket(bucket_number)
|
76
|
-
if File.exist?(path_for(bucket_number))
|
77
|
-
File.open(path_for(bucket_number)) do |input|
|
78
|
-
@buckets[bucket_number] = Marshal.load(input)
|
79
|
-
end
|
80
|
-
else
|
81
|
-
@buckets[bucket_number] = {}
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|