nitro 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. data/AUTHORS +3 -0
  2. data/ChangeLog +83 -0
  3. data/LICENCE +8 -8
  4. data/README +5 -1
  5. data/RELEASES +9 -0
  6. data/Rakefile +43 -23
  7. data/bin/cluster.rb +15 -12
  8. data/examples/ndb/README +5 -0
  9. data/examples/ndb/run.rb +271 -0
  10. data/examples/simple/README +27 -0
  11. data/examples/simple/app.rb +2 -2
  12. data/examples/simple/conf/config.rb +3 -8
  13. data/examples/simple/conf/debug-config.rb +6 -7
  14. data/examples/simple/conf/live-config.rb +2 -4
  15. data/examples/simple/conf/requires.rb +2 -10
  16. data/examples/simple/ctl +1 -1
  17. data/examples/simple/env.rb +2 -2
  18. data/examples/simple/root/article-form.ss +1 -1
  19. data/examples/simple/root/comments-form.ss +1 -1
  20. data/examples/tiny/README +15 -0
  21. data/examples/tiny/app.rb +2 -2
  22. data/examples/tiny/conf/config.rb +8 -13
  23. data/examples/tiny/conf/requires.rb +2 -8
  24. data/examples/tiny/ctl +2 -17
  25. data/examples/tiny/root/index.sx +1 -1
  26. data/lib/n/app/cluster.rb +15 -12
  27. data/lib/n/app/cookie.rb +10 -9
  28. data/lib/n/app/filters/autologin.rb +5 -4
  29. data/lib/n/app/fragment.rb +13 -10
  30. data/lib/n/app/handlers.rb +29 -22
  31. data/lib/n/app/handlers/code-handler.rb +2 -4
  32. data/lib/n/app/handlers/page-handler.rb +3 -5
  33. data/lib/n/app/request-part.rb +2 -7
  34. data/lib/n/app/request.rb +27 -22
  35. data/lib/n/app/script.rb +4 -15
  36. data/lib/n/app/server.rb +11 -7
  37. data/lib/n/app/session.rb +7 -11
  38. data/lib/n/app/user.rb +10 -11
  39. data/lib/n/app/webrick-servlet.rb +23 -10
  40. data/lib/n/app/webrick.rb +13 -10
  41. data/lib/n/application.rb +13 -6
  42. data/lib/n/config.rb +18 -7
  43. data/lib/n/db.rb +56 -40
  44. data/lib/n/db/connection.rb +18 -22
  45. data/lib/n/db/managed.rb +6 -8
  46. data/lib/n/db/mixins.rb +4 -7
  47. data/lib/n/db/mysql.rb +6 -3
  48. data/lib/n/db/psql.rb +15 -10
  49. data/lib/n/db/tools.rb +5 -9
  50. data/lib/n/db/utils.rb +11 -8
  51. data/lib/n/events.rb +14 -10
  52. data/lib/n/logger.rb +8 -2
  53. data/lib/n/macros.rb +5 -2
  54. data/lib/n/parts.rb +13 -10
  55. data/lib/n/properties.rb +17 -12
  56. data/lib/n/server.rb +3 -2
  57. data/lib/n/server/filter.rb +2 -4
  58. data/lib/n/shaders.rb +11 -13
  59. data/lib/n/sitemap.rb +23 -20
  60. data/lib/n/std.rb +15 -4
  61. data/lib/n/sync/clc.rb +4 -2
  62. data/lib/n/sync/handler.rb +20 -12
  63. data/lib/n/sync/server.rb +24 -18
  64. data/lib/n/ui/date-select.rb +2 -4
  65. data/lib/n/ui/pager.rb +10 -8
  66. data/lib/n/ui/popup.rb +5 -4
  67. data/lib/n/ui/select.rb +3 -4
  68. data/lib/n/ui/tabs.rb +3 -4
  69. data/lib/n/utils/array.rb +6 -14
  70. data/lib/n/utils/cache.rb +3 -7
  71. data/lib/n/utils/gfx.rb +5 -6
  72. data/lib/n/utils/hash.rb +7 -12
  73. data/lib/n/utils/html.rb +8 -4
  74. data/lib/n/utils/http.rb +10 -6
  75. data/lib/n/utils/mail.rb +6 -6
  76. data/lib/n/utils/number.rb +3 -4
  77. data/lib/n/utils/pool.rb +5 -8
  78. data/lib/n/utils/string.rb +12 -10
  79. data/lib/n/utils/template.rb +3 -5
  80. data/lib/n/utils/time.rb +7 -5
  81. data/lib/n/utils/uri.rb +5 -4
  82. data/lib/p/README +1 -0
  83. data/lib/xsl/xforms.xsl +2 -0
  84. data/test/n/app/tc_cookie.rb +34 -0
  85. data/test/n/app/tc_request.rb +70 -0
  86. data/test/n/app/tc_requestpart.rb +28 -0
  87. data/test/n/app/tc_session.rb +34 -0
  88. data/test/n/tc_db.rb +223 -0
  89. data/test/n/tc_db_mysql.rb +241 -0
  90. data/test/n/tc_events.rb +44 -0
  91. data/test/n/tc_properties.rb +68 -0
  92. data/test/n/tc_sitemap.rb +37 -0
  93. data/test/n/ui/tc_pager.rb +52 -0
  94. data/test/n/utils/tc_cache.rb +47 -0
  95. data/test/n/utils/tc_hash.rb +39 -0
  96. data/test/n/utils/tc_html.rb +79 -0
  97. data/test/n/utils/tc_http.rb +18 -0
  98. data/test/n/utils/tc_number.rb +21 -0
  99. data/test/n/utils/tc_strings.rb +149 -0
  100. data/test/n/utils/tc_uri.rb +100 -0
  101. metadata +49 -22
  102. data/doc/css.txt +0 -20
  103. data/doc/ideas.txt +0 -120
  104. data/doc/pg.txt +0 -47
  105. data/doc/svn.txt +0 -82
  106. data/doc/todo.txt +0 -30
  107. data/examples/simple/conf/overrides.rb +0 -9
  108. data/examples/simple/logs/access_log +0 -2
  109. data/examples/simple/logs/apache.log +0 -3
  110. data/examples/simple/logs/app.log +0 -1
  111. data/examples/simple/logs/events.log +0 -1
  112. data/examples/tiny/conf/apache.conf +0 -100
  113. data/examples/tiny/logs/access_log +0 -9
  114. data/examples/tiny/logs/apache.log +0 -9
  115. data/lib/n/db/make-release.sh +0 -26
  116. data/lib/n/tools/README +0 -11
  117. data/lib/xsl/ce.xsl +0 -30
  118. data/lib/xsl/localization.xsl +0 -23
  119. data/test/run.rb +0 -95
