nitro 0.2.0 → 0.3.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.
Files changed (76) hide show
  1. data/ChangeLog +186 -0
  2. data/README +40 -11
  3. data/RELEASES +10 -1
  4. data/Rakefile +5 -4
  5. data/bin/cluster.rb +3 -3
  6. data/{etc/new-project.rb → bin/new_app.rb} +1 -1
  7. data/examples/og/README +4 -0
  8. data/examples/og/run.rb +254 -0
  9. data/examples/simple/app.rb +3 -3
  10. data/examples/simple/conf/config.rb +10 -22
  11. data/examples/simple/conf/debug-config.rb +6 -32
  12. data/examples/simple/conf/live-config.rb +3 -23
  13. data/examples/simple/conf/requires.rb +5 -5
  14. data/examples/simple/env.rb +3 -4
  15. data/examples/simple/lib/articles/entities.rb +17 -15
  16. data/examples/simple/lib/articles/methods.rb +15 -15
  17. data/examples/simple/lib/articles/part.rb +7 -8
  18. data/examples/simple/root/comments.si +1 -1
  19. data/examples/simple/root/index.sx +1 -1
  20. data/examples/simple/root/view-article.sx +1 -2
  21. data/examples/tiny/app.rb +3 -3
  22. data/examples/tiny/conf/config.rb +4 -4
  23. data/examples/tiny/conf/requires.rb +3 -4
  24. data/lib/n/config.rb +50 -3
  25. data/lib/n/logger.rb +14 -2
  26. data/lib/n/og.rb +381 -0
  27. data/lib/n/og/backend.rb +252 -0
  28. data/lib/n/og/backends/mysql.rb +352 -0
  29. data/lib/n/og/backends/psql.rb +351 -0
  30. data/lib/n/og/connection.rb +253 -0
  31. data/lib/n/og/meta.rb +127 -0
  32. data/lib/n/properties.rb +6 -6
  33. data/lib/n/server.rb +4 -7
  34. data/lib/n/server/appserver.rb +58 -0
  35. data/lib/n/{app → server}/cluster.rb +3 -3
  36. data/lib/n/{app → server}/cookie.rb +3 -3
  37. data/lib/n/server/dispatcher.rb +55 -0
  38. data/lib/n/server/{filter.rb → filters.rb} +1 -1
  39. data/lib/n/{app → server}/filters/autologin.rb +5 -5
  40. data/lib/n/{app → server}/fragment.rb +3 -3
  41. data/lib/n/{app → server}/handlers.rb +4 -4
  42. data/lib/n/{app → server}/handlers/code-handler.rb +6 -6
  43. data/lib/n/{app → server}/handlers/page-handler.rb +9 -7
  44. data/lib/n/{app → server}/request.rb +8 -8
  45. data/lib/n/{app/request-part.rb → server/requestpart.rb} +4 -4
  46. data/lib/n/{app → server}/script.rb +5 -5
  47. data/lib/n/{app → server}/server.rb +1 -1
  48. data/lib/n/{app → server}/session.rb +5 -5
  49. data/lib/n/{app → server}/user.rb +1 -1
  50. data/lib/n/{app/webrick-servlet.rb → server/webrick.rb} +77 -20
  51. data/lib/n/shaders.rb +3 -2
  52. data/lib/n/std.rb +5 -32
  53. data/test/n/{app → server}/tc_cookie.rb +2 -2
  54. data/test/n/server/tc_filters.rb +38 -0
  55. data/test/n/{app → server}/tc_request.rb +6 -6
  56. data/test/n/{app → server}/tc_requestpart.rb +3 -3
  57. data/test/n/{app → server}/tc_session.rb +2 -2
  58. data/test/n/tc_og.rb +178 -0
  59. data/test/n/ui/tc_pager.rb +3 -3
  60. metadata +41 -65
  61. data/examples/ndb/README +0 -5
  62. data/examples/ndb/run.rb +0 -271
  63. data/lib/n/app/webrick.rb +0 -73
  64. data/lib/n/db.rb +0 -233
  65. data/lib/n/db/README +0 -232
  66. data/lib/n/db/connection.rb +0 -365
  67. data/lib/n/db/managed.rb +0 -233
  68. data/lib/n/db/mixins.rb +0 -279
  69. data/lib/n/db/mysql.rb +0 -345
  70. data/lib/n/db/psql.rb +0 -383
  71. data/lib/n/db/tools.rb +0 -106
  72. data/lib/n/db/utils.rb +0 -102
  73. data/lib/n/server/PLAYBACK.txt +0 -8
  74. data/lib/n/server/RESEARCH.txt +0 -13
  75. data/test/n/tc_db.rb +0 -223
  76. data/test/n/tc_db_mysql.rb +0 -241
