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/doc/config.txt
CHANGED
@@ -13,7 +13,7 @@ applications/sites on a single database.
|
|
13
13
|
|
14
14
|
If true, use Ruby's advanced introspection capabilities to
|
15
15
|
automatically manage classes that define properties.
|
16
|
-
|
16
|
+
|
17
17
|
=== Og.create_schema = true
|
18
18
|
|
19
19
|
If set to true, Og attempts to recreate the database schema
|
data/examples/mysql_to_psql.rb
CHANGED
@@ -12,19 +12,19 @@ require 'og'
|
|
12
12
|
# Configure databases.
|
13
13
|
|
14
14
|
psql_config = {
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
:destroy => true,
|
16
|
+
:name => 'test',
|
17
|
+
:store => 'psql',
|
18
|
+
:user => 'postgres',
|
19
|
+
:password => 'navelrulez'
|
20
20
|
}
|
21
21
|
|
22
22
|
mysql_config = {
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
:destroy => true,
|
24
|
+
:name => 'test',
|
25
|
+
:store => 'mysql',
|
26
|
+
:user => 'root',
|
27
|
+
:password => 'navelrulez'
|
28
28
|
}
|
29
29
|
|
30
30
|
# Initialize Og.
|
@@ -36,11 +36,11 @@ mysql = Og.connect(mysql_config)
|
|
36
36
|
# Looks like an ordinary Ruby object.
|
37
37
|
|
38
38
|
class Article
|
39
|
-
|
39
|
+
property :name, :body, String
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
def initialize(name = nil, body = nil)
|
42
|
+
@name, @body = name, body
|
43
|
+
end
|
44
44
|
end
|
45
45
|
|
46
46
|
# First populate the mysql database.
|
@@ -62,7 +62,7 @@ psql.manage(Article)
|
|
62
62
|
# Store all articles.
|
63
63
|
|
64
64
|
for article in articles
|
65
|
-
|
65
|
+
article.insert
|
66
66
|
end
|
67
67
|
|
68
68
|
# Fetch an article from PostgreSQL
|
data/examples/run.rb
CHANGED
@@ -9,137 +9,137 @@ $DBG = true
|
|
9
9
|
# A child class.
|
10
10
|
|
11
11
|
class Comment
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
12
|
+
property :body, String
|
13
|
+
|
14
|
+
def initialize(body = nil)
|
15
|
+
@body = body
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
return @body
|
20
|
+
end
|
21
21
|
end
|
22
22
|
|
23
23
|
# = A Parent class.
|
24
24
|
|
25
25
|
class User
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
26
|
+
property :name, String, :unique => true
|
27
|
+
has_many :comments, UserComment
|
28
|
+
|
29
|
+
def initialize(name = nil)
|
30
|
+
@name = name
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
return @name
|
35
|
+
end
|
36
36
|
end
|
37
37
|
|
38
38
|
|
39
39
|
# A parent class.
|
40
40
|
|
41
41
|
class Article
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
42
|
+
property :title, String
|
43
|
+
property :body, String
|
44
|
+
|
45
|
+
# override the default O->R mapping
|
46
|
+
|
47
|
+
property :level, Fixnum, :sql => "smallint DEFAULT 1"
|
48
|
+
|
49
|
+
# store a Ruby Hash in the Database. YAML
|
50
|
+
# is used for serializing the attribute.
|
51
|
+
# no need to define the class, but you can if you want.
|
52
|
+
|
53
|
+
property :options
|
54
|
+
|
55
|
+
# exactly like the standard Ruby attr creates only the reader.
|
56
|
+
|
57
|
+
prop :create_time, Time
|
58
|
+
|
59
|
+
# define comment relation:
|
60
|
+
|
61
|
+
has_many :comments, ArticleComment
|
62
|
+
|
63
|
+
has_many :parts, Part
|
64
|
+
|
65
|
+
# many to many relation.
|
66
|
+
|
67
|
+
many_to_many Category
|
68
|
+
|
69
|
+
# define author relation:
|
70
|
+
|
71
|
+
belongs_to :author, User
|
72
|
+
|
73
|
+
# this attribute is NOT stored in the db.
|
74
|
+
|
75
|
+
attr_accessor :other_options
|
76
|
+
|
77
|
+
# Managed object constructors with no args, take *args
|
78
|
+
# as parameter to allow for Mixin chaining.
|
79
|
+
|
80
|
+
def initialize(title = nil, body = nil)
|
81
|
+
@title, @body = title, body
|
82
|
+
@create_time = Time.now
|
83
|
+
@options = {}
|
84
|
+
@other_options = {}
|
85
|
+
end
|
86
|
+
|
87
|
+
def to_s
|
88
|
+
return "#@title: #@body"
|
89
|
+
end
|
90
90
|
end
|
91
91
|
|
92
92
|
# A parent class.
|
93
93
|
|
94
94
|
class Category
|
95
|
-
|
96
|
-
|
95
|
+
property :title, String
|
96
|
+
property :body, String
|
97
97
|
|
98
|
-
|
98
|
+
# define a 'many to many' relation.
|
99
99
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
100
|
+
many_to_many Article
|
101
|
+
|
102
|
+
def initialize(title = nil)
|
103
|
+
@title = title
|
104
|
+
end
|
105
105
|
end
|
106
106
|
|
107
107
|
|
108
108
|
# Article comment.
|
109
109
|
|
110
110
|
class ArticleComment < Comment
|
111
|
-
|
111
|
+
belongs_to Article
|
112
112
|
end
|
113
113
|
|
114
114
|
# User comment.
|
115
115
|
|
116
116
|
class UserComment < Comment
|
117
|
-
|
117
|
+
belongs_to :author, User
|
118
118
|
end
|
119
119
|
|
120
120
|
# Another child class.
|
121
121
|
|
122
122
|
class Part
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
123
|
+
property :name, String
|
124
|
+
belongs_to Article
|
125
|
+
|
126
|
+
def initialize(name = nil)
|
127
|
+
@name = name
|
128
|
+
end
|
129
|
+
|
130
|
+
def to_s
|
131
|
+
return @name
|
132
|
+
end
|
133
133
|
end
|
134
134
|
|
135
135
|
# Og configuration.
|
136
136
|
|
137
137
|
config = {
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
138
|
+
:destroy => true, # destroy table created from earlier runs.
|
139
|
+
:store => 'psql',
|
140
|
+
:name => 'test',
|
141
|
+
:user => "postgres",
|
142
|
+
:password => "navelrulez"
|
143
143
|
}
|
144
144
|
|
145
145
|
# Initialize Og
|
data/install.rb
CHANGED
@@ -1,28 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
# * George Moschovitis <gm@navel.gr>
|
4
|
-
# (c) 2004-2005 Navel, all rights reserved.
|
5
|
-
# $Id: install.rb 32 2005-04-25 12:31:21Z gmosx $
|
6
|
-
|
7
3
|
require 'rbconfig'
|
8
4
|
require 'ftools'
|
9
5
|
|
10
6
|
dst_dir = Config::CONFIG['sitelibdir']
|
11
7
|
|
12
8
|
Dir.chdir('lib') do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
# gmosx: this is potentially dangerous, rethink.
|
20
|
-
|
21
|
-
Dir.chdir('vendor') do
|
22
|
-
Dir['**/*.rb'].each do |file|
|
23
|
-
File.mkpath File.join(dst_dir, File.dirname(file)), true
|
24
|
-
File.install file, File.join(dst_dir, file), 0644, true
|
25
|
-
end
|
9
|
+
Dir['**/*.rb'].each do |file|
|
10
|
+
File.mkpath File.join(dst_dir, File.dirname(file)), true
|
11
|
+
File.install file, File.join(dst_dir, file), 0644, true
|
12
|
+
end
|
26
13
|
end
|
27
14
|
|
28
15
|
puts %{
|
@@ -45,3 +32,6 @@ at the command line.
|
|
45
32
|
|
46
33
|
Enjoy the magic of Og!
|
47
34
|
}
|
35
|
+
|
36
|
+
# * George Moschovitis <gm@navel.gr>
|
37
|
+
|
data/lib/og.rb
CHANGED
@@ -27,19 +27,20 @@ require 'glue/configuration'
|
|
27
27
|
#
|
28
28
|
# The library provides the following features:
|
29
29
|
#
|
30
|
-
# + Object-Relational mapping
|
30
|
+
# + Object-Relational mapping, automatically maps standard
|
31
|
+
# Ruby objects to sql schemas
|
31
32
|
# + Absolutely no configuration files.
|
32
33
|
# + Multiple stores (PostgreSQL, MySQL, SQLite, Oraclei, SqlServer, ..).
|
33
|
-
# + Supports non SQL stores.
|
34
|
+
# + Supports non SQL stores (in-memory, filesystem, ..).
|
34
35
|
# + ActiveRecord-style meta language and db aware methods.
|
35
36
|
# + Deserialize to Ruby Objects.
|
36
37
|
# + Deserialize sql join queries to Ruby Objects.
|
37
38
|
# + Eager associations.
|
38
39
|
# + Serialize arbitrary ruby object graphs through YAML.
|
39
40
|
# + Connection pooling.
|
40
|
-
# + Thread safety
|
41
|
+
# + Thread safety.
|
41
42
|
# + SQL transactions.
|
42
|
-
#
|
43
|
+
# + Aspect oriented constructs allow interception of lifecycle callbacks.
|
43
44
|
# + Transparent support for cascading deletes for all backends.
|
44
45
|
# + Hierarchical structures (nested sets)
|
45
46
|
# + Works safely as part of distributed application.
|
@@ -51,10 +52,10 @@ require 'glue/configuration'
|
|
51
52
|
# metadata types:
|
52
53
|
#
|
53
54
|
# [+:sql_index+]
|
54
|
-
#
|
55
|
+
# Create an sql index for this property.
|
55
56
|
#
|
56
57
|
# [+:unique+]
|
57
|
-
#
|
58
|
+
# This value of the property must be unique.
|
58
59
|
#
|
59
60
|
# === Design
|
60
61
|
#
|
@@ -67,78 +68,78 @@ require 'glue/configuration'
|
|
67
68
|
#
|
68
69
|
# * og_read
|
69
70
|
# * og_insert
|
70
|
-
#
|
71
|
-
#
|
71
|
+
# * og_update
|
72
|
+
# * og_delete
|
72
73
|
|
73
74
|
module Og
|
74
75
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
76
|
+
# The version.
|
77
|
+
|
78
|
+
Version = '0.21.0'
|
79
|
+
|
80
|
+
# Library path.
|
81
|
+
|
82
|
+
LibPath = File.dirname(__FILE__)
|
83
|
+
|
84
|
+
# If true, check for implicit changes in the object
|
85
|
+
# graph. For example when you add an object to a parent
|
86
|
+
# the object might be removed from his previous parent.
|
87
|
+
# In this case Og emmits a warning.
|
88
|
+
|
89
|
+
setting :check_implicit_graph_changes, :default => false, :doc => 'If true, check for implicit changes in the object graph'
|
90
|
+
|
91
|
+
# If true, only allow reading from the database. Usefull
|
92
|
+
# for maintainance.
|
93
|
+
# WARNING: not implemented yet.
|
94
|
+
|
95
|
+
setting :read_only_mode, :default => false, :doc => 'If true, only allow reading from the database'
|
96
|
+
|
97
|
+
# Prepend the following prefix to all generated SQL table names.
|
98
|
+
# Usefull on hosting scenarios where you have to run multiple
|
99
|
+
# web applications/sites on a single database.
|
100
|
+
#
|
101
|
+
# Don't set the table_prefix to nil, or you may face problems
|
102
|
+
# with reserved words on some RDBM systems. For example User
|
103
|
+
# maps to user which is reserved in postgresql). The prefix
|
104
|
+
# should start with an alphanumeric character to be compatible
|
105
|
+
# with all RDBM systems (most notable Oracle).
|
106
|
+
#--
|
107
|
+
# TODO: move this to the sql store.
|
108
|
+
#++
|
109
|
+
|
110
|
+
setting :table_prefix, :default => 'og', :doc => 'Prepend the prefix to all generated SQL table names'
|
111
|
+
|
112
|
+
# If true, Og tries to create/update the schema in the
|
113
|
+
# data store. For production/live environments set this to
|
114
|
+
# false and only set to true when the object model is
|
115
|
+
# upadated. For debug/development environments this should
|
116
|
+
# stay true for convienience.
|
117
|
+
|
118
|
+
setting :create_schema, :default => true, :doc => 'If true, Og tries to create/update the schema in the data store'
|
119
|
+
|
120
|
+
# If true raises exceptions on store errors, usefull when
|
121
|
+
# debugging. For production environments it should probably be
|
122
|
+
# set to false to make the application more fault tolerant.
|
123
|
+
|
124
|
+
setting :raise_store_exceptions, :default => true, :doc => 'If true raises exceptions on store errors'
|
125
|
+
|
126
|
+
# Enable/dissable thread safe mode.
|
127
|
+
|
128
|
+
setting :thread_safe, :default => true, :doc => 'Enable/dissable thread safe mode'
|
129
|
+
|
130
|
+
# Marker module. If included in a class, the Og automanager
|
131
|
+
# ignores this class.
|
132
|
+
|
133
|
+
module Unmanageable; end
|
134
|
+
|
135
|
+
# The active manager
|
136
|
+
|
137
|
+
mattr_accessor :manager
|
138
|
+
|
139
|
+
# Pseudo type for binary data
|
140
|
+
|
141
|
+
class Blob; end
|
142
|
+
|
142
143
|
end
|
143
144
|
|
144
145
|
# gmosx: leave this here.
|