data/AUTHORS CHANGED
@@ -6,3 +6,6 @@
6
6
 
7
7
  * Elias Athanasopoulos <elathan@navel.gr>
8
8
  Additional coding.
9
+
10
+ * Elias Karakoulakis <ekarak@navel.gr>
11
+ Additional design.
data/ChangeLog CHANGED
@@ -1,5 +1,88 @@
1
+ 25-10-2004 George Moschovitis <gm@navel.gr>
2
+
3
+ * test cases pass again.
4
+
5
+ * lib/n/app/webrick-servlet.rb: fixed bug with default index,
6
+ better handler selection.
7
+
8
+ * lib/n/db/utils.rb: prepend _ before tables. it was dangerous!
9
+
10
+ * lib/n/db.rb: wrap drop table.
11
+
12
+ * lib/n/db/psql.rb: use Base64.decode64.
13
+
14
+ * examples/ndb/rub.rb: implemented.
15
+
16
+ 23-10-2004 George Moschovitis <gm@navel.gr>
17
+
18
+ * examples/ndb/*: introduced.
19
+
20
+ * lib/n/app/webrick-servlet.rb (#create_request): enforce default
21
+ index if missing.
22
+
23
+ * lib/n/config.rb: index_filename renamed from $srv_default_file.
24
+
25
+ * lib/n/utils/string.rb (#extension_from_path): returns nil if no
26
+ exception.
27
+
28
+ * lib/n/app/server.rb: info msg on start to let the admin know,
29
+ the server has started.
30
+
31
+ * lib/n/app/webrick.rb: extend from App::Server.
32
+
33
+ * examples/tiny/ctl: run without apache.
34
+ * examples/tiny/conf/config.rb: run without apache.
35
+
36
+ * examples/simple/README: improved.
37
+
38
+ 22-10-2004 George Moschovitis <gm@navel.gr>
39
+
40
+ * README: updated.
41
+
42
+ * fixed many file permissions.
43
+
44
+ * examples/simple/conf/config.rb: fixes.
45
+
46
+ * examples/simple/app.rb: fixes.
47
+
48
+ * test/*: copied all tests here,
49
+ too many fixes to list to make all tests pass again.
50
+
51
+ * Rakefile: fixed :install,
52
+ TestTask.
53
+
54
+ * lib/n/tools: removed.
55
+
56
+ * lib/n/app/request.rb: params alias for parameters.
57
+
58
+ * lib/xsl/ce.xsl: removed, not ready.
59
+
60
+ * lib/xsl/localization.xsl: deprecated.
61
+
62
+ * no need for action=#{request.uri} in forms.
63
+
64
+ * improved RDoc documentation to many, many souce files.
65
+
1
66
  21-10-2004 George Moschovitis <gm@navel.gr>
2
67
 
68
+ * lib/n/db/make-release.sh: removed.
69
+
70
+ * improved RDoc documentation to many, many, many source files.
71
+
72
+ * lib/n/app/user.rb (AnonymousUser#role?): introduced.
73
+
74
+ * lib/n/db/utils.rb (#write_prop): use base64 encoding.
75
+
76
+ * lib/n/db/psql.rb (#read_prop): use base64 encoding.
77
+
78
+ * Rakefile: added dependency for postgres-0.7.1
79
+
80
+ * doc/*: moved many txt files to the gen/doc directory.
81
+
82
+ 21-10-2004 George Moschovitis <gm@navel.gr>
83
+
84
+ * --- VERSION 0.1.2 ---
85
+
3
86
  * README: final changes before the release.
4
87
 
5
88
  20-10-2004 George Moschovitis <gm@navel.gr>
data/LICENCE CHANGED
@@ -7,16 +7,16 @@ Redistribution and use in source and binary forms, with or without
7
7
  modification, are permitted provided that the following conditions are
8
8
  met:
9
9
 
10
- * Redistributions of source code must retain the above copyright
11
- notice, this list of conditions and the following disclaimer.
10
+ * Redistributions of source code must retain the above copyright
11
+ notice, this list of conditions and the following disclaimer.
12
12
 
13
- * Redistributions in binary form must reproduce the above copyright
14
- notice, this list of conditions and the following disclaimer in the
15
- documentation and/or other materials provided with the distribution.
13
+ * Redistributions in binary form must reproduce the above copyright
14
+ notice, this list of conditions and the following disclaimer in the
15
+ documentation and/or other materials provided with the distribution.
16
16
 
17
- * Neither the name of Navel nor the names of its contributors may be
18
- used to endorse or promote products derived from this software
19
- without specific prior written permission.
17
+ * Neither the name of Navel nor the names of its contributors may be
18
+ used to endorse or promote products derived from this software
19
+ without specific prior written permission.
20
20
 
21
21
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
22
  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
data/README CHANGED
@@ -108,7 +108,11 @@ A short summary of the major features:
108
108
 
109
109
  * Support for 'nice' urls.
110
110
 
111
- Experimental
111
+ Experimental.
112
+
113
+ * Simple events manager.
114
+
115
+ Experimental.
112
116
 
113
117
  * Advanced debuging features
114
118
 
data/RELEASES CHANGED
@@ -1,4 +1,13 @@
1
1
 
2
+ == Version 0.2.0 was released on 25/10/2004.
3
+
4
+ Greatly improved RDoc documentation. Cleaned up many source files,
5
+ and improved the directory structure to be more compatible with
6
+ other Ruby projects. Introduced a test suite. Important bug fixes
7
+ in NDB. Tiny example no longer requires apache so sholud run out
8
+ of the box.
9
+
10
+
2
11
  == Version 0.1.2 was released on 21/10/2004.
3
12
 
4
13
  The first public version. Features 2 examples and limited
data/Rakefile CHANGED
@@ -8,8 +8,9 @@
8
8
 
9
9
  require "rake"
10
10
  require "rake/rdoctask"
11
- require "rubygems"
12
11
  require "rake/gempackagetask"
12
+ require "rake/testtask"
13
+ require "rubygems"
13
14
 
14
15
  require "lib/n/config"
15
16
 
@@ -20,9 +21,28 @@ task :default => :package
20
21
 
21
22
  # ----------------------------------------------------------------------
22
23
 
23
- desc "Run unit tests"
24
- task :test do
25
- # Might wait until I"ve got some...
24
+ # Run the tests
25
+
26
+ Rake::TestTask.new do |t|
27
+ t.libs << "test"
28
+ t.test_files = FileList["test/**/tc*.rb"].exclude("**/tc*db*.rb")
29
+ t.verbose = true
30
+ end
31
+
32
+ # Run all tests
33
+
34
+ Rake::TestTask.new(:test_all) do |t|
35
+ t.libs << "test"
36
+ t.test_files = FileList["test/**/tc*.rb"].exclude("**/tc*mysql*.rb")
37
+ t.verbose = true
38
+ end
39
+
40
+ # Run experimental tests
41
+
42
+ Rake::TestTask.new(:test_exp) do |t|
43
+ t.libs << "test"
44
+ t.test_files = FileList["test/**/tc*.rb"]
45
+ t.verbose = true
26
46
  end
