og 0.24.0 → 0.25.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ProjectInfo +2 -5
- data/README +2 -0
- data/doc/AUTHORS +4 -1
- data/doc/RELEASES +53 -0
- data/examples/run.rb +2 -2
- data/lib/{og/mixin → glue}/hierarchical.rb +19 -19
- data/lib/{og/mixin → glue}/optimistic_locking.rb +1 -1
- data/lib/glue/orderable.rb +235 -0
- data/lib/glue/revisable.rb +2 -0
- data/lib/glue/taggable.rb +176 -0
- data/lib/{og/mixin/taggable.rb → glue/taggable_old.rb} +6 -0
- data/lib/glue/timestamped.rb +37 -0
- data/lib/{og/mixin → glue}/tree.rb +3 -8
- data/lib/og.rb +21 -20
- data/lib/og/collection.rb +15 -1
- data/lib/og/entity.rb +256 -114
- data/lib/og/manager.rb +60 -27
- data/lib/og/{mixin/schema_inheritance_base.rb → markers.rb} +5 -2
- data/lib/og/relation.rb +70 -74
- data/lib/og/relation/belongs_to.rb +5 -3
- data/lib/og/relation/has_many.rb +1 -0
- data/lib/og/relation/joins_many.rb +5 -4
- data/lib/og/store.rb +25 -46
- data/lib/og/store/alpha/filesys.rb +1 -1
- data/lib/og/store/alpha/kirby.rb +30 -30
- data/lib/og/store/alpha/memory.rb +49 -49
- data/lib/og/store/alpha/sqlserver.rb +7 -7
- data/lib/og/store/kirby.rb +38 -38
- data/lib/og/store/mysql.rb +43 -43
- data/lib/og/store/psql.rb +222 -53
- data/lib/og/store/sql.rb +165 -105
- data/lib/og/store/sqlite.rb +29 -25
- data/lib/og/validation.rb +24 -14
- data/lib/{vendor → og/vendor}/README +0 -0
- data/lib/{vendor → og/vendor}/kbserver.rb +1 -1
- data/lib/{vendor → og/vendor}/kirbybase.rb +230 -79
- data/lib/{vendor → og/vendor}/mysql.rb +0 -0
- data/lib/{vendor → og/vendor}/mysql411.rb +0 -0
- data/test/og/mixin/tc_hierarchical.rb +1 -1
- data/test/og/mixin/tc_optimistic_locking.rb +1 -1
- data/test/og/mixin/tc_orderable.rb +1 -1
- data/test/og/mixin/tc_taggable.rb +2 -2
- data/test/og/mixin/tc_timestamped.rb +2 -2
- data/test/og/tc_finder.rb +33 -0
- data/test/og/tc_inheritance.rb +2 -2
- data/test/og/tc_scoped.rb +45 -0
- data/test/og/tc_store.rb +1 -7
- metadata +21 -18
- data/lib/og/mixin/orderable.rb +0 -174
- data/lib/og/mixin/revisable.rb +0 -0
- data/lib/og/mixin/timestamped.rb +0 -24
File without changes
|
File without changes
|
@@ -4,11 +4,11 @@ require 'test/unit'
|
|
4
4
|
require 'ostruct'
|
5
5
|
|
6
6
|
require 'og'
|
7
|
-
require '
|
7
|
+
require 'glue/taggable'
|
8
8
|
|
9
9
|
class Article
|
10
10
|
property :title, :body, String
|
11
|
-
|
11
|
+
is Taggable
|
12
12
|
|
13
13
|
def initialize(title = nil)
|
14
14
|
@title = title
|
@@ -4,7 +4,7 @@ require 'test/unit'
|
|
4
4
|
require 'ostruct'
|
5
5
|
|
6
6
|
require 'og'
|
7
|
-
require '
|
7
|
+
require 'glue/timestamped'
|
8
8
|
|
9
9
|
$og = Og.setup(
|
10
10
|
:store => 'psql',
|
@@ -17,7 +17,7 @@ $og = Og.setup(
|
|
17
17
|
class TestCaseOgTimestamped < Test::Unit::TestCase # :nodoc: all
|
18
18
|
|
19
19
|
class Article
|
20
|
-
|
20
|
+
is Timestamped
|
21
21
|
property :body, String
|
22
22
|
|
23
23
|
def initialize(body = nil)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
$DBG = true
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
require 'og'
|
8
|
+
|
9
|
+
class TC_OgFinder < Test::Unit::TestCase # :nodoc: all
|
10
|
+
|
11
|
+
class User
|
12
|
+
property :name, String
|
13
|
+
property :age, Fixnum
|
14
|
+
end
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@og = Og.setup($og_config)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_all
|
21
|
+
User.find_by_name('tml')
|
22
|
+
User.find_by_name_and_age('tml', 3)
|
23
|
+
User.find_all_by_name_and_age('tml', 3)
|
24
|
+
User.find_all_by_name_and_age('tml', 3, :name_op => 'LIKE', :age_op => '>', :limit => 4)
|
25
|
+
|
26
|
+
User.find_or_create_by_name_and_age('tml', 3)
|
27
|
+
User.find_or_create_by_name_and_age('stella', 5)
|
28
|
+
User.find_or_create_by_name_and_age('tml', 3)
|
29
|
+
|
30
|
+
assert_equal 2, User.all.size
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/test/og/tc_inheritance.rb
CHANGED
@@ -56,11 +56,11 @@ class TC_OgInheritance < Test::Unit::TestCase # :nodoc: all
|
|
56
56
|
assert_equal Document, Photo.superclass
|
57
57
|
assert_equal [Photo, Article], Document.descendents
|
58
58
|
|
59
|
-
assert Document.ann.
|
59
|
+
assert Document.ann.self.schema_inheritance
|
60
60
|
|
61
61
|
# propagate schema_inheritance flag.
|
62
62
|
|
63
|
-
assert Photo.ann.
|
63
|
+
assert Photo.ann.self.schema_inheritance
|
64
64
|
|
65
65
|
# subclasses reuse the same table.
|
66
66
|
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'CONFIG.rb')
|
2
|
+
|
3
|
+
$DBG = true
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
|
7
|
+
require 'og'
|
8
|
+
|
9
|
+
class TC_OgScoped < Test::Unit::TestCase # :nodoc: all
|
10
|
+
|
11
|
+
class User
|
12
|
+
property :name, String
|
13
|
+
has_many :articles
|
14
|
+
|
15
|
+
def initialize(name = nil)
|
16
|
+
@name = name
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Article
|
21
|
+
property :hits, Fixnum
|
22
|
+
belongs_to :user
|
23
|
+
|
24
|
+
def initialize(hits = nil)
|
25
|
+
@hits = hits
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def setup
|
30
|
+
@og = Og.setup($og_config)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_all
|
34
|
+
u = User.create('tml')
|
35
|
+
a1 = Article.create(10)
|
36
|
+
a2 = Article.create(20)
|
37
|
+
u.articles << a1
|
38
|
+
u.articles << a2
|
39
|
+
|
40
|
+
assert_equal 2, u.articles.size
|
41
|
+
assert_equal 1, u.articles.find(:condition => 'hits > 15').size
|
42
|
+
assert_equal 20, u.articles.find(:condition => 'hits > 15').first.hits
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
data/test/og/tc_store.rb
CHANGED
@@ -236,11 +236,6 @@ class TCOgStore < Test::Unit::TestCase # :nodoc: all
|
|
236
236
|
|
237
237
|
assert_equal 'gmosx', a4.owner.name
|
238
238
|
|
239
|
-
# generated finders
|
240
|
-
|
241
|
-
assert User.respond_to?(:find_by_name)
|
242
|
-
assert Comment.respond_to?(:find_by_body)
|
243
|
-
|
244
239
|
u = User.find_by_name('gmosx')
|
245
240
|
assert_equal 'gmosx', u.name
|
246
241
|
|
@@ -263,14 +258,13 @@ class TCOgStore < Test::Unit::TestCase # :nodoc: all
|
|
263
258
|
|
264
259
|
assert_equal 2, a.categories.size
|
265
260
|
|
266
|
-
a = Article.find_by_body('Hello')
|
261
|
+
a = Article.find_by_body('Hello')
|
267
262
|
assert_equal 2, a.categories.size
|
268
263
|
assert_equal 'News', a.categories[0].title
|
269
264
|
|
270
265
|
c = Category.find_by_title('News')
|
271
266
|
assert_equal 1, c.articles.size
|
272
267
|
|
273
|
-
|
274
268
|
# bug: extended class and many_to_many.
|
275
269
|
|
276
270
|
na = NewArticle.create('Bug')
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.10
|
|
3
3
|
specification_version: 1
|
4
4
|
name: og
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2005-
|
6
|
+
version: 0.25.0
|
7
|
+
date: 2005-11-17
|
8
8
|
summary: State of the art object-relational mapping system.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -51,15 +51,23 @@ files:
|
|
51
51
|
- examples/mysql_to_psql.rb
|
52
52
|
- examples/README
|
53
53
|
- examples/run.rb
|
54
|
+
- lib/glue
|
54
55
|
- lib/og
|
55
56
|
- lib/og.rb
|
56
|
-
- lib/
|
57
|
+
- lib/glue/hierarchical.rb
|
58
|
+
- lib/glue/optimistic_locking.rb
|
59
|
+
- lib/glue/orderable.rb
|
60
|
+
- lib/glue/revisable.rb
|
61
|
+
- lib/glue/taggable.rb
|
62
|
+
- lib/glue/taggable_old.rb
|
63
|
+
- lib/glue/timestamped.rb
|
64
|
+
- lib/glue/tree.rb
|
57
65
|
- lib/og/collection.rb
|
58
66
|
- lib/og/entity.rb
|
59
67
|
- lib/og/errors.rb
|
60
68
|
- lib/og/evolution.rb
|
61
69
|
- lib/og/manager.rb
|
62
|
-
- lib/og/
|
70
|
+
- lib/og/markers.rb
|
63
71
|
- lib/og/relation
|
64
72
|
- lib/og/relation.rb
|
65
73
|
- lib/og/store
|
@@ -68,14 +76,7 @@ files:
|
|
68
76
|
- lib/og/test.rb
|
69
77
|
- lib/og/types.rb
|
70
78
|
- lib/og/validation.rb
|
71
|
-
- lib/og/
|
72
|
-
- lib/og/mixin/optimistic_locking.rb
|
73
|
-
- lib/og/mixin/orderable.rb
|
74
|
-
- lib/og/mixin/revisable.rb
|
75
|
-
- lib/og/mixin/schema_inheritance_base.rb
|
76
|
-
- lib/og/mixin/taggable.rb
|
77
|
-
- lib/og/mixin/timestamped.rb
|
78
|
-
- lib/og/mixin/tree.rb
|
79
|
+
- lib/og/vendor
|
79
80
|
- lib/og/relation/all.rb
|
80
81
|
- lib/og/relation/belongs_to.rb
|
81
82
|
- lib/og/relation/has_many.rb
|
@@ -95,16 +96,17 @@ files:
|
|
95
96
|
- lib/og/store/alpha/sqlserver.rb
|
96
97
|
- lib/og/test/assertions.rb
|
97
98
|
- lib/og/test/testcase.rb
|
98
|
-
- lib/vendor/kbserver.rb
|
99
|
-
- lib/vendor/kirbybase.rb
|
100
|
-
- lib/vendor/mysql.rb
|
101
|
-
- lib/vendor/mysql411.rb
|
102
|
-
- lib/vendor/README
|
99
|
+
- lib/og/vendor/kbserver.rb
|
100
|
+
- lib/og/vendor/kirbybase.rb
|
101
|
+
- lib/og/vendor/mysql.rb
|
102
|
+
- lib/og/vendor/mysql411.rb
|
103
|
+
- lib/og/vendor/README
|
103
104
|
- test/og
|
104
105
|
- test/og/CONFIG.rb
|
105
106
|
- test/og/mixin
|
106
107
|
- test/og/store
|
107
108
|
- test/og/tc_delete_all.rb
|
109
|
+
- test/og/tc_finder.rb
|
108
110
|
- test/og/tc_inheritance.rb
|
109
111
|
- test/og/tc_join.rb
|
110
112
|
- test/og/tc_multiple.rb
|
@@ -112,6 +114,7 @@ files:
|
|
112
114
|
- test/og/tc_polymorphic.rb
|
113
115
|
- test/og/tc_relation.rb
|
114
116
|
- test/og/tc_reverse.rb
|
117
|
+
- test/og/tc_scoped.rb
|
115
118
|
- test/og/tc_select.rb
|
116
119
|
- test/og/tc_store.rb
|
117
120
|
- test/og/tc_types.rb
|
@@ -136,5 +139,5 @@ dependencies:
|
|
136
139
|
-
|
137
140
|
- "="
|
138
141
|
- !ruby/object:Gem::Version
|
139
|
-
version: 0.
|
142
|
+
version: 0.25.0
|
140
143
|
version:
|
data/lib/og/mixin/orderable.rb
DELETED
@@ -1,174 +0,0 @@
|
|
1
|
-
require 'mega/dynamod'
|
2
|
-
|
3
|
-
module Og
|
4
|
-
|
5
|
-
# Attach list/ordering methods to the enchanted class.
|
6
|
-
|
7
|
-
module Orderable
|
8
|
-
|
9
|
-
def self.append_dynamic_features(base, options)
|
10
|
-
o = {
|
11
|
-
:position => 'position',
|
12
|
-
:type => Fixnum,
|
13
|
-
}
|
14
|
-
o.update(options) if options
|
15
|
-
|
16
|
-
if o[:scope].is_a?(Symbol) && o[:scope].to_s !~ /_oid$/
|
17
|
-
o[:scope] = "#{o[:scope]}_oid".intern
|
18
|
-
end
|
19
|
-
|
20
|
-
position = o[:position]
|
21
|
-
scope = o[:scope]
|
22
|
-
|
23
|
-
if scope
|
24
|
-
if scope.is_a?(Symbol)
|
25
|
-
scope = %{(#{scope} ? "#{scope} = \#{@#{scope}}" : "#{scope} IS NULL")}
|
26
|
-
end
|
27
|
-
|
28
|
-
cond = ':condition => ' + scope
|
29
|
-
cond_and = ':condition => ' + scope + ' + " AND " +'
|
30
|
-
else
|
31
|
-
cond = ':condition => nil'
|
32
|
-
cond_and = ':condition => '
|
33
|
-
end
|
34
|
-
|
35
|
-
code = %{
|
36
|
-
property :#{position}, #{o[:type]}
|
37
|
-
|
38
|
-
pre "add_to_bottom", :on => :og_insert
|
39
|
-
pre "decrement_position_of_lower_items", :on => :og_delete
|
40
|
-
|
41
|
-
def move_higher
|
42
|
-
if higher = higher_item
|
43
|
-
#{base}.transaction do
|
44
|
-
higher.increment_position
|
45
|
-
decrement_position
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def move_lower
|
51
|
-
if lower = lower_item
|
52
|
-
#{base}.transaction do
|
53
|
-
lower.decrement_position
|
54
|
-
increment_position
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def move_to_top
|
60
|
-
#{base}.transaction do
|
61
|
-
increment_position_of_higher_items
|
62
|
-
set_top_position
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def move_to_bottom
|
67
|
-
#{base}.transaction do
|
68
|
-
decrement_position_of_lower_items
|
69
|
-
set_bottom_position
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def move_to(dest_position)
|
74
|
-
return if @#{position} == dest_position
|
75
|
-
|
76
|
-
#{base}.transaction do
|
77
|
-
if @#{position} < dest_position
|
78
|
-
#{base}.update("#{position}=(#{position} - 1)", #{cond_and}"#{position} > \#\{@#{position}\} AND #{position} <= \#\{dest_position\}")
|
79
|
-
else
|
80
|
-
#{base}.update("#{position}=(#{position} + 1)", #{cond_and}"#{position} >= \#\{dest_position\} AND #{position} < \#\{@#{position}\} ")
|
81
|
-
end
|
82
|
-
@#{position} = dest_position
|
83
|
-
update_property(:#{position})
|
84
|
-
end
|
85
|
-
|
86
|
-
self
|
87
|
-
end
|
88
|
-
|
89
|
-
def add_to_top
|
90
|
-
increment_position_of_all_items
|
91
|
-
end
|
92
|
-
|
93
|
-
def add_to_bottom
|
94
|
-
@#{position} = bottom_position + 1
|
95
|
-
end
|
96
|
-
|
97
|
-
def add_to
|
98
|
-
end
|
99
|
-
|
100
|
-
def higher_item
|
101
|
-
#{base}.one(#{cond_and}"#{position}=\#\{@#{position} - 1\}")
|
102
|
-
end
|
103
|
-
alias_method :previous_item, :higher_item
|
104
|
-
|
105
|
-
def lower_item
|
106
|
-
#{base}.one(#{cond_and}"#{position}=\#\{@#{position} + 1\}")
|
107
|
-
end
|
108
|
-
alias_method :next_item, :lower_item
|
109
|
-
|
110
|
-
def top_item
|
111
|
-
end
|
112
|
-
alias_method :first_item, :top_item
|
113
|
-
|
114
|
-
def bottom_item
|
115
|
-
#{base}.one(#{cond}, :order => "#{position} DESC", :limit => 1)
|
116
|
-
end
|
117
|
-
alias_method :last_item, :last_item
|
118
|
-
|
119
|
-
def top?
|
120
|
-
@#{position} == 1
|
121
|
-
end
|
122
|
-
alias_method :first?, :top?
|
123
|
-
|
124
|
-
def bottom?
|
125
|
-
@#{position} == bottom_position
|
126
|
-
end
|
127
|
-
alias_method :last?, :bottom?
|
128
|
-
|
129
|
-
def increment_position
|
130
|
-
@#{position} += 1
|
131
|
-
update_property(:#{position})
|
132
|
-
end
|
133
|
-
|
134
|
-
def decrement_position
|
135
|
-
@#{position} -= 1
|
136
|
-
update_property(:#{position})
|
137
|
-
end
|
138
|
-
|
139
|
-
def bottom_position
|
140
|
-
item = bottom_item
|
141
|
-
item ? item.#{position} : 0
|
142
|
-
end
|
143
|
-
|
144
|
-
def set_top_position
|
145
|
-
@#{position} = 1
|
146
|
-
update_property(:#{position})
|
147
|
-
end
|
148
|
-
|
149
|
-
def set_bottom_position
|
150
|
-
@#{position} = bottom_position + 1
|
151
|
-
update_property(:#{position})
|
152
|
-
end
|
153
|
-
|
154
|
-
def increment_position_of_higher_items
|
155
|
-
#{base}.update("#{position}=(#{position} + 1)", #{cond_and}"#{position} < \#\{@#{position}\}")
|
156
|
-
end
|
157
|
-
|
158
|
-
def increment_position_of_all_items
|
159
|
-
#{base}.update("#{position}=(#{position} + 1)", #{cond})
|
160
|
-
end
|
161
|
-
|
162
|
-
def decrement_position_of_lower_items
|
163
|
-
#{base}.update("#{position}=(#{position} - 1)", #{cond_and}"#{position} > \#\{@#{position}\}")
|
164
|
-
end
|
165
|
-
}
|
166
|
-
|
167
|
-
base.module_eval(code)
|
168
|
-
end
|
169
|
-
|
170
|
-
end
|
171
|
-
|
172
|
-
end
|
173
|
-
|
174
|
-
# * George Moschovitis <gm@navel.gr>
|