nitro 0.8.0 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +3 -4
- data/ChangeLog +418 -0
- data/LICENSE +1 -1
- data/README +157 -89
- data/RELEASES +50 -0
- data/Rakefile +5 -7
- data/benchmark/nitro/bench.rb +5 -0
- data/benchmark/nitro/simple-webrick-n-200.txt +44 -0
- data/benchmark/nitro/static-webrick-n-200.txt +43 -0
- data/benchmark/nitro/tiny-lhttpd-n-200-c-5.txt +43 -0
- data/benchmark/nitro/tiny-webrick-n-200-c-5.txt +44 -0
- data/benchmark/nitro/tiny-webrick-n-200.txt +44 -0
- data/benchmark/nitro/tiny2-webrick-n-200.txt +44 -0
- data/{lib/nitro/server/cluster.rb → bin/cluster} +26 -30
- data/bin/proto/README +2 -2
- data/bin/proto/{apache.conf → conf/apache.conf} +0 -0
- data/bin/proto/conf/app.conf.rb +22 -0
- data/bin/proto/conf/lhttpd.conf +236 -0
- data/bin/proto/ctl +4 -0
- data/bin/proto/lib/README +5 -0
- data/bin/proto/log/README +3 -0
- data/bin/proto/root/fcgi.rb +6 -0
- data/bin/proto/root/index.xhtml +65 -7
- data/bin/proto/root/m/nitro.png +0 -0
- data/examples/blog/README +7 -5
- data/examples/blog/{apache.conf → conf/apache.conf} +0 -0
- data/examples/blog/conf/app.conf.rb +56 -0
- data/examples/blog/conf/lhttpd.conf +236 -0
- data/examples/blog/ctl +4 -0
- data/examples/blog/lib/blog.rb +11 -136
- data/examples/blog/lib/blog/controller.rb +99 -0
- data/examples/blog/lib/blog/model.rb +39 -0
- data/examples/blog/log/README +3 -0
- data/examples/blog/root/comments.xhtml +2 -2
- data/examples/blog/root/fcgi.rb +6 -0
- data/examples/blog/root/index.xhtml +4 -5
- data/examples/blog/root/login.xhtml +2 -2
- data/examples/blog/root/style.xsl +9 -9
- data/examples/blog/root/view_entry.xhtml +2 -2
- data/examples/flash/conf/app.conf.rb +23 -0
- data/examples/flash/ctl +4 -0
- data/examples/flash/log/README +3 -0
- data/examples/flash/root/index.xhtml +0 -9
- data/examples/flash/root/show_inline_text.xhtml +10 -5
- data/examples/no_xsl_blog/README +12 -0
- data/examples/no_xsl_blog/conf/apache.conf +0 -0
- data/examples/no_xsl_blog/conf/app.conf.rb +57 -0
- data/examples/no_xsl_blog/conf/lhttpd.conf +236 -0
- data/examples/no_xsl_blog/ctl +4 -0
- data/examples/no_xsl_blog/lib/blog.rb +20 -0
- data/examples/no_xsl_blog/lib/blog/controller.rb +102 -0
- data/examples/no_xsl_blog/lib/blog/model.rb +39 -0
- data/examples/no_xsl_blog/lib/blog/template.rb +134 -0
- data/examples/no_xsl_blog/log/README +3 -0
- data/examples/no_xsl_blog/root/comments.xhtml +41 -0
- data/examples/no_xsl_blog/root/entry_form.xhtml +22 -0
- data/examples/no_xsl_blog/root/fcgi.rb +6 -0
- data/examples/no_xsl_blog/root/index.xhtml +39 -0
- data/examples/no_xsl_blog/root/login.xhtml +21 -0
- data/examples/no_xsl_blog/root/m/bubbles.gif +0 -0
- data/examples/no_xsl_blog/root/m/comments_curve.gif +0 -0
- data/examples/no_xsl_blog/root/m/down.gif +0 -0
- data/examples/no_xsl_blog/root/m/footer_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/garrow.gif +0 -0
- data/examples/no_xsl_blog/root/m/gbull.gif +0 -0
- data/examples/no_xsl_blog/root/m/grbull.gif +0 -0
- data/examples/no_xsl_blog/root/m/h1_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/header_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/nitro.gif +0 -0
- data/examples/no_xsl_blog/root/m/obull.gif +0 -0
- data/examples/no_xsl_blog/root/m/page_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/rss.gif +0 -0
- data/examples/no_xsl_blog/root/m/side_title_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/sidebar_bg.gif +0 -0
- data/examples/no_xsl_blog/root/recent_posts.xhtml +14 -0
- data/examples/no_xsl_blog/root/style.css +301 -0
- data/examples/no_xsl_blog/root/view_entry.xhtml +25 -0
- data/examples/no_xsl_blog/root/view_entry.xml +12 -0
- data/examples/og/run.rb +2 -2
- data/examples/tiny/README +2 -2
- data/examples/tiny/conf/apache.conf +5 -0
- data/examples/tiny/conf/app.conf.rb +21 -0
- data/examples/tiny/conf/lhttpd.conf +236 -0
- data/examples/tiny/ctl +4 -0
- data/examples/tiny/log/README +3 -0
- data/examples/tiny/root/fcgi.rb +6 -0
- data/examples/tiny/root/index.xhtml +7 -4
- data/examples/tiny/root/nitro.png +0 -0
- data/lib/glue.rb +13 -9
- data/lib/glue/array.rb +1 -1
- data/lib/glue/cache.rb +1 -1
- data/lib/glue/flexob.rb +12 -0
- data/lib/glue/hash.rb +1 -1
- data/lib/glue/inflector.rb +2 -2
- data/lib/glue/logger.rb +4 -8
- data/lib/glue/misc.rb +14 -0
- data/lib/glue/number.rb +1 -1
- data/lib/glue/object.rb +26 -0
- data/lib/glue/pool.rb +1 -1
- data/lib/glue/property.rb +84 -91
- data/lib/glue/string.rb +1 -1
- data/lib/glue/time.rb +1 -1
- data/lib/glue/validation.rb +1 -1
- data/lib/nitro.rb +18 -6
- data/lib/nitro/adaptors/cgi.rb +291 -0
- data/lib/nitro/adaptors/fastcgi.rb +42 -0
- data/lib/nitro/adaptors/runner.rb +123 -0
- data/lib/nitro/adaptors/webrick.rb +110 -0
- data/lib/nitro/buffering.rb +43 -0
- data/lib/nitro/builders/form.rb +1 -1
- data/lib/nitro/builders/rss.rb +1 -1
- data/{bin → lib/nitro}/cluster.rb +26 -30
- data/lib/nitro/context.rb +82 -0
- data/lib/nitro/controller.rb +50 -0
- data/lib/nitro/cookie.rb +46 -0
- data/lib/nitro/dispatcher.rb +105 -0
- data/lib/nitro/filters.rb +9 -10
- data/lib/nitro/localization.rb +42 -0
- data/lib/nitro/mail.rb +11 -14
- data/lib/nitro/render.rb +275 -0
- data/lib/nitro/request.rb +128 -0
- data/lib/nitro/response.rb +38 -0
- data/lib/nitro/scaffold.rb +11 -11
- data/lib/nitro/session.rb +84 -0
- data/lib/nitro/{server/shaders.rb → shaders.rb} +56 -36
- data/lib/nitro/ui/pager.rb +23 -26
- data/lib/nitro/{sitemap.rb → ui/sitemap.rb} +4 -12
- data/lib/nitro/uri.rb +1 -1
- data/lib/nitro/version.rb +10 -8
- data/lib/og.rb +66 -65
- data/lib/og/backend.rb +1 -1
- data/lib/og/backends/mysql.rb +48 -52
- data/lib/og/backends/psql.rb +34 -37
- data/lib/og/connection.rb +15 -15
- data/lib/og/enchant.rb +16 -9
- data/lib/og/meta.rb +127 -54
- data/lib/og/mock.rb +18 -18
- data/lib/og/version.rb +6 -4
- data/lib/parts/content.rb +4 -8
- data/test/glue/tc_logger.rb +3 -0
- data/test/glue/tc_property.rb +19 -3
- data/test/nitro/adaptors/tc_cgi.rb +63 -0
- data/test/nitro/adaptors/tc_webrick.rb +15 -0
- data/test/nitro/builders/tc_xml.rb +2 -2
- data/test/nitro/tc_context.rb +13 -0
- data/test/nitro/tc_controller.rb +47 -0
- data/test/nitro/tc_dispatcher.rb +64 -0
- data/test/nitro/tc_session.rb +20 -0
- data/test/nitro/{tc_sitemap.rb → ui/tc_sitemap.rb} +1 -1
- data/test/root/blog/list.xhtml +6 -0
- data/test/tc_og.rb +41 -4
- metadata +115 -59
- data/bin/proto/app.rb +0 -20
- data/bin/proto/config.rb +0 -77
- data/examples/blog/app.rb +0 -21
- data/examples/blog/config.rb +0 -95
- data/examples/blog/env.rb +0 -22
- data/examples/flash/README +0 -34
- data/examples/flash/app.rb +0 -20
- data/examples/flash/config.rb +0 -38
- data/examples/flash/lib/flash.rb +0 -40
- data/examples/flash/tmp.swf +0 -0
- data/examples/tiny/app.rb +0 -19
- data/examples/tiny/config.rb +0 -29
- data/examples/tiny/root/nitro-small.png +0 -0
- data/lib/nitro/application.rb +0 -217
- data/lib/nitro/config.rb +0 -128
- data/lib/nitro/events.rb +0 -122
- data/lib/nitro/html.rb +0 -151
- data/lib/nitro/http.rb +0 -102
- data/lib/nitro/l10n.rb +0 -30
- data/lib/nitro/server.rb +0 -59
- data/lib/nitro/server/appserver.rb +0 -67
- data/lib/nitro/server/cookie.rb +0 -87
- data/lib/nitro/server/dispatcher.rb +0 -62
- data/lib/nitro/server/filters.rb +0 -75
- data/lib/nitro/server/filters/autologin.rb +0 -51
- data/lib/nitro/server/fragment.rb +0 -70
- data/lib/nitro/server/handlers.rb +0 -127
- data/lib/nitro/server/render.rb +0 -426
- data/lib/nitro/server/request.rb +0 -658
- data/lib/nitro/server/requestpart.rb +0 -54
- data/lib/nitro/server/script.rb +0 -387
- data/lib/nitro/server/server.rb +0 -57
- data/lib/nitro/server/session.rb +0 -220
- data/lib/nitro/server/user.rb +0 -46
- data/lib/nitro/server/webrick.rb +0 -180
- data/lib/nitro/service.rb +0 -26
- data/lib/xsl/ui.xsl +0 -51
- data/lib/xsl/xforms.xsl +0 -28
- data/test/nitro/server/tc_cookie.rb +0 -34
- data/test/nitro/server/tc_filters.rb +0 -38
- data/test/nitro/server/tc_request.rb +0 -70
- data/test/nitro/server/tc_requestpart.rb +0 -28
- data/test/nitro/server/tc_session.rb +0 -34
- data/test/nitro/tc_events.rb +0 -44
- data/test/nitro/tc_html.rb +0 -79
- data/test/nitro/tc_http.rb +0 -18
data/lib/nitro/ui/pager.rb
CHANGED
@@ -1,18 +1,14 @@
|
|
1
|
-
# code:
|
2
1
|
# * George Moschovitis <gm@navel.gr>
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# $Id: pager.rb 185 2004-12-10 13:29:09Z gmosx $
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
+
# $Id: pager.rb 223 2005-01-26 17:07:40Z gmosx $
|
6
4
|
|
7
5
|
require 'nitro/uri'
|
8
6
|
|
9
7
|
module N; module UI
|
10
8
|
|
11
|
-
# = Pager
|
12
|
-
#
|
13
9
|
# Displays a collection of entitities in multiple pages.
|
14
10
|
#
|
15
|
-
# === Design
|
11
|
+
# === Design
|
16
12
|
#
|
17
13
|
# The new version is carefully designed for scaleability. It stores
|
18
14
|
# only the items for one page. The name parameter is needed, multiple
|
@@ -23,7 +19,7 @@ module N; module UI
|
|
23
19
|
# avoid a concat() in the initialization step.
|
24
20
|
#
|
25
21
|
#
|
26
|
-
# === Example
|
22
|
+
# === Example
|
27
23
|
#
|
28
24
|
# @pager = N::UI::Pager.new('entries', @request, 5)
|
29
25
|
# @entries = N::BlogEntry.all("ORDER BY oid #{@pager.sql_limit}")
|
@@ -41,21 +37,24 @@ module N; module UI
|
|
41
37
|
# <td width="64"><x:pager-next>Next</x:pager-next></td>
|
42
38
|
# </tr>
|
43
39
|
# </table>
|
44
|
-
|
45
|
-
# === Investigate:
|
46
|
-
#
|
40
|
+
#--
|
47
41
|
# INVESTIGATE:
|
48
42
|
# mysql> SELECT SQL_CALC_FOUND_ROWS * FROM tbl_name
|
49
43
|
# -> WHERE id > 100 LIMIT 10;
|
50
44
|
# mysql> SELECT FOUND_ROWS();
|
51
|
-
|
45
|
+
#++
|
46
|
+
|
52
47
|
class Pager < Array
|
48
|
+
|
53
49
|
attr_accessor :name, :idx, :page, :page_count
|
54
|
-
|
50
|
+
|
51
|
+
# Total count of items
|
55
52
|
attr_accessor :total_count
|
56
|
-
|
53
|
+
|
54
|
+
# Page items
|
57
55
|
attr_accessor :page_items
|
58
|
-
|
56
|
+
|
57
|
+
# Read needed variables from the request.
|
59
58
|
attr_accessor :request
|
60
59
|
|
61
60
|
def initialize(name, request, items_per_page = 10, items = nil)
|
@@ -95,14 +94,14 @@ class Pager < Array
|
|
95
94
|
end
|
96
95
|
|
97
96
|
# Iterator
|
98
|
-
|
97
|
+
|
99
98
|
def each(&block)
|
100
99
|
@page_items.each(&block)
|
101
100
|
end
|
102
101
|
|
103
102
|
# Iterator
|
104
103
|
# Returns 1-based index.
|
105
|
-
|
104
|
+
|
106
105
|
def each_with_index
|
107
106
|
idx = @start_idx
|
108
107
|
for item in @page_items
|
@@ -120,7 +119,7 @@ class Pager < Array
|
|
120
119
|
end
|
121
120
|
|
122
121
|
# Returns the range of the current page.
|
123
|
-
|
122
|
+
|
124
123
|
def page_range
|
125
124
|
s = @idx
|
126
125
|
e = [@idx + @items_per_page - 1, all_total_count].min
|
@@ -129,7 +128,7 @@ class Pager < Array
|
|
129
128
|
end
|
130
129
|
|
131
130
|
# Override if needed.
|
132
|
-
|
131
|
+
|
133
132
|
def nav_range
|
134
133
|
# effective range = 10 pages.
|
135
134
|
s = [@page - 5, 1].max()
|
@@ -144,7 +143,7 @@ class Pager < Array
|
|
144
143
|
# Override this method in your application
|
145
144
|
# if needed.
|
146
145
|
# TODO: better markup.
|
147
|
-
|
146
|
+
|
148
147
|
def navigation
|
149
148
|
nav = ""
|
150
149
|
|
@@ -183,7 +182,7 @@ class Pager < Array
|
|
183
182
|
|
184
183
|
# Create an appropriate SQL limit clause.
|
185
184
|
# Returns postgres/mysql compatible limit.
|
186
|
-
|
185
|
+
|
187
186
|
def sql_limit
|
188
187
|
if @start_idx > 0
|
189
188
|
return "LIMIT #{@items_per_page} OFFSET #{@start_idx}"
|
@@ -194,20 +193,18 @@ class Pager < Array
|
|
194
193
|
end
|
195
194
|
|
196
195
|
# Returns the current offset. The offset is zero-based.
|
197
|
-
|
196
|
+
|
198
197
|
def offset
|
199
198
|
(@page-1) * @items_per_page
|
200
199
|
end
|
201
200
|
|
202
|
-
# ------------------------------------------------------------------
|
203
|
-
|
204
201
|
# Generate the target URI.
|
205
202
|
#
|
206
203
|
def target_uri(page)
|
207
204
|
params = {"__pg#{@name}" => page}
|
208
|
-
return N::UriUtils.update_query_string(@request.
|
205
|
+
return N::UriUtils.update_query_string(@request.uri.to_s, params)
|
209
206
|
end
|
210
207
|
|
211
208
|
end
|
212
209
|
|
213
|
-
end; end
|
210
|
+
end; end
|
@@ -1,21 +1,13 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# code:
|
6
|
-
# George Moschovitis <gm@navel.gr>
|
7
|
-
#
|
8
|
-
# (c) 2004 Navel, all rights reserved.
|
9
|
-
# $Id: sitemap.rb 167 2004-11-23 14:03:10Z gmosx $
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
+
# $Id: sitemap.rb 229 2005-01-27 12:55:29Z gmosx $
|
10
4
|
|
11
5
|
require "glue/hash"
|
12
6
|
|
13
7
|
module N
|
14
8
|
|
15
|
-
# = SitePage
|
16
|
-
#
|
17
9
|
# A single page in the page map.
|
18
|
-
|
10
|
+
|
19
11
|
class SitePage
|
20
12
|
# the uri for this page
|
21
13
|
attr_accessor :uri
|
data/lib/nitro/uri.rb
CHANGED
data/lib/nitro/version.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
|
-
|
2
|
-
# George Moschovitis <gm@navel.gr>
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
3
2
|
# (c) 2004-2005 Navel, all rights reserved.
|
4
|
-
# $Id: version.rb
|
5
|
-
#++
|
3
|
+
# $Id: version.rb 247 2005-01-28 16:15:52Z gmosx $
|
6
4
|
|
7
|
-
|
5
|
+
module Nitro
|
6
|
+
|
7
|
+
# The name of the engine.
|
8
8
|
|
9
|
-
|
9
|
+
Name = 'Nitro'
|
10
10
|
|
11
|
-
# The version of the server.
|
11
|
+
# The version of the server.
|
12
12
|
|
13
|
-
|
13
|
+
Version = '0.9.3'
|
14
|
+
|
15
|
+
end
|
data/lib/og.rb
CHANGED
@@ -1,18 +1,15 @@
|
|
1
|
-
# code:
|
2
1
|
# * George Moschovitis <gm@navel.gr>
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# $Id: og.rb 197 2004-12-21 13:50:17Z gmosx $
|
2
|
+
# (c) 2004-2005 Navel, all rights reserved.
|
3
|
+
# $Id: og.rb 248 2005-01-31 13:38:34Z gmosx $
|
6
4
|
|
7
5
|
require 'glue/logger'
|
6
|
+
require 'glue/attribute'
|
8
7
|
require 'glue/property'
|
9
8
|
require 'glue/array'
|
10
9
|
require 'glue/hash'
|
11
10
|
require 'glue/time'
|
12
11
|
require 'glue/pool'
|
13
12
|
|
14
|
-
# = Og
|
15
|
-
#
|
16
13
|
# Og (ObjectGraph) is an efficient, yet simple Object-Relational
|
17
14
|
# mapping library.
|
18
15
|
#
|
@@ -36,7 +33,7 @@ require 'glue/pool'
|
|
36
33
|
# + Works safely as part of distributed application.
|
37
34
|
# + Simple implementation.
|
38
35
|
#
|
39
|
-
#
|
36
|
+
# == Meta language
|
40
37
|
#
|
41
38
|
# primary_key :pid (NOT IMPLEMENTED)
|
42
39
|
# name_key :name (NOT IMPLEMENTED)
|
@@ -45,7 +42,7 @@ require 'glue/pool'
|
|
45
42
|
# many_to_many Role, :roles
|
46
43
|
# sql_index :pid
|
47
44
|
#
|
48
|
-
#
|
45
|
+
# == Design
|
49
46
|
#
|
50
47
|
# Keep the main classes backend agnostic.
|
51
48
|
#--
|
@@ -69,7 +66,7 @@ require 'glue/pool'
|
|
69
66
|
# The og.xxx methods are more flexible and allow you to use
|
70
67
|
# multiple databases for example.
|
71
68
|
#
|
72
|
-
#
|
69
|
+
# == Managed Objects Lifecycle Callbacks
|
73
70
|
#
|
74
71
|
# * og_pre_insert
|
75
72
|
# * og_post_insert
|
@@ -82,53 +79,58 @@ require 'glue/pool'
|
|
82
79
|
# A class level callback is used for delete because typically you call
|
83
80
|
# delete with an oid and not an object to avoid a deserialization.
|
84
81
|
#
|
85
|
-
#
|
82
|
+
# == Future
|
86
83
|
#
|
87
84
|
# * Support prepared statements (pgsql)
|
88
85
|
# * Support stored procedures (pgsql)
|
89
86
|
# * Support caching.
|
90
87
|
# * Deserialize to OpenStruct.
|
91
88
|
# * Better documentation.
|
92
|
-
|
89
|
+
|
93
90
|
class Og
|
94
|
-
class << self
|
95
|
-
# If true, only allow reading from the database. Usefull
|
96
|
-
# for maintainance.
|
97
|
-
attr_accessor :read_only_mode
|
98
|
-
|
99
|
-
# If true, the library automatically 'enchants' managed classes.
|
100
|
-
# In enchant mode, special db aware methods are added to
|
101
|
-
# managed classes and instances.
|
102
|
-
attr_accessor :enchant_managed_classes
|
103
|
-
|
104
|
-
# If true, use Ruby's advanced introspection capabilities to
|
105
|
-
# automatically manage classes tha define properties.
|
106
|
-
attr_accessor :auto_manage_classes
|
107
91
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
92
|
+
# If true, only allow reading from the database. Usefull
|
93
|
+
# for maintainance.
|
94
|
+
|
95
|
+
cattr_accessor :read_only_mode, false
|
96
|
+
|
97
|
+
# If true, the library automatically 'enchants' managed classes.
|
98
|
+
# In enchant mode, special db aware methods are added to
|
99
|
+
# managed classes and instances.
|
100
|
+
|
101
|
+
cattr_accessor :enchant_managed_classes, true
|
102
|
+
|
103
|
+
# If true, use Ruby's advanced introspection capabilities to
|
104
|
+
# automatically manage classes tha define properties.
|
105
|
+
|
106
|
+
cattr_accessor :auto_manage_classes, true
|
107
|
+
|
108
|
+
# If true, automatically include the Og meta-language into Module.
|
109
|
+
#
|
110
|
+
# By default this is FALSE, to avoid polution of the Module object.
|
111
|
+
# However if you include a prop_accessor or a managed Mixin in your
|
112
|
+
# object MetaLanguage gets automatically extended in the class.
|
113
|
+
|
114
|
+
cattr_accessor :include_meta_language, true
|
115
|
+
|
116
|
+
# Attach the following prefix to all generated SQL table names.
|
117
|
+
# Usefull on hosting scenarios where you have to run multiple
|
118
|
+
# web applications/sites on a single database.
|
125
119
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
120
|
+
cattr_accessor :table_prefix, nil
|
121
|
+
|
122
|
+
# The active database. Og allows you to access multiple
|
123
|
+
# databases from a single application.
|
124
|
+
|
125
|
+
cattr_accessor :db
|
126
|
+
|
127
|
+
# Set the active database.
|
128
|
+
|
129
|
+
def self.use(db)
|
130
|
+
@@db = db
|
131
|
+
@@db.get_connection
|
132
|
+
end
|
133
|
+
|
132
134
|
end
|
133
135
|
|
134
136
|
# gmosx: leave this here.
|
@@ -137,22 +139,18 @@ require 'og/meta'
|
|
137
139
|
|
138
140
|
class Og
|
139
141
|
|
140
|
-
# = Unmanageable
|
141
|
-
#
|
142
142
|
# Marker module. If included this in a class, the Og automanager
|
143
143
|
# ignores this class.
|
144
|
-
|
144
|
+
|
145
145
|
module Unmanageable; end
|
146
146
|
|
147
|
-
# = Database
|
148
|
-
#
|
149
147
|
# Encapsulates an Og Database.
|
150
|
-
|
148
|
+
|
151
149
|
class Database
|
152
150
|
include Og::Enchant
|
153
151
|
|
154
152
|
# Managed class metadata
|
155
|
-
|
153
|
+
|
156
154
|
class ManagedClassMeta
|
157
155
|
# The managed class.
|
158
156
|
attr_accessor :klass
|
@@ -167,16 +165,19 @@ class Database
|
|
167
165
|
end
|
168
166
|
|
169
167
|
# hash of configuration options.
|
168
|
+
|
170
169
|
attr_accessor :config
|
171
170
|
|
172
171
|
# Pool of connections to the backend.
|
172
|
+
|
173
173
|
attr_accessor :connection_pool
|
174
174
|
|
175
175
|
# Managed classes.
|
176
|
+
|
176
177
|
attr_accessor :managed_classes
|
177
178
|
|
178
179
|
# Initialize the database interface.
|
179
|
-
|
180
|
+
|
180
181
|
def initialize(config)
|
181
182
|
@config = config
|
182
183
|
|
@@ -199,7 +200,7 @@ class Database
|
|
199
200
|
|
200
201
|
# gmosx, FIXME: this automanage code is not elegant and slow
|
201
202
|
# should probably recode this, along with glue/property.rb
|
202
|
-
|
203
|
+
|
203
204
|
if Og.auto_manage_classes
|
204
205
|
# automatically manage classes with properties and metadata.
|
205
206
|
# gmosx: Any idea how to optimize this?
|
@@ -219,7 +220,7 @@ class Database
|
|
219
220
|
end
|
220
221
|
|
221
222
|
# Shutdown the database interface.
|
222
|
-
|
223
|
+
|
223
224
|
def shutdown
|
224
225
|
for con in @connection_pool
|
225
226
|
con.close()
|
@@ -229,7 +230,7 @@ class Database
|
|
229
230
|
|
230
231
|
# Get a connection from the pool to access the database.
|
231
232
|
# Stores the connection in a thread-local variable.
|
232
|
-
|
233
|
+
|
233
234
|
def get_connection
|
234
235
|
thread = Thread.current
|
235
236
|
|
@@ -243,7 +244,7 @@ class Database
|
|
243
244
|
alias_method :connection, :get_connection
|
244
245
|
|
245
246
|
# Restore an unused connection to the pool.
|
246
|
-
|
247
|
+
|
247
248
|
def put_connection
|
248
249
|
thread = Thread.current
|
249
250
|
|
@@ -254,7 +255,7 @@ class Database
|
|
254
255
|
end
|
255
256
|
|
256
257
|
# Utility method, automatically restores a connection to the pool.
|
257
|
-
|
258
|
+
|
258
259
|
def connect(deserialize = nil, &block)
|
259
260
|
result = nil
|
260
261
|
|
@@ -275,7 +276,7 @@ class Database
|
|
275
276
|
|
276
277
|
|
277
278
|
# Register a standard Ruby class as managed.
|
278
|
-
|
279
|
+
|
279
280
|
def manage(klass)
|
280
281
|
return if managed?(klass) or klass.ancestors.include?(Og::Unmanageable)
|
281
282
|
|
@@ -289,7 +290,7 @@ class Database
|
|
289
290
|
end
|
290
291
|
|
291
292
|
# Helper method to set multiple managed classes.
|
292
|
-
|
293
|
+
|
293
294
|
def manage_classes(*klasses)
|
294
295
|
for klass in klasses
|
295
296
|
manage(klass)
|
@@ -297,7 +298,7 @@ class Database
|
|
297
298
|
end
|
298
299
|
|
299
300
|
# Stop managing a Ruby class
|
300
|
-
|
301
|
+
|
301
302
|
def unmanage(klass)
|
302
303
|
@managed_classes.delete(klass)
|
303
304
|
end
|
@@ -309,7 +310,7 @@ class Database
|
|
309
310
|
end
|
310
311
|
|
311
312
|
# Add standard og functionality to the class
|
312
|
-
|
313
|
+
|
313
314
|
def convert(klass)
|
314
315
|
# Grab backend class
|
315
316
|
backend = @config[:backend]
|
@@ -393,4 +394,4 @@ class Database
|
|
393
394
|
end
|
394
395
|
end
|
395
396
|
|
396
|
-
end
|
397
|
+
end
|