27
47
 
28
48
  # ----------------------------------------------------------------------
@@ -37,30 +57,30 @@ end
37
57
 
38
58
  PKG_VERSION = $srv_version
39
59
  PKG_FILES = FileList[
40
- "[A-Z]*", "{bin,etc,examples,doc,lib,test}/**/*"
60
+ "[A-Z]*", "{bin,etc,ext,examples,doc,lib,test}/**/*"
41
61
  # "examples/*.rb"
42
62
  ].exclude(".svn/**/*")
43
63
 
44
64
  spec = Gem::Specification.new do |s|
45
- s.name = "nitro"
46
- s.version = PKG_VERSION
47
- s.summary = "Web Engine"
48
- s.description = "An efficient, yet simple engine for Web Applications"
49
- # s.add_dependency("extensions", ">= 0.5")
50
- s.required_ruby_version = ">= 1.8.1"
51
- s.files = PKG_FILES.to_a
52
- s.require_path = "lib"
53
- s.autorequire = "n/std"
54
- s.has_rdoc = true
55
- s.extra_rdoc_files = FileList["[A-Z]*"].to_a
56
- s.rdoc_options << "--main" << "README" << "--title" <<
57
- "Nitro Documentation"
58
- s.test_files = []
65
+ s.name = "nitro"
66
+ s.version = PKG_VERSION
67
+ s.summary = "Web Engine"
68
+ s.description = "An efficient, yet simple engine for Web Applications"
69
+ s.add_dependency("postgres", ">= 0.7.1")
70
+ s.add_dependency("extensions", ">= 0.5")
71
+ s.required_ruby_version = ">= 1.8.1"
72
+ s.files = PKG_FILES.to_a
73
+ s.require_path = "lib"
74
+ s.autorequire = "n/std"
75
+ s.has_rdoc = true
76
+ s.extra_rdoc_files = FileList["[A-Z]*"].to_a
77
+ s.rdoc_options << "--main" << "README" << "--title" << "Nitro Documentation"
78
+ s.test_files = []
59
79
  s.bindir = "bin"
