nitro 0.9.3 → 0.9.5
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 +64 -0
- data/RELEASES +13 -0
- data/examples/blog/README +1 -1
- data/examples/blog/conf/app.conf.rb +2 -6
- data/examples/blog/conf/lhttpd.conf +1 -1
- data/examples/blog/lib/blog/controller.rb +2 -2
- data/examples/blog/root/style.css +0 -2
- data/examples/flash/conf/app.conf.rb +2 -4
- data/examples/no_xsl_blog/README +9 -0
- data/examples/no_xsl_blog/conf/app.conf.rb +5 -8
- data/examples/no_xsl_blog/conf/lhttpd.conf +1 -1
- data/examples/no_xsl_blog/lib/blog/controller.rb +2 -3
- data/examples/no_xsl_blog/lib/blog/template.rb +3 -3
- data/examples/no_xsl_blog/root/style.css +0 -2
- data/examples/og/mock_example.rb +1 -4
- data/examples/og/mysql_to_psql.rb +2 -4
- data/examples/tiny/README +1 -1
- data/examples/tiny/conf/app.conf.rb +2 -6
- data/examples/tiny/conf/lhttpd.conf +1 -1
- data/examples/wee_style/README +10 -0
- data/examples/wee_style/wee.rb +50 -0
- data/lib/glue/cache.rb +32 -34
- data/lib/glue/number.rb +3 -9
- data/lib/glue/time.rb +14 -22
- data/lib/glue/validation.rb +2 -4
- data/lib/nitro.rb +1 -3
- data/lib/nitro/adaptors/fastcgi.rb +10 -0
- data/lib/nitro/adaptors/webrick.rb +27 -11
- data/lib/nitro/builders/rss.rb +31 -11
- data/lib/nitro/builders/xhtml.rb +2 -8
- data/lib/nitro/context.rb +3 -1
- data/lib/nitro/dispatcher.rb +21 -4
- data/lib/nitro/filters.rb +12 -12
- data/lib/nitro/version.rb +1 -1
- data/lib/og/backend.rb +36 -40
- data/lib/og/backends/psql.rb +7 -7
- data/lib/og/backends/sqlite.rb +383 -0
- data/lib/og/connection.rb +34 -34
- data/lib/og/meta.rb +8 -0
- data/lib/og/version.rb +2 -4
- data/test/nitro/builders/tc_rss.rb +22 -0
- data/test/nitro/tc_dispatcher.rb +6 -1
- metadata +7 -2
data/lib/og/connection.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
# George Moschovitis <gm@navel.gr>
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
3
2
|
# (c) 2004-2005 Navel, all rights reserved.
|
4
3
|
# $Id: connection.rb 248 2005-01-31 13:38:34Z gmosx $
|
5
|
-
#++
|
6
4
|
|
7
5
|
class Og;
|
8
6
|
|
@@ -33,7 +31,7 @@ class Connection
|
|
33
31
|
|
34
32
|
attr_accessor :deserialize
|
35
33
|
|
36
|
-
# Initialize a connection to the database
|
34
|
+
# Initialize a connection to the database.
|
37
35
|
|
38
36
|
def initialize(og)
|
39
37
|
@og = og
|
@@ -42,8 +40,8 @@ class Connection
|
|
42
40
|
Logger.debug "Created DB connection." if $DBG
|
43
41
|
end
|
44
42
|
|
45
|
-
# Close the connection to the database
|
46
|
-
|
43
|
+
# Close the connection to the database.
|
44
|
+
|
47
45
|
def close()
|
48
46
|
@db.close()
|
49
47
|
Logger.debug "Closed DB connection." if $DBG
|
@@ -51,7 +49,7 @@ class Connection
|
|
51
49
|
|
52
50
|
# Save an object to the database. Insert if this is a new object or
|
53
51
|
# update if this is already stored in the database.
|
54
|
-
|
52
|
+
|
55
53
|
def save(obj)
|
56
54
|
if obj.oid
|
57
55
|
# object allready inserted, update!
|
@@ -65,13 +63,13 @@ class Connection
|
|
65
63
|
alias_method :put, :save
|
66
64
|
|
67
65
|
# Force insertion of managed object.
|
68
|
-
|
66
|
+
|
69
67
|
def insert(obj)
|
70
68
|
obj.og_insert(self)
|
71
69
|
end
|
72
70
|
|
73
71
|
# Force update of managed object.
|
74
|
-
|
72
|
+
|
75
73
|
def update(obj)
|
76
74
|
obj.og_update(self)
|
77
75
|
end
|
@@ -81,11 +79,11 @@ class Connection
|
|
81
79
|
# Input:
|
82
80
|
# sql = the sql code to updated the properties.
|
83
81
|
#
|
84
|
-
# WARNING: the object in
|
82
|
+
# WARNING: the object in memory is not updated.
|
85
83
|
#--
|
86
84
|
# TODO: should update the object in memory.
|
87
85
|
#++
|
88
|
-
|
86
|
+
|
89
87
|
def update_properties(update_sql, obj_or_oid, klass = nil)
|
90
88
|
oid = obj_or_oid.to_i
|
91
89
|
klass = obj_or_oid.class unless klass
|
@@ -98,7 +96,7 @@ class Connection
|
|
98
96
|
#
|
99
97
|
# Input:
|
100
98
|
# oid = the object oid, OR the object name.
|
101
|
-
|
99
|
+
|
102
100
|
def load(oid, klass)
|
103
101
|
if oid.to_i > 0 # a valid Fixnum ?
|
104
102
|
load_by_oid(oid, klass)
|
@@ -109,7 +107,7 @@ class Connection
|
|
109
107
|
alias_method :get, :load
|
110
108
|
|
111
109
|
# Load an object by oid.
|
112
|
-
|
110
|
+
|
113
111
|
def load_by_oid(oid, klass)
|
114
112
|
res = query "SELECT * FROM #{klass::DBTABLE} WHERE oid=#{oid}"
|
115
113
|
@deserialize? @db.deserialize_one(res, klass) : res
|
@@ -117,7 +115,7 @@ class Connection
|
|
117
115
|
alias_method :get_by_oid, :load_by_oid
|
118
116
|
|
119
117
|
# Load an object by name.
|
120
|
-
|
118
|
+
|
121
119
|
def load_by_name(name, klass)
|
122
120
|
res = query "SELECT * FROM #{klass::DBTABLE} WHERE name='#{name}'"
|
123
121
|
@deserialize? @db.deserialize_one(res, klass) : res
|
@@ -126,7 +124,7 @@ class Connection
|
|
126
124
|
|
127
125
|
# Load all objects of the given klass.
|
128
126
|
# Used to be called 'collect' in an earlier version.
|
129
|
-
|
127
|
+
|
130
128
|
def load_all(klass, extrasql = nil)
|
131
129
|
res = query "SELECT * FROM #{klass::DBTABLE} #{extrasql}"
|
132
130
|
@deserialize? @db.deserialize_all(res, klass) : res
|
@@ -135,7 +133,7 @@ class Connection
|
|
135
133
|
|
136
134
|
# Perform a standard SQL query to the database. Deserializes the
|
137
135
|
# results.
|
138
|
-
|
136
|
+
|
139
137
|
def select(sql, klass)
|
140
138
|
unless sql =~ /SELECT/i
|
141
139
|
sql = "SELECT * FROM #{klass::DBTABLE} WHERE #{sql}"
|
@@ -146,7 +144,7 @@ class Connection
|
|
146
144
|
end
|
147
145
|
|
148
146
|
# Optimized for one result.
|
149
|
-
|
147
|
+
|
150
148
|
def select_one(sql, klass)
|
151
149
|
unless sql =~ /SELECT/i
|
152
150
|
sql = "SELECT * FROM #{klass::DBTABLE} WHERE #{sql}"
|
@@ -157,7 +155,7 @@ class Connection
|
|
157
155
|
end
|
158
156
|
|
159
157
|
# Perform a count query.
|
160
|
-
|
158
|
+
|
161
159
|
def count(sql, klass = nil)
|
162
160
|
unless sql =~ /SELECT/i
|
163
161
|
sql = "SELECT COUNT(*) FROM #{klass::DBTABLE} WHERE #{sql}"
|
@@ -173,21 +171,23 @@ class Connection
|
|
173
171
|
# No need to optimize here with pregenerated code. Deletes are
|
174
172
|
# not used as much as reads or writes.
|
175
173
|
#
|
176
|
-
#
|
174
|
+
# Input:
|
177
175
|
#
|
178
176
|
# obj_or_oid = Object or oid to delete.
|
179
177
|
# klass = Class of object (can be nil if an object is passed)
|
180
|
-
|
178
|
+
|
181
179
|
def delete(obj_or_oid, klass = nil, cascade = true)
|
182
180
|
oid = obj_or_oid.to_i
|
183
181
|
klass = obj_or_oid.class unless klass
|
184
182
|
|
185
183
|
# this is a class callback!
|
184
|
+
|
186
185
|
if klass.respond_to?(:og_pre_delete)
|
187
186
|
klass.og_pre_delete(self, oid)
|
188
187
|
end
|
189
188
|
|
190
189
|
# TODO: implement this as stored procedure? naaah.
|
190
|
+
|
191
191
|
transaction do |tx|
|
192
192
|
tx.exec "DELETE FROM #{klass::DBTABLE} WHERE oid=#{oid}"
|
193
193
|
if cascade and klass.__meta.include?(:has)
|
@@ -202,60 +202,60 @@ class Connection
|
|
202
202
|
# Create the managed object table. The properties of the
|
203
203
|
# object are mapped to the table columns. Additional sql relations
|
204
204
|
# and constrains are created (indicices, sequences, etc).
|
205
|
-
|
205
|
+
|
206
206
|
def create_table(klass)
|
207
207
|
@db.create_table(klass)
|
208
208
|
end
|
209
209
|
|
210
210
|
# Drop the managed object table.
|
211
|
-
|
211
|
+
|
212
212
|
def drop_table(klass)
|
213
213
|
@db.drop_table(klass)
|
214
214
|
end
|
215
215
|
|
216
216
|
# Execute an SQL query and return the result
|
217
|
-
|
217
|
+
|
218
218
|
def query(sql)
|
219
219
|
@db.safe_query(sql)
|
220
220
|
end
|
221
221
|
|
222
222
|
# Execute an SQL query, no result returned.
|
223
|
-
|
223
|
+
|
224
224
|
def exec(sql)
|
225
225
|
@db.safe_exec(sql)
|
226
226
|
end
|
227
227
|
|
228
228
|
# Start a new transaction.
|
229
|
-
|
229
|
+
|
230
230
|
def start
|
231
|
-
@db.start
|
231
|
+
@db.start
|
232
232
|
end
|
233
233
|
|
234
234
|
# Commit a transaction.
|
235
|
-
|
235
|
+
|
236
236
|
def commit
|
237
|
-
@db.commit
|
237
|
+
@db.commit
|
238
238
|
end
|
239
239
|
|
240
240
|
# Rollback transaction.
|
241
|
-
|
241
|
+
|
242
242
|
def rollback
|
243
|
-
@db.rollback
|
243
|
+
@db.rollback
|
244
244
|
end
|
245
245
|
|
246
246
|
# Transaction helper. In the transaction block use
|
247
247
|
# the db pointer to the backend.
|
248
|
-
|
248
|
+
|
249
249
|
def transaction(&block)
|
250
250
|
begin
|
251
|
-
@db.start
|
251
|
+
@db.start
|
252
252
|
yield(@db)
|
253
|
-
@db.commit
|
253
|
+
@db.commit
|
254
254
|
rescue => ex
|
255
255
|
Logger.error "DB Error: ERROR IN TRANSACTION"
|
256
256
|
Logger.error #{ex}
|
257
257
|
Logger.error #{ex.backtrace}
|
258
|
-
@db.rollback
|
258
|
+
@db.rollback
|
259
259
|
end
|
260
260
|
end
|
261
261
|
|
data/lib/og/meta.rb
CHANGED
@@ -315,6 +315,14 @@ module MetaLanguage
|
|
315
315
|
}
|
316
316
|
end
|
317
317
|
|
318
|
+
# Declares that this class can join with another class.
|
319
|
+
# The join parameters are given so the join-compatible
|
320
|
+
# methods are generated.
|
321
|
+
|
322
|
+
def joins(klass, options = {})
|
323
|
+
meta :joins, [klass, options]
|
324
|
+
end
|
325
|
+
|
318
326
|
end
|
319
327
|
|
320
328
|
end
|
data/lib/og/version.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
|
2
|
-
# George Moschovitis <gm@navel.gr>
|
1
|
+
# * George Moschovitis <gm@navel.gr>
|
3
2
|
# (c) 2004-2005 Navel, all rights reserved.
|
4
3
|
# $Id: version.rb 248 2005-01-31 13:38:34Z gmosx $
|
5
|
-
#++
|
6
4
|
|
7
5
|
class Og
|
8
6
|
# The version of Og.
|
9
7
|
|
10
|
-
Version = '0.9.
|
8
|
+
Version = '0.9.5'
|
11
9
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', '..', 'lib')
|
2
|
+
|
3
|
+
require 'test/unit'
|
4
|
+
require 'nitro/builders/rss'
|
5
|
+
|
6
|
+
class TC_BuildersRss < Test::Unit::TestCase # :nodoc: all
|
7
|
+
|
8
|
+
Blog = Struct.new(:title, :body, :view_uri)
|
9
|
+
|
10
|
+
def test_render
|
11
|
+
blogs = []
|
12
|
+
blogs << Blog.new('Hello1', 'World1', 'uri1');
|
13
|
+
blogs << Blog.new('Hello2', 'World2', 'uri2');
|
14
|
+
blogs << Blog.new('Hello3', 'World3', 'uri3');
|
15
|
+
|
16
|
+
rss = N::RssBuilder.render(blogs, :link => 'http://www.navel.gr')
|
17
|
+
|
18
|
+
assert_match %r{<link>http://www.navel.gr/uri1</link>}, rss
|
19
|
+
assert_match %r{<link>http://www.navel.gr/uri2</link>}, rss
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/test/nitro/tc_dispatcher.rb
CHANGED
@@ -8,7 +8,7 @@ class TC_Dispatcher < Test::Unit::TestCase # :nodoc: all
|
|
8
8
|
class MainController
|
9
9
|
end
|
10
10
|
|
11
|
-
class BlogController
|
11
|
+
class BlogController < N::Controller
|
12
12
|
end
|
13
13
|
|
14
14
|
def setup
|
@@ -27,6 +27,11 @@ class TC_Dispatcher < Test::Unit::TestCase # :nodoc: all
|
|
27
27
|
def teardown
|
28
28
|
@d = @dxml = nil
|
29
29
|
end
|
30
|
+
|
31
|
+
def test_initialize
|
32
|
+
d = N::Dispatcher.new(BlogController)
|
33
|
+
assert_equal BlogController, d.controllers[:index]
|
34
|
+
end
|
30
35
|
|
31
36
|
def test_dispatch
|
32
37
|
klass, action = @d.dispatch('/blog/list')
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: nitro
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.9.
|
7
|
-
date: 2005-02-
|
6
|
+
version: 0.9.5
|
7
|
+
date: 2005-02-04
|
8
8
|
summary: Web Engine
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- examples/no_xsl_blog
|
68
68
|
- examples/flash
|
69
69
|
- examples/tiny
|
70
|
+
- examples/wee_style
|
70
71
|
- examples/blog
|
71
72
|
- examples/og
|
72
73
|
- examples/no_xsl_blog/ctl
|
@@ -130,6 +131,8 @@ files:
|
|
130
131
|
- examples/tiny/root/nitro.png
|
131
132
|
- examples/tiny/root/fcgi.rb
|
132
133
|
- examples/tiny/root/include.xhtml
|
134
|
+
- examples/wee_style/wee.rb
|
135
|
+
- examples/wee_style/README
|
133
136
|
- examples/blog/ctl
|
134
137
|
- examples/blog/log
|
135
138
|
- examples/blog/conf
|
@@ -251,6 +254,7 @@ files:
|
|
251
254
|
- lib/og/meta.rb
|
252
255
|
- lib/og/backend.rb
|
253
256
|
- lib/og/backends/mysql.rb
|
257
|
+
- lib/og/backends/sqlite.rb
|
254
258
|
- lib/og/backends/psql.rb
|
255
259
|
- test/nitro
|
256
260
|
- test/tc_og.rb
|
@@ -269,6 +273,7 @@ files:
|
|
269
273
|
- test/nitro/adaptors/tc_cgi.rb
|
270
274
|
- test/nitro/builders/tc_xhtml.rb
|
271
275
|
- test/nitro/builders/tc_xml.rb
|
276
|
+
- test/nitro/builders/tc_rss.rb
|
272
277
|
- test/nitro/ui/tc_pager.rb
|
273
278
|
- test/nitro/ui/tc_sitemap.rb
|
274
279
|
- test/root/blog
|