og 0.17.0 → 0.18.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 +81 -0
- data/README +1 -0
- data/doc/AUTHORS +9 -6
- data/doc/RELEASES +24 -1
- data/lib/og.rb +8 -2
- data/lib/og/collection.rb +38 -22
- data/lib/og/entity.rb +15 -0
- data/lib/og/manager.rb +52 -10
- data/lib/og/mixin/hierarchical.rb +3 -4
- data/lib/og/mixin/orderable.rb +3 -2
- data/lib/og/mixin/timestamped.rb +2 -0
- data/lib/og/relation.rb +6 -1
- data/lib/og/relation/has_many.rb +6 -0
- data/lib/og/relation/joins_many.rb +5 -0
- data/lib/og/store/kirby.rb +280 -0
- data/lib/og/store/kirby/README +6 -0
- data/lib/og/store/kirby/kirbybase.rb +1601 -0
- data/lib/og/store/kirby/readme.txt +63 -0
- data/lib/og/store/madeleine.rb +0 -2
- data/lib/og/store/mysql.rb +5 -5
- data/lib/og/store/psql.rb +15 -7
- data/lib/og/store/sql.rb +50 -23
- data/lib/og/store/sqlite.rb +16 -12
- data/lib/og/store/sqlserver.rb +7 -3
- data/test/og/tc_store.rb +19 -6
- metadata +8 -3
data/CHANGELOG
CHANGED
@@ -1,5 +1,86 @@
|
|
1
|
+
29-05-2005 George Moschovitis <gm@navel.gr>
|
2
|
+
|
3
|
+
* lib/og/relation/has_many.rb: takes :order into account.
|
4
|
+
|
5
|
+
* lib/og/entity.rb (#find/#all): take find_options into account,
|
6
|
+
(#find_options): implemented.
|
7
|
+
(#order): implemented.
|
8
|
+
|
9
|
+
24-05-2005 George Moschovitis <gm@navel.gr>
|
10
|
+
|
11
|
+
* lib/og/store/kirby.rb (#og_insert): implemented,
|
12
|
+
(#destroy): implemented,
|
13
|
+
save files in a custom directory.
|
14
|
+
|
15
|
+
* test/*: some changes to make them pass again.
|
16
|
+
|
17
|
+
* lib/og/mixin/orderable.rb: use facet/macro instead of dinclude.
|
18
|
+
|
19
|
+
* lib/og/mixin/hierarchical.rb: use facet/macro instead of dinclude.
|
20
|
+
|
21
|
+
23-05-2005 George Moschovitis <gm@navel.gr>
|
22
|
+
|
23
|
+
* lib/og.rb: added thread_safe mode.
|
24
|
+
|
25
|
+
* lib/og/manager.rb: re-added support for threads,
|
26
|
+
use thread code only in thread safe mode.
|
27
|
+
|
28
|
+
20-05-2005 George Moschovitis <gm@navel.gr>
|
29
|
+
|
30
|
+
* lib/og/store/psql.rb (#initialize) min_messages, encoding,
|
31
|
+
schema_order options.
|
32
|
+
|
33
|
+
* lib/og/store/kirbybase/*: copied files from kirby distribution.
|
34
|
+
|
35
|
+
* lib/og/store/kirby.rb: introduced,
|
36
|
+
(#create_table): works.
|
37
|
+
(#create_column_map): implemented.
|
38
|
+
|
39
|
+
* lib/og/store/*: converted all stores to better handle nil
|
40
|
+
values [mneumann],
|
41
|
+
don't use the term 'column', use 'field' instead to make
|
42
|
+
more SQL agnostic.
|
43
|
+
|
44
|
+
* lib/og/store/sql.rb (#parse_float): added,
|
45
|
+
(#parse_int): added,
|
46
|
+
(#read_prop): handle nil values. [mneumann]
|
47
|
+
|
48
|
+
* lib/og/store/sqlite.rb (#blank?): alias eof? [jperrot]
|
49
|
+
|
50
|
+
--- THE REVENGE OF SITH ---
|
51
|
+
|
52
|
+
19-05-2005 George Moschovitis <gm@navel.gr>
|
53
|
+
|
54
|
+
* resolved a posted bug [mneumann].
|
55
|
+
|
56
|
+
* lib/og/relation/has_many.rb: added 'dummy' remove support.
|
57
|
+
|
58
|
+
* lib/og/collection.rb: improved Julien's patch.
|
59
|
+
|
60
|
+
18-05-2005 Julien Perrot <jperrot@exosec.fr>
|
61
|
+
|
62
|
+
* lib/og/collection.rb (#remove): implemented.
|
63
|
+
|
64
|
+
* lib/og/relation/joins_many.rb (#remove_xxx): implemented.
|
65
|
+
|
66
|
+
* lib/og/store/sql.rb (#unjoin): implemented.
|
67
|
+
|
68
|
+
* lib/og/manager.rb (#==): fixed when other == nil.
|
69
|
+
|
70
|
+
18-05-2005 George Moschovitis <gm@navel.gr>
|
71
|
+
|
72
|
+
* lib/og/store/sqlite.rb (#db_filename): overridable db file name [slewis].
|
73
|
+
|
74
|
+
* README: added warning about sqlite3 version [slewis].
|
75
|
+
|
76
|
+
17-05-2005 George Moschovitis <gm@navel.gr>
|
77
|
+
|
78
|
+
* lib/og.rb: keep active manager.
|
79
|
+
|
1
80
|
16-05-2005 George Moschovitis <gm@navel.gr>
|
2
81
|
|
82
|
+
* --- VERSION 0.17.0 ---
|
83
|
+
|
3
84
|
* doc/RELEASES: updated.
|
4
85
|
|
5
86
|
* README: updated.
|
data/README
CHANGED
@@ -90,6 +90,7 @@ Og requires the following applications or libraries:
|
|
90
90
|
|
91
91
|
* SQLite
|
92
92
|
http://www.sqlite.org/download.html
|
93
|
+
WARNING: you need sqlite3-ruby > 1.1.0
|
93
94
|
|
94
95
|
Please install the required applications and libraries before continuing
|
95
96
|
with the installation of Og. Only install the libraries needed for
|
data/doc/AUTHORS
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
MAIN DEVELOPER:
|
2
2
|
|
3
|
-
* George Moschovitis
|
3
|
+
* George Moschovitis <gm@navel.gr>
|
4
4
|
Project leader, architecture and design, main coder,
|
5
5
|
documentation, maintainer.
|
6
6
|
|
7
7
|
IDEAS, ADDITIONAL CODING, SUPPORT:
|
8
8
|
|
9
|
-
* Michael Neumann
|
9
|
+
* Michael Neumann <mneumann@ntecs.de>
|
10
10
|
Design, additional coding and bug reports.
|
11
11
|
|
12
|
-
*
|
12
|
+
* Anastasios Koutoumanos <ak@navel.gr>
|
13
|
+
Design, additional coding.
|
14
|
+
|
15
|
+
* Matt Bowen <matt.bowen@farweststeel.com>
|
13
16
|
Additional code and documentation.
|
14
17
|
|
15
|
-
*
|
16
|
-
|
18
|
+
* Julien Perrot <jperrot@exosec.fr>
|
19
|
+
Bug reports and patches.
|
17
20
|
|
18
|
-
* Thomas Quas
|
21
|
+
* Thomas Quas <tquas@yahoo.com>
|
19
22
|
Ideas, bug reports, unit tests.
|
data/doc/RELEASES
CHANGED
@@ -1,4 +1,27 @@
|
|
1
|
-
== Version 0.
|
1
|
+
== Version 0.18.0
|
2
|
+
|
3
|
+
Mainly a bug fix release. Many small improvements were
|
4
|
+
implemented. All reported bugs were fixed, as well as bugs found
|
5
|
+
during the deployment of a live application. For more information
|
6
|
+
consult the detailed changelog. Thanks to Julien Perrot for small
|
7
|
+
patches.
|
8
|
+
|
9
|
+
Some notable changes:
|
10
|
+
|
11
|
+
* Thread safe mode was added again in Og. This works nice with
|
12
|
+
the Webrick server.
|
13
|
+
|
14
|
+
* New order macro in Og to set default ordering for each
|
15
|
+
entity. The has_many collections respect the order setting.
|
16
|
+
|
17
|
+
* Fixes in the SQLite adapter.
|
18
|
+
|
19
|
+
* No warnings in the Posrgres adapter.
|
20
|
+
|
21
|
+
* Cleaned up some source files.
|
22
|
+
|
23
|
+
|
24
|
+
== Version 0.17.0 was released on 16/05/2005.
|
2
25
|
|
3
26
|
Og Reloaded!! A totally new, clean and elegant implementation
|
4
27
|
that supports tons of new advanced features. This version should
|
data/lib/og.rb
CHANGED
@@ -15,7 +15,6 @@ require 'glue/array'
|
|
15
15
|
require 'glue/hash'
|
16
16
|
require 'glue/time'
|
17
17
|
require 'glue/pool'
|
18
|
-
require 'glue/inflector'
|
19
18
|
require 'glue/validation'
|
20
19
|
require 'glue/aspects'
|
21
20
|
|
@@ -74,7 +73,7 @@ module Og
|
|
74
73
|
|
75
74
|
# The version.
|
76
75
|
|
77
|
-
Version = '0.
|
76
|
+
Version = '0.18.0'
|
78
77
|
|
79
78
|
# Library path.
|
80
79
|
|
@@ -122,11 +121,18 @@ module Og
|
|
122
121
|
|
123
122
|
mattr_accessor :raise_store_exceptions, true
|
124
123
|
|
124
|
+
# Enable/dissable thread safe mode.
|
125
|
+
|
126
|
+
mattr_accessor :thread_safe, true
|
127
|
+
|
125
128
|
# Marker module. If included in a class, the Og automanager
|
126
129
|
# ignores this class.
|
127
130
|
|
128
131
|
module Unmanageable; end
|
129
132
|
|
133
|
+
# The active manager
|
134
|
+
|
135
|
+
mattr_accessor :manager
|
130
136
|
end
|
131
137
|
|
132
138
|
# gmosx: leave this here.
|
data/lib/og/collection.rb
CHANGED
@@ -18,12 +18,16 @@ class Collection
|
|
18
18
|
# A method used to add insert objects in the collection.
|
19
19
|
|
20
20
|
attr_accessor :insert_proc
|
21
|
+
|
22
|
+
# A method used to remove objects from the collection.
|
23
|
+
|
24
|
+
attr_accessor :remove_proc
|
21
25
|
|
22
26
|
# A method used to find the objects that belong to the
|
23
27
|
# collection.
|
24
28
|
|
25
29
|
attr_accessor :find_proc
|
26
|
-
|
30
|
+
|
27
31
|
# The default find options.
|
28
32
|
|
29
33
|
attr_accessor :find_options
|
@@ -38,9 +42,10 @@ class Collection
|
|
38
42
|
|
39
43
|
# Initialize the collection.
|
40
44
|
|
41
|
-
def initialize(owner = nil, insert_proc = nil, find_proc = nil, find_options = {})
|
45
|
+
def initialize(owner = nil, insert_proc = nil, remove_proc = nil, find_proc = nil, find_options = {})
|
42
46
|
@owner = owner
|
43
47
|
@insert_proc = insert_proc
|
48
|
+
@remove_proc = remove_proc
|
44
49
|
@find_proc = find_proc
|
45
50
|
@find_options = find_options
|
46
51
|
@members = []
|
@@ -97,7 +102,24 @@ class Collection
|
|
97
102
|
alias_method :<<, :push
|
98
103
|
alias_method :add, :push
|
99
104
|
|
100
|
-
#
|
105
|
+
# Remove a member from the collection, the actual object
|
106
|
+
# is not deleted.
|
107
|
+
|
108
|
+
def remove(*objects)
|
109
|
+
objects = objects.flatten
|
110
|
+
|
111
|
+
objects.reject! { |obj| @members.delete(obj) if obj.unsaved? }
|
112
|
+
return if objects.empty?
|
113
|
+
|
114
|
+
@owner.transaction do
|
115
|
+
objects.each do |obj|
|
116
|
+
@owner.send(@remove_proc, obj)
|
117
|
+
@members.delete(obj)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
# Delete a member from the collection AND the store.
|
101
123
|
|
102
124
|
def delete(*objects)
|
103
125
|
objects = objects.flatten
|
@@ -113,9 +135,20 @@ class Collection
|
|
113
135
|
end
|
114
136
|
end
|
115
137
|
|
116
|
-
#
|
138
|
+
# Remove all members from the collection.
|
139
|
+
|
140
|
+
def remove_all
|
141
|
+
@owner.transaction do
|
142
|
+
@members.each { |obj| @owner.send(@remove_proc, obj) }
|
143
|
+
end
|
144
|
+
@members.clear
|
145
|
+
end
|
146
|
+
alias_method :clear, :remove_all
|
147
|
+
|
148
|
+
# Delete all members of the collection. Also delete from the
|
149
|
+
# store.
|
117
150
|
|
118
|
-
def
|
151
|
+
def delete_all
|
119
152
|
@owner.transaction do
|
120
153
|
@members.each { |obj| obj.delete }
|
121
154
|
end
|
@@ -137,20 +170,3 @@ private
|
|
137
170
|
end
|
138
171
|
|
139
172
|
end
|
140
|
-
|
141
|
-
__END__
|
142
|
-
|
143
|
-
=== Examples
|
144
|
-
|
145
|
-
article.comments.to_ary
|
146
|
-
|
147
|
-
for article in article.comments
|
148
|
-
end
|
149
|
-
|
150
|
-
blog = Blog.new
|
151
|
-
blog.categories << Category.new
|
152
|
-
blog.categories << Category.new
|
153
|
-
blog.enties << Entry.new
|
154
|
-
blog.save
|
155
|
-
|
156
|
-
blog.categories.unlink(1)
|
data/lib/og/entity.rb
CHANGED
@@ -71,6 +71,9 @@ module EntityMixin
|
|
71
71
|
alias_method :batch_update, :update_properties
|
72
72
|
|
73
73
|
def find(options = {})
|
74
|
+
if find_options = self.__meta[:find_options]
|
75
|
+
options = find_options.first.update(options)
|
76
|
+
end
|
74
77
|
options[:class] = self
|
75
78
|
ogmanager.store.find(options)
|
76
79
|
end
|
@@ -107,6 +110,18 @@ module EntityMixin
|
|
107
110
|
def const_missing(sym)
|
108
111
|
return sym
|
109
112
|
end
|
113
|
+
|
114
|
+
# Set the default find options for this entity.
|
115
|
+
|
116
|
+
def find_options(options)
|
117
|
+
meta :find_options, options
|
118
|
+
end
|
119
|
+
|
120
|
+
# Set the default order option for this entity.
|
121
|
+
|
122
|
+
def order(order_str)
|
123
|
+
meta :find_options, :order => order_str
|
124
|
+
end
|
110
125
|
end
|
111
126
|
|
112
127
|
end
|
data/lib/og/manager.rb
CHANGED
@@ -13,8 +13,7 @@ class Manager
|
|
13
13
|
class EntityInfo
|
14
14
|
attr_accessor :klass
|
15
15
|
attr_accessor :enchanted
|
16
|
-
attr_accessor :options
|
17
|
-
|
16
|
+
attr_accessor :options
|
18
17
|
|
19
18
|
def initialize(klass = nil)
|
20
19
|
@klass = klass
|
@@ -27,8 +26,9 @@ class Manager
|
|
27
26
|
|
28
27
|
attr_accessor :options
|
29
28
|
|
30
|
-
# The store used for persistence.
|
31
|
-
|
29
|
+
# The store used for persistence. This is a virtual field
|
30
|
+
# when running in thread_safe mode.
|
31
|
+
|
32
32
|
attr_accessor :store
|
33
33
|
|
34
34
|
# The collection of Entities managed by this manager.
|
@@ -38,7 +38,50 @@ class Manager
|
|
38
38
|
def initialize(options)
|
39
39
|
@options = options
|
40
40
|
@entities = {}
|
41
|
+
@pool = Glue::Pool.new
|
42
|
+
|
43
|
+
store_class = Store.for_name(options[:store])
|
44
|
+
store_class.destroy(options) if options[:destroy]
|
45
|
+
|
46
|
+
if Og.thread_safe
|
47
|
+
(options[:connection_count] || 5).times do
|
48
|
+
@pool << store_class.new(options)
|
49
|
+
end
|
50
|
+
else
|
51
|
+
@store = store_class.new(options)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Get a store from the pool.
|
56
|
+
|
57
|
+
def get_store
|
58
|
+
if Og.thread_safe
|
59
|
+
thread = Thread.current
|
60
|
+
|
61
|
+
unless conn = thread[:og_store]
|
62
|
+
conn = @pool.pop()
|
63
|
+
thread[:og_store] = conn
|
64
|
+
end
|
65
|
+
|
66
|
+
return conn
|
67
|
+
else
|
68
|
+
return @store
|
69
|
+
end
|
41
70
|
end
|
71
|
+
alias_method :store, :get_store
|
72
|
+
|
73
|
+
# Return a store to the pool.
|
74
|
+
|
75
|
+
def put_store
|
76
|
+
if Og.thread_safe
|
77
|
+
thread = Thread.current
|
78
|
+
|
79
|
+
if conn = thread[:og_store]
|
80
|
+
thread[:og_store] = nil
|
81
|
+
return @pool.push(conn)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
42
85
|
|
43
86
|
# Manage a class. Converts the class to an Entity.
|
44
87
|
|
@@ -49,7 +92,7 @@ class Manager
|
|
49
92
|
|
50
93
|
klass.module_eval %{
|
51
94
|
def ==(other)
|
52
|
-
@#{klass.primary_key.first} == other.#{klass.primary_key.first}
|
95
|
+
other ? @#{klass.primary_key.first} == other.#{klass.primary_key.first} : false
|
53
96
|
end
|
54
97
|
}
|
55
98
|
|
@@ -57,7 +100,9 @@ class Manager
|
|
57
100
|
klass.class.send(:attr_accessor, :ogmanager)
|
58
101
|
|
59
102
|
Relation.enchant(klass)
|
60
|
-
|
103
|
+
|
104
|
+
# FIXME: uggly!
|
105
|
+
store.enchant(klass, self); put_store
|
61
106
|
|
62
107
|
@entities[klass] = info
|
63
108
|
end
|
@@ -101,10 +146,7 @@ class << self
|
|
101
146
|
# Helper method, useful to initialize Og.
|
102
147
|
|
103
148
|
def setup(options = {})
|
104
|
-
m = Manager.new(options)
|
105
|
-
store = Store.for_name(options[:store])
|
106
|
-
store.destroy(options) if options[:destroy]
|
107
|
-
m.store = store.new(options)
|
149
|
+
m = @@manager = Manager.new(options)
|
108
150
|
m.manage_classes
|
109
151
|
return m
|
110
152
|
end
|
@@ -2,15 +2,14 @@ require 'facet/string/plural'
|
|
2
2
|
require 'facet/string/singular'
|
3
3
|
require 'facet/string/demodulize'
|
4
4
|
require 'facet/string/underscore'
|
5
|
-
|
6
|
-
require 'glue/dynamic_include'
|
5
|
+
require 'facet/macro'
|
7
6
|
|
8
7
|
module Og
|
9
8
|
|
10
9
|
# Implements the Nested Sets pattern for hierarchical
|
11
10
|
# SQL queries.
|
12
11
|
#--
|
13
|
-
# TODO: use
|
12
|
+
# TODO: use active collections.
|
14
13
|
#++
|
15
14
|
|
16
15
|
module NestedSets
|
@@ -137,4 +136,4 @@ end
|
|
137
136
|
|
138
137
|
end
|
139
138
|
|
140
|
-
|
139
|
+
# * George Moschovitis <gm@navel.gr>
|
data/lib/og/mixin/orderable.rb
CHANGED