60
- s.author = "George Moschovitis"
61
- s.email = "gm@navel.gr"
62
- s.homepage = "http://www.navel.gr/nitro"
63
- s.rubyforge_project = "nitro"
80
+ s.author = "George Moschovitis"
81
+ s.email = "gm@navel.gr"
82
+ s.homepage = "http://www.navel.gr/nitro"
83
+ s.rubyforge_project = "nitro"
64
84
  end
65
85
 
66
86
  Rake::GemPackageTask.new(spec) do |pkg|
@@ -1,13 +1,10 @@
1
- # = Cluster
2
- #
3
- # TODO: use Sync instead of Monitor
4
- #
5
- # code:: gmosx
1
+ # code:
2
+ # * George Moschovitis <gm@navel.gr>
6
3
  #
7
4
  # (c) 2004 Navel, all rights reserved.
8
- # $Id: cluster.rb 74 2004-10-18 11:30:20Z gmosx $
5
+ # $Id: cluster.rb 104 2004-10-22 13:35:03Z gmosx $
9
6
 
10
- $:.unshift "nitro/lib"
7
+ $:.unshift "lib"
11
8
 
12
9
  require "drb"
13
10
  require "monitor"
@@ -21,16 +18,20 @@ module N
21
18
 
22
19
  # = Cluster
23
20
  #
24
- # A Cluster is a collection of servers. The cluster synchronizes the
25
- # servers and distributes the state. An older version used a polling
26
- # system, ie: the servers polled the cluster to obtain the state. This
27
- # version uses a push system, ie when the state is changed a delta
28
- # is pushed to the clients.
21
+ # A Cluster manages the state of a collection of servers. The cluster
22
+ # synchronizes the servers and distributes the state. An older version
23
+ # used a polling system, ie: the servers polled the cluster to
24
+ # obtain the state. This version uses a push system, ie when the
25
+ # state is changed a delta is pushed to the clients.
26
+ #
27
+ # TODO: use Sync instead of Monitor
29
28
  #
30
29
  class Cluster < N::Application
31
30
 
32
31
  # = CHash ClusterHash
33
32
  #
33
+ # The CHash 'endpoint' resides in the Cluster server
34
+ #
34
35
  class CHash < Hash
35
36
  attr :mon
36
37
 
@@ -111,6 +112,8 @@ class Cluster < N::Application
111
112
 
112
113
  # = SHash ServerHash
113
114
  #
115
+ # The SHash 'endpoint' resides in the App server
116
+ #
114
117
  class SHash < Hash
115
118
  attr :mon
116
119
 
@@ -0,0 +1,5 @@
1
+ = NDB Example
2
+
3
+ A simple example that demonstrates various NDB features. Before
4
+ runing this example, create a database named test.
5
+
@@ -0,0 +1,271 @@
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
+