rod 0.6.1 → 0.6.2
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/.gitignore +7 -0
- data/{README → README.rdoc} +33 -2
- data/Rakefile +7 -2
- data/changelog.txt +13 -0
- data/contributors.txt +2 -0
- data/features/append.feature +221 -0
- data/features/assoc_indexing.feature +66 -0
- data/features/basic.feature +199 -0
- data/features/collection.feature +171 -0
- data/features/flat_indexing.feature +140 -0
- data/features/fred.feature +49 -0
- data/features/inheritence.feature +211 -0
- data/features/muliple_db.feature +113 -0
- data/features/relationships.feature +195 -0
- data/features/segmented_indexing.feature +172 -0
- data/features/steps/model.rb +386 -0
- data/features/steps/rod.rb +71 -0
- data/features/steps/test_helper.rb +5 -0
- data/lib/rod/abstract_database.rb +17 -5
- data/lib/rod/constants.rb +1 -1
- data/lib/rod/database.rb +95 -74
- data/lib/rod/join_element.rb +6 -2
- data/lib/rod/model.rb +37 -9
- data/rod.gemspec +15 -12
- data/tests/check_strings.rb +10 -0
- data/tests/class_compatibility_create.rb +14 -0
- data/tests/class_compatibility_verify.rb +18 -0
- data/tests/eff1_test.rb +60 -0
- data/tests/eff2_test.rb +61 -0
- data/tests/full_runs.rb +68 -0
- data/tests/generate_classes_create.rb +25 -0
- data/tests/generate_classes_model.rb +23 -0
- data/tests/generate_classes_rewrite.rb +7 -0
- data/tests/generate_classes_verify.rb +46 -0
- data/tests/load_struct.rb +24 -0
- data/tests/migration_create.rb +25 -0
- data/tests/migration_migrate.rb +22 -0
- data/tests/migration_model1.rb +23 -0
- data/tests/migration_model2.rb +27 -0
- data/tests/migration_verify.rb +56 -0
- data/tests/mock_tests.rb +128 -0
- data/tests/read_on_create.rb +45 -0
- data/tests/save_struct.rb +49 -0
- data/tests/structures.rb +52 -0
- data/tests/unit/database.rb +60 -0
- data/tests/unit/model.rb +36 -0
- data/tests/unit/model_tests.rb +116 -0
- data/tests/validate_read_on_create.rb +12 -0
- data/utils/convert_index.rb +31 -0
- metadata +77 -28
data/tests/unit/model.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
$:.unshift("tests")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'structures'
|
4
|
+
|
5
|
+
class ModelTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
RodTest::Database.instance.open_database("tmp/abc")
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
RodTest::Database.instance.close_database()
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_referential_integrity
|
15
|
+
struct1 = RodTest::MyStruct.find_by_title("title_0")
|
16
|
+
assert(not(struct1.nil?))
|
17
|
+
struct2 = RodTest::MyStruct.find_by_title("title_0")
|
18
|
+
assert(not(struct2.nil?))
|
19
|
+
assert(struct1.object_id == struct2.object_id,
|
20
|
+
"Referential integrity not working for find_by " +
|
21
|
+
"#{struct1.object_id}:#{struct2.object_id}")
|
22
|
+
|
23
|
+
struct3 = RodTest::YourStruct[0]
|
24
|
+
assert(not(struct3.nil?))
|
25
|
+
struct4 = RodTest::HisStruct[0]
|
26
|
+
assert(not(struct4.nil?))
|
27
|
+
assert(struct3.his_structs[0].object_id == struct4.object_id,
|
28
|
+
"Referential integrity not working for has_many " +
|
29
|
+
"#{struct3.his_structs[0].object_id}:#{struct4.object_id}")
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_print_system_error
|
33
|
+
puts "Test system error:"
|
34
|
+
RodTest::Database.instance.print_system_error
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
$:.unshift("lib")
|
2
|
+
require 'rod'
|
3
|
+
require 'test/unit'
|
4
|
+
|
5
|
+
module RodTest
|
6
|
+
class Database < Rod::Database
|
7
|
+
end
|
8
|
+
|
9
|
+
class Model < Rod::Model
|
10
|
+
attr_accessor :used
|
11
|
+
database_class Database
|
12
|
+
end
|
13
|
+
|
14
|
+
class AStruct < Model
|
15
|
+
field :a1, :integer
|
16
|
+
field :a2, :ulong, :index => true
|
17
|
+
has_many :b_structs, :class_name => "RodTest::BStruct"
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
"#{self.a1}, #{self.a2}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class BStruct < Model
|
25
|
+
field :b, :string
|
26
|
+
has_one :a_struct
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
"#{self.b}"
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
class ModuleTests < Test::Unit::TestCase
|
35
|
+
def setup
|
36
|
+
Database.instance.create_database("tmp/test_stored_instances")
|
37
|
+
end
|
38
|
+
|
39
|
+
def teardown
|
40
|
+
Database.instance.close_database
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_reflection
|
44
|
+
# A
|
45
|
+
|
46
|
+
assert AStruct.fields.has_key?(:a1)
|
47
|
+
assert AStruct.fields[:a1].has_key?(:type)
|
48
|
+
assert AStruct.fields[:a1][:type] == :integer
|
49
|
+
|
50
|
+
assert AStruct.fields.has_key?(:a2)
|
51
|
+
assert AStruct.fields[:a2].has_key?(:type)
|
52
|
+
assert AStruct.fields[:a2][:type] == :ulong
|
53
|
+
assert AStruct.fields[:a2].has_key?(:index)
|
54
|
+
assert AStruct.fields[:a2][:index] == true
|
55
|
+
|
56
|
+
assert AStruct.fields.has_key?("rod_id")
|
57
|
+
|
58
|
+
assert AStruct.plural_associations.has_key?(:b_structs)
|
59
|
+
assert AStruct.plural_associations[:b_structs].has_key?(:class_name)
|
60
|
+
assert AStruct.plural_associations[:b_structs][:class_name] == "RodTest::BStruct"
|
61
|
+
|
62
|
+
# B
|
63
|
+
assert BStruct.singular_associations.has_key?(:a_struct)
|
64
|
+
|
65
|
+
assert BStruct.fields.has_key?("rod_id")
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_instances
|
69
|
+
a1 = AStruct.new
|
70
|
+
a2 = AStruct.new
|
71
|
+
a3 = AStruct.new
|
72
|
+
|
73
|
+
b1 = BStruct.new
|
74
|
+
b2 = BStruct.new
|
75
|
+
|
76
|
+
# these are generated, non-trivial accessors, so they need to be tested
|
77
|
+
a1.a1 = 2
|
78
|
+
a1.a2 = 2000000000
|
79
|
+
assert a1.a1 == 2
|
80
|
+
assert a1.a2 == 2000000000
|
81
|
+
|
82
|
+
assert a1.b_structs_count == a1.b_structs.count
|
83
|
+
a1.b_structs = [b1, b2]
|
84
|
+
assert a1.b_structs == [b1, b2]
|
85
|
+
assert a1.b_structs_count == a1.b_structs.count
|
86
|
+
|
87
|
+
b1.b = "tead-only database"
|
88
|
+
assert b1.b == "tead-only database"
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_stored_instances
|
92
|
+
|
93
|
+
a1 = AStruct.new
|
94
|
+
a2 = AStruct.new
|
95
|
+
a3 = AStruct.new
|
96
|
+
|
97
|
+
b1 = BStruct.new
|
98
|
+
b2 = BStruct.new
|
99
|
+
|
100
|
+
a1.b_structs = [b1, b2]
|
101
|
+
a2.b_structs = [b1]
|
102
|
+
a3.b_structs = []
|
103
|
+
|
104
|
+
a1.store
|
105
|
+
a2.store
|
106
|
+
a3.store
|
107
|
+
|
108
|
+
b1.store
|
109
|
+
b2.store
|
110
|
+
|
111
|
+
assert a1.b_structs_count == a1.b_structs.count
|
112
|
+
#p "AStruct.count: #{AStruct.count}" <- should throw a more relevant exception
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
def validate(index,struct)
|
2
|
+
if struct.count != index
|
3
|
+
raise "Invalid MyStruct#count #{struct.count}, should be #{index}"
|
4
|
+
end
|
5
|
+
if struct.title != "Title_#{index}"
|
6
|
+
raise "Invalid MyStruct#title #{struct.title}, shoud be 'Title_#{index}"
|
7
|
+
end
|
8
|
+
raise "Missing MyStruct#your_struct" if struct.your_struct.nil?
|
9
|
+
raise "Invalid YourStruct#counter" if struct.your_struct.counter != index
|
10
|
+
end
|
11
|
+
|
12
|
+
MAGNITUDO = 1000
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rod'
|
2
|
+
|
3
|
+
if ARGV.size != 3
|
4
|
+
puts "convert_index.rb db_path class_name property"
|
5
|
+
puts
|
6
|
+
puts " Converts flat to segmented index"
|
7
|
+
puts " db_path - the path to the database"
|
8
|
+
puts " class_name - the name of the class with the indexed property"
|
9
|
+
puts " property - the name of the indexed property"
|
10
|
+
puts
|
11
|
+
puts " Don't forget to change the definition of the class after the conversion"
|
12
|
+
exit
|
13
|
+
end
|
14
|
+
|
15
|
+
db_path, class_name, property = ARGV
|
16
|
+
|
17
|
+
Rod::Database.instance.open_database(db_path,false)
|
18
|
+
db = Rod::Database.instance
|
19
|
+
klass = class_name.split("::").inject(Object) do |mod,name|
|
20
|
+
begin
|
21
|
+
mod.const_get(name)
|
22
|
+
rescue
|
23
|
+
klass = Class.new(Rod::Model)
|
24
|
+
mod.const_set(name,klass)
|
25
|
+
klass
|
26
|
+
end
|
27
|
+
end
|
28
|
+
index = db.read_index(class_name.constantize,property,{:index => :flat})
|
29
|
+
klass.instance_variable_set("@#{property}_index",index)
|
30
|
+
db.write_index(klass,property,{:index => :segmented, :convert => true})
|
31
|
+
#Rod::Database.instance.close_database
|
metadata
CHANGED
@@ -2,17 +2,15 @@
|
|
2
2
|
name: rod
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.6.
|
5
|
+
version: 0.6.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Aleksander Pohl
|
9
|
-
- Piotr Gurgul
|
10
|
-
- Marcin Sieniek
|
11
9
|
autorequire:
|
12
10
|
bindir: bin
|
13
11
|
cert_chain: []
|
14
12
|
|
15
|
-
date: 2011-
|
13
|
+
date: 2011-07-04 00:00:00 +02:00
|
16
14
|
default_executable:
|
17
15
|
dependencies:
|
18
16
|
- !ruby/object:Gem::Dependency
|
@@ -77,12 +75,9 @@ dependencies:
|
|
77
75
|
requirement: &id005 !ruby/object:Gem::Requirement
|
78
76
|
none: false
|
79
77
|
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.9.4
|
83
|
-
- - <
|
78
|
+
- - ~>
|
84
79
|
- !ruby/object:Gem::Version
|
85
|
-
version: 0.
|
80
|
+
version: 1.0.0
|
86
81
|
type: :development
|
87
82
|
version_requirements: *id005
|
88
83
|
- !ruby/object:Gem::Dependency
|
@@ -100,7 +95,8 @@ dependencies:
|
|
100
95
|
type: :development
|
101
96
|
version_requirements: *id006
|
102
97
|
description: Ruby object database is designed for large amount of data, whose structure rarely changes.
|
103
|
-
email:
|
98
|
+
email:
|
99
|
+
- apohllo@o2.pl
|
104
100
|
executables: []
|
105
101
|
|
106
102
|
extensions: []
|
@@ -108,31 +104,72 @@ extensions: []
|
|
108
104
|
extra_rdoc_files: []
|
109
105
|
|
110
106
|
files:
|
107
|
+
- .gitignore
|
108
|
+
- Gemfile
|
109
|
+
- README.rdoc
|
111
110
|
- Rakefile
|
112
|
-
- rod.gemspec
|
113
|
-
- lib/rod.rb
|
114
|
-
- README
|
115
111
|
- changelog.txt
|
116
|
-
-
|
117
|
-
-
|
118
|
-
-
|
119
|
-
-
|
120
|
-
-
|
112
|
+
- contributors.txt
|
113
|
+
- features/append.feature
|
114
|
+
- features/assoc_indexing.feature
|
115
|
+
- features/basic.feature
|
116
|
+
- features/collection.feature
|
117
|
+
- features/flat_indexing.feature
|
118
|
+
- features/fred.feature
|
119
|
+
- features/inheritence.feature
|
120
|
+
- features/muliple_db.feature
|
121
|
+
- features/relationships.feature
|
122
|
+
- features/segmented_indexing.feature
|
123
|
+
- features/steps/model.rb
|
124
|
+
- features/steps/rod.rb
|
125
|
+
- features/steps/test_helper.rb
|
126
|
+
- lib/rod.rb
|
121
127
|
- lib/rod/abstract_database.rb
|
122
|
-
- lib/rod/
|
128
|
+
- lib/rod/abstract_model.rb
|
129
|
+
- lib/rod/cache.rb
|
130
|
+
- lib/rod/collection_proxy.rb
|
123
131
|
- lib/rod/constants.rb
|
124
|
-
- lib/rod/
|
132
|
+
- lib/rod/database.rb
|
125
133
|
- lib/rod/exception.rb
|
126
|
-
- lib/rod/
|
134
|
+
- lib/rod/join_element.rb
|
135
|
+
- lib/rod/model.rb
|
136
|
+
- lib/rod/segmented_index.rb
|
127
137
|
- lib/rod/string_element.rb
|
128
|
-
- lib/rod/
|
138
|
+
- lib/rod/string_ex.rb
|
139
|
+
- rod.gemspec
|
140
|
+
- tests/check_strings.rb
|
141
|
+
- tests/class_compatibility_create.rb
|
142
|
+
- tests/class_compatibility_verify.rb
|
143
|
+
- tests/eff1_test.rb
|
144
|
+
- tests/eff2_test.rb
|
145
|
+
- tests/full_runs.rb
|
146
|
+
- tests/generate_classes_create.rb
|
147
|
+
- tests/generate_classes_model.rb
|
148
|
+
- tests/generate_classes_rewrite.rb
|
149
|
+
- tests/generate_classes_verify.rb
|
150
|
+
- tests/load_struct.rb
|
151
|
+
- tests/migration_create.rb
|
152
|
+
- tests/migration_migrate.rb
|
153
|
+
- tests/migration_model1.rb
|
154
|
+
- tests/migration_model2.rb
|
155
|
+
- tests/migration_verify.rb
|
156
|
+
- tests/mock_tests.rb
|
157
|
+
- tests/read_on_create.rb
|
158
|
+
- tests/save_struct.rb
|
159
|
+
- tests/structures.rb
|
160
|
+
- tests/unit/database.rb
|
161
|
+
- tests/unit/model.rb
|
162
|
+
- tests/unit/model_tests.rb
|
163
|
+
- tests/validate_read_on_create.rb
|
164
|
+
- utils/convert_index.rb
|
129
165
|
has_rdoc: true
|
130
|
-
homepage:
|
166
|
+
homepage: http://github.com/apohllo/rod
|
131
167
|
licenses: []
|
132
168
|
|
133
169
|
post_install_message:
|
134
|
-
rdoc_options:
|
135
|
-
|
170
|
+
rdoc_options:
|
171
|
+
- --main
|
172
|
+
- README.rdoc
|
136
173
|
require_paths:
|
137
174
|
- lib
|
138
175
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -149,10 +186,22 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
186
|
version: "0"
|
150
187
|
requirements: []
|
151
188
|
|
152
|
-
rubyforge_project:
|
189
|
+
rubyforge_project: rod
|
153
190
|
rubygems_version: 1.5.2
|
154
191
|
signing_key:
|
155
192
|
specification_version: 3
|
156
193
|
summary: Ruby object database
|
157
|
-
test_files:
|
158
|
-
|
194
|
+
test_files:
|
195
|
+
- features/append.feature
|
196
|
+
- features/assoc_indexing.feature
|
197
|
+
- features/basic.feature
|
198
|
+
- features/collection.feature
|
199
|
+
- features/flat_indexing.feature
|
200
|
+
- features/fred.feature
|
201
|
+
- features/inheritence.feature
|
202
|
+
- features/muliple_db.feature
|
203
|
+
- features/relationships.feature
|
204
|
+
- features/segmented_indexing.feature
|
205
|
+
- features/steps/model.rb
|
206
|
+
- features/steps/rod.rb
|
207
|
+
- features/steps/test_helper.rb
|