og 0.20.0 → 0.21.0
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/CHANGELOG +796 -664
- data/INSTALL +24 -24
- data/README +39 -32
- data/Rakefile +41 -42
- data/benchmark/bench.rb +36 -36
- data/doc/AUTHORS +15 -12
- data/doc/LICENSE +3 -3
- data/doc/RELEASES +311 -243
- data/doc/config.txt +1 -1
- data/examples/mysql_to_psql.rb +15 -15
- data/examples/run.rb +92 -92
- data/install.rb +7 -17
- data/lib/og.rb +76 -75
- data/lib/og/collection.rb +203 -160
- data/lib/og/entity.rb +168 -169
- data/lib/og/errors.rb +5 -5
- data/lib/og/manager.rb +179 -178
- data/lib/og/mixin/hierarchical.rb +107 -107
- data/lib/og/mixin/optimistic_locking.rb +36 -36
- data/lib/og/mixin/orderable.rb +148 -148
- data/lib/og/mixin/timestamped.rb +8 -8
- data/lib/og/mixin/tree.rb +124 -124
- data/lib/og/relation.rb +237 -213
- data/lib/og/relation/belongs_to.rb +5 -5
- data/lib/og/relation/has_many.rb +60 -58
- data/lib/og/relation/joins_many.rb +93 -47
- data/lib/og/relation/refers_to.rb +25 -21
- data/lib/og/store.rb +210 -207
- data/lib/og/store/filesys.rb +79 -79
- data/lib/og/store/kirby.rb +263 -258
- data/lib/og/store/memory.rb +261 -261
- data/lib/og/store/mysql.rb +288 -284
- data/lib/og/store/psql.rb +261 -244
- data/lib/og/store/sql.rb +873 -720
- data/lib/og/store/sqlite.rb +177 -175
- data/lib/og/store/sqlserver.rb +204 -214
- data/lib/og/types.rb +1 -1
- data/lib/og/validation.rb +57 -57
- data/lib/vendor/mysql.rb +376 -376
- data/lib/vendor/mysql411.rb +10 -10
- data/test/og/mixin/tc_hierarchical.rb +59 -59
- data/test/og/mixin/tc_optimistic_locking.rb +40 -40
- data/test/og/mixin/tc_orderable.rb +67 -67
- data/test/og/mixin/tc_timestamped.rb +19 -19
- data/test/og/store/tc_filesys.rb +46 -46
- data/test/og/tc_inheritance.rb +81 -81
- data/test/og/tc_join.rb +67 -0
- data/test/og/tc_polymorphic.rb +49 -49
- data/test/og/tc_relation.rb +57 -30
- data/test/og/tc_select.rb +49 -0
- data/test/og/tc_store.rb +345 -337
- data/test/og/tc_types.rb +11 -11
- metadata +11 -18
data/test/og/store/tc_filesys.rb
CHANGED
@@ -5,67 +5,67 @@ require 'test/unit'
|
|
5
5
|
require 'og'
|
6
6
|
|
7
7
|
class TestCaseOgFilesys < Test::Unit::TestCase # :nodoc: all
|
8
|
-
|
8
|
+
include Og
|
9
9
|
|
10
|
-
|
10
|
+
class Comment; end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
class Article
|
13
|
+
property :body, String
|
14
|
+
has_many :comment, Comment
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
def initialize(body = nil)
|
17
|
+
@body = body
|
18
|
+
end
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
class Comment
|
22
|
+
property :body, String
|
23
|
+
belongs_to :article, Article
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
def initialize(body = nil)
|
26
|
+
@body = body
|
27
|
+
end
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
class User
|
31
|
+
property :name, :name_key => true
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup
|
35
|
+
@og = Og.setup(:store => 'filesys', :name => 'test')
|
36
|
+
end
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
38
|
+
def teardown
|
39
|
+
@og = nil
|
40
|
+
end
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
def test_all
|
43
|
+
# p Comment.__meta
|
44
|
+
# p Article.__meta
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
a1 = Article.new('Article 1')
|
47
|
+
@og.store.save(a1)
|
48
48
|
|
49
|
-
|
49
|
+
a2 = @og.store.load(1, Article)
|
50
50
|
|
51
|
-
|
51
|
+
assert_equal a1.body, a2.body
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
a3 = Article.new('Article 3')
|
54
|
+
a3.save
|
55
|
+
|
56
|
+
@og.store.delete(a3)
|
57
57
|
|
58
|
-
|
59
|
-
|
58
|
+
assert @og.store.load(1, Article)
|
59
|
+
assert !@og.store.load(2, Article)
|
60
60
|
|
61
|
-
|
61
|
+
a2.delete
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
# a.comments << Comment.new('Comment 1')
|
64
|
+
# a.save
|
65
|
+
# a = Article[1]
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
@og.store.close
|
68
|
+
@og.store.class.destroy(@og.options)
|
69
|
+
end
|
70
70
|
|
71
71
|
end
|
data/test/og/tc_inheritance.rb
CHANGED
@@ -7,97 +7,97 @@ require 'test/unit'
|
|
7
7
|
require 'og'
|
8
8
|
|
9
9
|
class TC_OgInheritance < Test::Unit::TestCase # :nodoc: all
|
10
|
-
|
10
|
+
include Og
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
12
|
+
class Document
|
13
|
+
property :title, String
|
14
|
+
schema_inheritance
|
15
|
+
|
16
|
+
def initialize(title)
|
17
|
+
@title = title
|
18
|
+
end
|
19
|
+
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
21
|
+
class Article < Document
|
22
|
+
property :body, String
|
23
|
+
|
24
|
+
def initialize(title, body)
|
25
|
+
@title, @body = title, body
|
26
|
+
end
|
27
|
+
end
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
class Photo < Document
|
30
|
+
property :url, String
|
31
|
+
|
32
|
+
def initialize(title, url)
|
33
|
+
@title, @url = title, url
|
34
|
+
end
|
35
|
+
end
|
36
36
|
|
37
|
-
|
37
|
+
def test_all
|
38
38
|
=begin
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
39
|
+
@og = Og.setup(
|
40
|
+
:store => :memory,
|
41
|
+
:name => :test
|
42
|
+
)
|
43
43
|
=end
|
44
44
|
#=begin
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
45
|
+
@og = Og.setup(
|
46
|
+
:destroy => true,
|
47
|
+
:store => :sqlite,
|
48
|
+
:name => 'test'
|
49
|
+
)
|
50
50
|
#=end
|
51
51
|
=begin
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
=end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
52
|
+
@og = Og.setup(
|
53
|
+
:destroy => true,
|
54
|
+
:store => :mysql,
|
55
|
+
:name => 'test',
|
56
|
+
:user => 'root',
|
57
|
+
:password => 'navelrulez'
|
58
|
+
)
|
59
|
+
=end
|
60
|
+
assert_equal [Document], Photo.metadata.superclass
|
61
|
+
assert_equal [Photo, Article], Document.metadata.subclasses
|
62
|
+
|
63
|
+
assert Document.metadata.schema_inheritance
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
65
|
+
# propagate schema_inheritance flag.
|
66
|
+
|
67
|
+
assert Photo.metadata.schema_inheritance
|
68
|
+
|
69
|
+
# subclasses reuse the same table.
|
70
|
+
|
71
|
+
assert_equal Document.table, Photo.table
|
72
|
+
|
73
|
+
doc = Document.create('doc1')
|
74
|
+
Photo.create('photo1', 'http:/www.gmosx.com/photo/1')
|
75
|
+
Photo.create('photo2', 'http:/www.gmosx.com/photo/2')
|
76
|
+
Article.create('art1', 'here comes the body')
|
77
|
+
Article.create('art2', 'this is cool')
|
78
|
+
Article.create('art3', 'this is cooler')
|
79
|
+
|
80
|
+
docs = Document.all
|
81
81
|
|
82
|
-
|
83
|
-
|
82
|
+
assert_equal 6, docs.size
|
83
|
+
assert_equal 'art2', docs[4].title
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
85
|
+
assert_equal Document, docs[0].class
|
86
|
+
assert_equal Photo, docs[1].class
|
87
|
+
assert_equal Article, docs[4].class
|
88
|
+
|
89
|
+
photos = Photo.all
|
90
|
+
|
91
|
+
assert_equal 2, photos.size
|
92
|
+
assert_equal 'photo2', photos[1].title
|
93
|
+
assert_equal 'http:/www.gmosx.com/photo/1', photos[0].url
|
94
|
+
|
95
|
+
articles = Article.all
|
96
|
+
|
97
|
+
assert_equal 3, articles.size
|
98
|
+
assert_equal 'art3', articles[2].title
|
99
|
+
|
100
|
+
articles = Article.all(:limit => 2)
|
101
|
+
assert_equal 2, articles.size
|
102
|
+
end
|
103
103
|
end
|
data/test/og/tc_join.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), 'lib')
|
2
|
+
|
3
|
+
$DBG = true
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
require 'og'
|
8
|
+
|
9
|
+
class TC_Join < Test::Unit::TestCase # :nodoc: all
|
10
|
+
include Og
|
11
|
+
|
12
|
+
class Category
|
13
|
+
property :title, String
|
14
|
+
|
15
|
+
def initialize(title)
|
16
|
+
@title = title
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Article
|
21
|
+
property :title, String
|
22
|
+
|
23
|
+
joins_many Category, :through => ArticleToCategory
|
24
|
+
|
25
|
+
def initialize(title)
|
26
|
+
@title = title
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class ArticleToCategory
|
31
|
+
property :rate, Float
|
32
|
+
property :hits, Fixnum
|
33
|
+
has_one Article
|
34
|
+
has_one Category
|
35
|
+
end
|
36
|
+
|
37
|
+
def setup
|
38
|
+
@og = Og.setup(
|
39
|
+
:destroy => true,
|
40
|
+
:store => :mysql,
|
41
|
+
# :store => :sqlite,
|
42
|
+
# :store => :psql,
|
43
|
+
# :user => 'postgres',
|
44
|
+
:user => 'root',
|
45
|
+
:password => 'navelrulez',
|
46
|
+
:name => 'test'
|
47
|
+
)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_all
|
51
|
+
c1 = Category.create('tech')
|
52
|
+
c2 = Category.create('funny')
|
53
|
+
|
54
|
+
a = Article.create('a1')
|
55
|
+
a.categories.push(c1, :hits =>3, :rate => 2.3)
|
56
|
+
a.categories.push(c2, :rate => 1.2)
|
57
|
+
|
58
|
+
join = a.category_join_data(c1)
|
59
|
+
assert_equal 2.3, join.rate
|
60
|
+
assert_equal 3, join.hits
|
61
|
+
|
62
|
+
join = a.category_join_data(c2)
|
63
|
+
assert_equal 1.2, join.rate
|
64
|
+
assert_equal nil, join.hits
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
data/test/og/tc_polymorphic.rb
CHANGED
@@ -5,60 +5,60 @@ require 'test/unit'
|
|
5
5
|
require 'og'
|
6
6
|
|
7
7
|
class TC_OgPolymorphic < Test::Unit::TestCase # :nodoc: all
|
8
|
-
|
8
|
+
include Og
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
10
|
+
# This class is a polymorphic parent. Ie' it acts as template
|
11
|
+
# to generate customized versions of this class.
|
12
|
+
|
13
|
+
class Comment
|
14
|
+
property :body, String
|
15
|
+
belongs_to :parent, Object # polymorphic marker !
|
16
|
+
|
17
|
+
def initialize(body)
|
18
|
+
@body = body
|
19
|
+
end
|
20
|
+
end
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
class Article
|
23
|
+
property :title, String
|
24
|
+
has_many Comment
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
26
|
+
def initialize(title)
|
27
|
+
@title = title
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class User
|
32
|
+
property :name, String
|
33
|
+
has_many Comment
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
def initialize(name)
|
36
|
+
@name = name
|
37
|
+
end
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
40
|
+
def setup
|
41
|
+
@og = Og.setup(
|
42
|
+
:destroy => true,
|
43
|
+
:store => :sqlite,
|
44
|
+
:name => 'test'
|
45
|
+
)
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
48
|
+
def test_all
|
49
|
+
u = User.create('gmosx')
|
50
|
+
|
51
|
+
u.comments << User::Comment.create('Hello')
|
52
|
+
u.comments << User::Comment.create('World')
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
54
|
+
assert_equal 2, u.comments.size
|
55
|
+
|
56
|
+
a = Article.create('test')
|
57
|
+
|
58
|
+
a.comments << Article::Comment.create('Hello2')
|
59
|
+
a.comments << Article::Comment.create('World2')
|
60
|
+
|
61
|
+
assert_equal 2, a.comments.size
|
62
|
+
end
|
63
|
+
|
64
64
|
end
|