data/examples/ndb/README DELETED
@@ -1,5 +0,0 @@
1
- = NDB Example
2
-
3
- A simple example that demonstrates various NDB features. Before
4
- runing this example, create a database named test.
5
-
data/examples/ndb/run.rb DELETED
@@ -1,271 +0,0 @@
1
- # = NDB Example
2
- #
3
- # A simple example to demonstrate the NDB library.
4
- # Ignore the errors marked as surpressed.
5
- #
6
- # code:
7
- # * George Moschovitis <gm@navel.gr>
8
- #
9
- # (c) 2004 Navel, all rights reserved.
10
- # $Id: run.rb 106 2004-10-25 11:31:11Z gmosx $
11
-
12
- $:.unshift "../../lib"
13
-
14
- require "n/std"
15
- require "n/logger"
16
- require "n/db"
17
-
18
- # = A parent class
19
- #
20
- class Article
21
- manage {
22
- # include some Mixins to 'synthesize' the class.
23
- include N::Entity
24
- include N::CreateTime
25
-
26
- prop_accessor String, :title
27
- prop_accessor String, :body
28
- # override the default O->R mapping
29
- prop_accessor Fixnum, "smallint DEFAULT 1", :level
30
- # store a Ruby Hash in the Database. Marshal
31
- # is used for serializing the attribute.
32
- prop_accessor Hash, :options
33
- }
34
- # this attribute is NOT stored in the db.
35
- attr_accessor :other_options
36
-
37
- # Managed object constructors with no args, take *args
38
- # as parameter to allow for Mixin chaining.
39
- #
40
- def initialize(title = nil, body = nil)
41
- # call the constructors of the mixins
42
- super
43
- @title, @body = title, body
44
- options = {}
45
- other_options = {}
46
- end
47
-
48
- def to_s
49
- return "#@title: #@body"
50
- end
51
- end
52
-
53
- # = Another Parent class
54
- #
55
- class User
56
- manage {
57
- include N::Entity
58
- include N::Named
59
- }
60
-
61
- def initialize(name = nil)
62
- @name = name
63
- # can be called afterwards if you want.
64
- super
65
- end
66
-
67
- def to_s
68
- return @name
69
- end
70
- end
71
-
72
- # = A child class
73
- #
74
- class Comment
75
- manage {
76
- # include some Mixins to 'synthesize' the class.
77
- # This way we get OO sql table definitions.
78
- include N::Entity
79
- include N::Child
80
- # by including this mixin the object can be attached
81
- # to different parents.
82
- include N::ParentClass
83
- include N::CreateTime
84
-
85
- prop_accessor String, :body
86
- }
87
-
88
- def initialize(body = nil)
89
- super
90
- @body = body
91
- end
92
-
93
- def to_s
94
- return @body
95
- end
96
- end
97
-
98
- # = Another child class
99
- #
100
- class DummyChild
101
- manage {
102
- include N::Entity
103
- include N::Child
104
-
105
- prop_accessor String, :body
106
- }
107
-
108
- def initialize(body = nil)
109
- super
110
- @body = body
111
- end
112
-
113
- def to_s
114
- return @body
115
- end
116
- end
117
-
118
- # Initialize a logger.
119
-
120
- $log = Logger.new(STDERR);
121
-
122
- # Intialize NDB
123
-
124
- begin
125
- $db = N::Db.new(
126
- :address => "localhost",
127
- :database => "test",
128
- :user => "postgres",
129
- :password => "navelrulez",
130
- :connection_count => 5
131
- )
132
- rescue => ex
133
- puts "Database 'test' does not exist"
134
- puts "Create a new database with the following command: "
135
- puts "$ createdb test -U postgres"
136
- end
137
-
138
- # Cleanup the database for earlier executions
139
-
140
- $db.drop_table(Article)
141
- $db.drop_table(Comment)
142
-
143
- # Create some articles
144
-
145
- a1 = Article.new("Title1", "Body1")
146
- # by adding the managed object to the $db virtual array you denote
147
- # that this object should be managed.
148
- $db << a1
149
-
150
- a2 = Article.new("Title2", "Body2")
151
- $db << a2
152
-
153
- puts "\n\n"
154
- puts "Ignore the errors, NDB automatically initialized the schema"
155
-
156
- # Until now we use $db as a helper. From now on we 'll explicitly
157
- # require a connection to the db. The standard block idiom is used.
158
- # You can also use the $db.xxx helpers if you just want to execute
159
- # one command.
160
-
161
- $db.open { |db|
162
-
163
- puts "\n\n"
164
- puts "* Get and print all articles:"
165
- articles = db.get_all(Article)
166
- articles.each { |a| puts a }
167
-
168
- puts "\n\n"
169
- puts "* Print all children of the root (oid = -1) of class Aritcle:"
170
- articles = db.children(-1, Article)
171
- articles.each { |a| puts a }
172
-
173
- # Create some comments
174
-
175
- c1 = Comment.new("Comment 1")
176
- c1.set_parent(a1)
177
- $db << c1
178
-
179
- c2 = Comment.new("Comment 2")
180
- # alternative way to set the parent.
181
- c2.pid = a1.oid
182
- $db << c2
183
-
184
- c3 = Comment.new("Comment 3")
185
- # alternative way to set the parent.
186
- c3.pid = a1.oid
187
- $db << c3
188
-
189
- puts "\n\n"
190
- puts "* Print all all comments for article 1:"
191
- comments = db.children(a1, Comment)
192
- comments.each { |c| puts c }
193
-
194
- # Most NDB commands allow you to fine-tune the low level
195
- # SQL code by passing extra_sql parameters, here is an
196
- # example
197
- puts "\n\n"
198
- puts "* comments with sql finetunings:"
199
- # use a standard SQL limit clause
200
- comments = db.children(a1, Comment, "LIMIT 2")
201
- comments.each { |c| puts c }
202
-
203
-
204
- # Change a managed object
205
- a1.title = "Changed Title"
206
- # NDB knows that this is a managed object and executes
207
- # an SQL UPDATE instead of an SQL INSERT
208
- $db << a1
209
-
210
- puts "\n\n"
211
- db.get_all(Article).each { |a| puts a }
212
-
213
- # The previous command updates the whole object. It is used
214
- # when there are many updates or you dont care about speed.
215
- # To update only specific fields use pupdate or properties_update
216
- db.pupdate("title='A specific title'", a2)
217
-
218
- puts "\n\n"
219
- db.get_all(Article).each { |a| puts a }
220
-
221
- # delete an object
222
- db.delete(c3)
223
-
224
- puts "\n\n"
225
- db.get_all(Comment).each { |a| puts a }
226
-
227
-
228
- # Serialize a hash
229
- a1.options = { "k1" => "val1", "k2" => "val2" }
230
- db << a1
231
-
232
- # lookup an object
233
- article = db.get(a1.oid, Article)
234
-
235
- puts "\n\n"
236
- puts article.options.inspect
237
-
238
- # attach another class of child objects to Article:
239
-
240
- d1 = DummyChild.new("hello")
241
- d1.set_parent(a1)
242
- db << d1
243
-
244
- d1 = DummyChild.new("world")
245
- d1.set_parent(a1)
246
- db << d1
247
-
248
- # Show the dummy children and not the comments.
249
-
250
- dummies = db.children(a1, DummyChild)
251
- dummies.each { |d| puts d }
252
-
253
- # And now something cool: We attach the Comment objects to different
254
- # parents
255
-
256
- u = User.new("gmosx")
257
- db << u
258
-
259
- c4 = Comment.new("Comment 4")
260
- c4.set_parent(u)
261
- $db << c4
262
-
263
- c5 = Comment.new("Comment 5")
264
- c5.set_parent(u)
265
- $db << c5
266
-
267
- comments = db.children(u, Comment)
268
- comments.each { |c| puts c }
269
- }
270
-
271
-
data/lib/n/app/webrick.rb DELETED
@@ -1,73 +0,0 @@
1
- # code:
2
- # * George Moschovitis <gm@navel.gr>
3
- # * Elias Athanasopoulos <elathan@navel.gr>
4
- #
5
- # (c) 2004 Navel, all rights reserved.
6
- # $Id: webrick.rb 106 2004-10-25 11:31:11Z gmosx $
7
-
8
- require "drb"
9
- require "cgi"
10
- require "webrick"
11
-
12
- require "n/logger"
13
- require "n/application"
14
- require "n/app/server"
15
- require "n/app/webrick-servlet"
16
-
17
- module N; module App
18
-
19
- # = Webrick AppServer
20
- #
21
- # The Application Server. Handles dynamic requests in a web application.
22
- # Dont keepalive (or use a VERY SMALL keepalive). Typically this server
23
- # is used along with a standard http server that handles other resources.
24
- #
25
- # Used temporarily unitl we build our own app server.
26
- #
27
- class Webrick < N::App::Server
28
- include WEBrick
29
-
30
- # the integrated webrock server.
31
- attr_accessor :webrick
32
-
33
- def initialize(name = "WebrickServer")
34
- super
35
- end
36
-
37
- # Start the application server.
38
- #
39
- def start
40
- accesslog = WEBrick::BasicLog::new("/dev/null")
41
- referer = WEBrick::BasicLog::new("/dev/null")
42
-
43
- @webrick = HTTPServer.new(
44
- :BindAddress => $appsrv_address,
45
- :Port => $appsrv_port,
46
- :DocumentRoot => $root_dir,
47
- # gmosx, FIXME: this shit still logs!!
48
- :Logger => Log.new(nil, WEBrick::Log::WARN),
49
- # elathan: amateur...
50
- :AccessLog => [
51
- [accesslog, AccessLog::COMMON_LOG_FORMAT],
52
- [referer, AccessLog::REFERER_LOG_FORMAT]
53
- ]
54
- )
55
-
56
- @webrick.mount("/", N::App::WebrickServlet)
57
-
58
- trap("INT") {
59
- @webrick.shutdown()
60
- }
61
-
62
- @webrick.start()
63
- end
64
-
65
- # Stop the application server.
66
- #
67
- def stop
68
- @webrick.stop
69
- end
70
-
71
- end
72
-
73
- end; end # module
data/lib/n/db.rb DELETED
@@ -1,233 +0,0 @@
1
- # code:
2
- # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
5
- # $Id: db.rb 106 2004-10-25 11:31:11Z gmosx $
6
-
7
- module N;
8
-
9
- require "n/properties"
10
- require "n/utils/array"
11
- require "n/utils/time"
12
- require "n/utils/pool"
13
-
14
- require "n/db/utils"
15
- require "n/db/managed"
16
- require "n/db/connection"
17
- require "n/db/mixins"
18
-
19
- # Configuration
20
-
21
- # if true, enables the read only mode
22
- $db_read_only_mode = false
23
-
24
- # = Db
25
- #
26
- # An efficient, yet simple Object-Relational Mapper.
27
- #
28
- # == Features
29
- #
30
- # The library provides the following features:
31
- #
32
- # + Object-Relational mapping
33
- # + Deserialize to Ruby Objects or ResultSets
34
- # + Deserialize sql join queries to Ruby Objects
35
- # + Serialize arbitrary ruby object graphs through Marshal
36
- # + Connection pooling
37
- # + Thread safety
38
- # + SQL transactions
39
- # + Callbacks
40
- # + Simple support for cascading deletes
41
- # + Hierarchical structures (preorder traversal, materialized paths)
42
- # + Works safely as part of distributed application.
43
- # + Simple implementation < 10k lines of code.
44
- #
45
- # === Design
46
- #
47
- # Keep this class backend agnostic. Put backend specific code in
48
- # the Connection / Managed class.
49
- #
50
- # Try to make the methods work with oids. We do keep
51
- # a unified id space. Include the N::Sequenced Marker to
52
- # denote custom id space.
53
- # Do NOT implement descendants use a root id (rid).
54
- #
55
- # For class ids we use the name instead of a hash. Class ids are
56
- # typically not used in querys, they are stored for completeness.
57
- # If we store a hash we cannot reclaim the class thus invalidating
58
- # the point. Instead of .name(), to_s() is used so the methods
59
- # are more flexible (they accept class names too!!)
60
- #
61
- # Db allows the serialization of arbitrary Ruby objects. Just
62
- # mark them as Object (or Array or Hash) in the prop_accessor
63
- # and the engine will serialize a Marshal.dump of the object.
64
- # Arbitrary object graphs are supported too.
65
- #
66
- # === Future
67
- #
68
- # * Support multiple DataBase backends (Postgres, MySQL, ...)
69
- # * Support prepared statements (pgsql)
70
- # * Support stored procedures (pgsql)
71
- # * Support caching
72
- # * Deserialize to OpenStruct
73
- # * Better documentation
74
- # * Code cleanup, refactoring
75
- # * Release as Gem, RPAbase
76
- # * Foreign keys (cascading delete)
77
- #
78
- # === Design:
79
- #
80
- # - This is NOT a singleton, an application may access multiple
81
- # databases.
82
- #
83
- class Db
84
- # hash of configuration options.
85
- attr_accessor :config
86
-
87
- # Pool of connections to the backend.
88
- attr_accessor :pool
89
-
90
- # Entities cache.
91
- attr_accessor :cache
92
-
93
- # Managed classes fields. A hash of hashes.
94
- attr_accessor :fields
95
-
96
- # Initialize the database interface.
97
- #
98
- def initialize(config)
99
- @config = config
100
-
101
- if backend = config[:backend]
102
- require "n/db/#{backend}"
103
- else
104
- require "n/db/psql"
105
- end
106
-
107
- $log.info "Connecting to database '#{config[:database]}'."
108
-
109
- @pool = N::Pool.new
110
- @fields = N::SafeHash.new
111
-
112
- for i in (0...config[:connection_count])
113
- @pool << DbConnection.new(config)
114
- end
115
- end
116
-
117
- # Shutdown the database interface.
118
- #
119
- def shutdown
120
- for con in @pool
121
- con.close()
122
- end
123
- end
124
- alias_method :close, :shutdown
125
-
126
- # Get a connection from the pool to access the database.
127
- #
128
- def get_connection
129
- return @pool.pop()
130
- end
131
-
132
- # Restore an unused connection to the pool.
133
- #
134
- def put_connection(connection)
135
- return @pool.push(connection)
136
- end
137
-
138
- # Utility method, automatically restores a connection to the pool.
139
- #
140
- def connect(deserialize = nil, &block)
141
- result = nil
142
-
143
- begin
144
- db = @pool.pop()
145
- db.deserialize = deserialize unless deserialize.nil?
146
-
147
- result = yield(db)
148
-
149
- db.deserialize = true
150
- ensure
151
- @pool.push(db)
152
- end
153
-
154
- return result
155
- end
156
- alias_method :open, :connect
157
-
158
- # Utility method, gets connection and encloses in transaction.
159
- #
160
- def transaction(deserialize = nil, &block)
161
- result = nil
162
-
163
- begin
164
- db = @pool.pop()
165
- db.deserialize = deserialize if deserialize
166
-
167
- db.start()
168
- result = yield(db)
169
- db.commit()
170
-
171
- db.deserialize = true
172
- ensure
173
- @pool.push(db)
174
- end
175
-
176
- return result
177
- end
178
-
179
- # Utility method, creates an entity from a row
180
- #
181
- def entity_from_row(row, klass)
182
- entity = klass.new()
183
- entity.__db_read_row__(row)
184
- return entity
185
- end
186
-
187
- private
188
-
189
- # Automatically wrap connection methods.
190
- #
191
- def self.wrap_method(method, args)
192
- args = args.split(/,/)
193
- class_eval %{
194
- def #{method}(#{args.join(", ")})
195
- begin
196
- db = @pool.pop()
197
- res = db.#{method}(#{args.collect {|a| a.split(/=/)[0]}.join(", ")})
198
- ensure
199
- @pool.push(db)
200
- end
201
- return res
202
- end
203
- }
204
- end
205
-
206
- wrap_method :put, "entity"
207
- alias_method :<<, :put
208
- wrap_method :insert, "obj"
209
- wrap_method :update, "obj"
210
- wrap_method :update_properties, "update_sql, ent_or_oid, klass = nil"
211
- wrap_method :pupdate, "update_sql, ent_or_oid, klass = nil"
212
- wrap_method :get, "oid, klass"
213
- wrap_method :get_by_oid, "oid, klass"
214
- wrap_method :get_by_name, "name, klass"
215
- wrap_method :get_all, "klass, extrasql = nil"
216
- wrap_method :select, "sql, klass, join_fields = nil"
217
- wrap_method :select_one, "sql, klass, join_fields = nil"
218
- wrap_method :child, "entity, klass, extrasql = nil"
219
- wrap_method :children, "entity, klass, extrasql = nil"
220
- wrap_method :count_children, "entity, klass, extrasql = nil"
221
- wrap_method :delete, "entity, klass = nil, cascade = true"
222
- wrap_method :query, "sql"
223
- wrap_method :query_one, "sql"
224
- wrap_method :count, "sql"
225
- wrap_method :match, "sql"
226
- wrap_method :exec, "sql"
227
- wrap_method :exec_and_clear, "sql"
228
- wrap_method :exec_clear, "sql"
229
- wrap_method :drop_table, "klass"
230
- end
231
-
232
- end # module
233
-