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/ChangeLog CHANGED
@@ -1,5 +1,191 @@
1
+ 01-10-2004 George Moschovitis <gm@navel.gr>
2
+
3
+ * --- VERSION 0.3.0 ---
4
+
5
+ * removed some dependencies from the Gem.
6
+
7
+ * MAJOR: renamed og get/put to load/save.
8
+
9
+ * lib/n/std.rb: removed most NilClass overrides [b.candler]
10
+
11
+ * lib/n/og/connection.rb (#delete): fixed delete with no descendants,
12
+ og_pre_delete callback.
13
+
14
+ * lib/n/og/backends/psql.rb (#read_prop): fixed YAML bug.
15
+
16
+ * lib/n/og/backends/mysql.rb (#read_prop): fixed YAML bug.
17
+
18
+ * lib/n/og.rb (#enchant): all method,
19
+ (#manage_classes): introduced,
20
+ (#enchant): delete! method,
21
+ (#enchant): klass.save() method.
22
+
23
+ * examples/og/run.rb: totally recoded the example to work with Og,
24
+ yeah the example fully works.
25
+
26
+ * moved db files to .scrap
27
+
28
+ * examples/simple: YEAH works with og.
29
+
30
+ * lib/n/server/webrick.rb (#do_GET): og connection per request.
31
+
32
+ 31-10-2004 George Moschovitis <gm@navel.gr>
33
+
34
+ * lib/n/og/backends/mysql.rb: converted to the new refactored code.
35
+
36
+ * lib/n/og/backend.rb (#eval_og_insert): moves the code here,
37
+ use a custom oid_generator,
38
+ factored out deserialize code,
39
+ pre/post_inser_update.
40
+ (#eval_og_update): generate callbacks.
41
+
42
+ * lib/n/og/backends/psql.rb (#eval_og_insert): if the managed
43
+ object defines pre/post callbacks, insert them,
44
+ (OgUtils::oid_generation_code): introduced.
45
+
46
+ * no __og, just og_xxx.
47
+
48
+ 30-10-2004 George Moschovitis <gm@navel.gr>
49
+
50
+ * lib/n/og/backends/psql.rb (#write_prop): fixed,
51
+ (#initialize): autocreate database if not found,
52
+ made createdb/dropdb class methods.
53
+
54
+ * lib/n/og/backends/mysql.rb (#write_prop): fixed,
55
+ (#initialize): autocreate database if not found,
56
+ made createdb/dropdb class methods,
57
+ no transactions for mysql.
58
+
59
+ * lib/n/og/backend.rb (OgUtils#table): remove leading module,
60
+ (#transaction, #start, #commit, #rollback): working transaction
61
+ support,
62
+ added missing methods from the backend implementations.
63
+
64
+ * lib/n/og/meta.rb: introduced,
65
+ (#belongs_to): mega it works,
66
+ (#has_many): mega it works, INCREDIBLE,
67
+ (OgMetaLanguage): use a separate module,
68
+ (#has_many): correct calculation of linkback property,
69
+ update og_descendants
70
+
71
+ * lib/n/og.rb (#enchant): more enchantments,
72
+ (#create_db!): introduced,
73
+ (#drop_db!): introduced,
74
+ (#pupdate!): enchant.
75
+
76
+ * lib/n/og/connection.rb (#select): added,
77
+ (#select_all): added, can use sql without select,
78
+ (#delete): it fuckin works and deletes descendants too!
79
+ (#transaction, #start, #commit, #rollback): working transaction
80
+ support,
81
+ removed all N::OgUtils.table crap.
82
+
83
+ 29-10-2004 George Moschovitis <gm@navel.gr>
84
+
85
+ * lib/n/og/backends/mysql.rb: introduced,
86
+ create_table works,
87
+ fuckin mega, insert works,
88
+ excellent, deserialize works,
89
+ (#valid?): implemented
90
+
91
+ * lib/n/og/backends/psql.rb: introduced,
92
+ yeah, i got a table created,
93
+ store Array,Hash,Object etc as text,
94
+ yeah, it inserts an object,
95
+ (#eval_og_deserialize): implemented,
96
+ (#map_fields): factored out.
97
+ (#valid?): implemented
98
+
99
+ * lib/n/og/managed.rb: introduced.
100
+
101
+ * lib/n/og/backend.rb: introduced,
102
+ different exec/query/safe_exec/safe_query.
103
+
104
+ * test/n/tc_og.rb: introduced.
105
+
106
+ * lib/n/og/connection.rb: introduced,
107
+ (#update_properties): introduced and works,
108
+ (#getxxxx): get methods work,
109
+ (#get_all): works.
110
+
111
+ * lib/n/og.rb: introduced the new O-R library a hybrid between
112
+ ndb and ActiveRecord,
113
+ (ManagedClassMeta): introduced,
114
+ (#enchant): nice :),
115
+ cool, use capitalize to get the Backend,
116
+ (#get_connection): use a thread-local variable,
117
+ (#put_connection): use a thread-local variable,
118
+ (#wrap_method): uses a connection from Thread.local,
119
+ (#convert): converts a normal object to a managed object,
120
+ (#manage): fixed bug with create_table,
121
+ (#enchant): YEAH, added the first enchantments :)
122
+
123
+ 28-10-2004 George Moschovitis <gm@navel.gr>
124
+
125
+ * lib/n/connection.rb (#create_schema, #drop_schema): removed.
126
+
127
+ * lib/n/managed.rb: fix in __db_read_row.
128
+
129
+ * lib/n/server/appserver.rb: show where app server is listening too.
130
+
131
+ * examples/simple/conf/*: greatly simplified configuration.
132
+
133
+ * lib/n/config.rb: moved many standard configurations
134
+ here.
135
+
136
+ 27-10-2004 George Moschovitis <gm@navel.gr>
137
+
138
+ * lib/n/db.rb: dont require utils and connection by default.
139
+
140
+ * lib/n/db/connection.rb (#count_children): use get_res_value,
141
+ greatly improved the organization and documentation.
142
+
143
+ * lib/n/db/mysql.rb: added latest psql fixes,
144
+ (#calc_fields): reimplemented,
145
+ (#get_res_value): introduced.
146
+
147
+ * test/n/tc_db_mysql.rb: many fixes.
148
+
149
+ * test/n/server/tc_filters.rb: added.
150
+
151
+ * lib/n/db/psql.rb (#retry_query): should raise after retries [b.candler],
152
+ (#retry_query, #next_oid): use //i in error checks [b.candler],
153
+ (#exec, #exec_clear): moved from connection,
154
+ removed PsqlBackend, overload DbConnection instead.
155
+
156
+ * MAJOR: removed the App namespace module from many many files.
157
+
158
+ * bin/new_project.rb: moved from etc/
159
+
160
+ * lib/n/server: renamed from app, more standard naming.
161
+
162
+ * lib/n/app/requestpart.rb: renamed.
163
+
164
+ * lib/n/app/webrick.rb: merged webrick-servlet.rb
165
+
166
+ * lib/n/server/PLAYBACK.txt: removed
167
+
168
+ * lib/n/server/RESEARCH.txt: removed
169
+
170
+ 26-10-2004 George Moschovitis <gm@navel.gr>
171
+
172
+ * lib/n/app/dispatcher.rb: introduced for experiments in design.
173
+
174
+ * lib/n/logger.rb: cleaned up formating with some Ruby magic.
175
+
176
+ * lib/n/shaders.rb (NilShader): name = nil for better dumps.
177
+
178
+ * lib/n/app/webrick-servlet.rb: alias :do_POST.
179
+
180
+ * Rakefile, added builder as required in the Gem.
181
+
182
+ * lib/n/app/handlers/page-handler.rb (#transform_script):
183
+ support <?rb as marker [c.nasis].
184
+
1
185
  25-10-2004 George Moschovitis <gm@navel.gr>
2
186
 
187
+ * --- VERSION 0.2.0 ---
188
+
3
189
  * test cases pass again.
4
190
 
5
191
  * lib/n/app/webrick-servlet.rb: fixed bug with default index,
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = Nitro
1
+ = Nitro 0.3.0
2
2
 
3
3
  Nitro is an efficient, yet simple engine for developing professional Web
4
4
  Applications using the Ruby language. Nitro aims to provide a robust
@@ -6,6 +6,8 @@ infrastructure for scalable web applications that can be distributed
6
6
  over a server cluster. However, Nitro can also power simple web
7
7
  applications for deployment on intranets or even personal computers.
8
8
 
9
+ Nitro integrated the powerful Og Object-Relational mapping library.
10
+
9
11
 
10
12
  == Features
11
13
 
@@ -62,17 +64,27 @@ A short summary of the major features:
62
64
  <!-- run time include (dynamic include) -->
63
65
  <x:include xl:href="myfile.si" />
64
66
 
67
+ * Minimum configuration
68
+
69
+ Configuration files are kept to the absolute minimum. The target
70
+ is to have no configuration files at all.
71
+
65
72
  * Object-Relational Mapping
66
73
 
67
- Nitro integrates the NDB object-relational mapping library. NDB
68
- provides transparent serialization of object graphs to a RDBMS
69
- backend. Unlike other similar libraries NDB maps standard Ruby
70
- objects to SQL tables and not vice versa. NDB provides a flexible
71
- and intuitive api for querieng the database, raw access to the
72
- SQL language if needed (for example to fine tune the automatically
73
- generated SQL tables, or for custom queries), suports deserialization
74
- to Ruby objects or tuples and provides a collection of usefull Mixins
75
- to synthesize common Entities.
74
+ Nitro integrates the Og (ObjectGraph) object-relational mapping
75
+ library. Og provides transparent serialization of object graphs to a RDBMS
76
+ backend. Unlike other similar libraries Og maps standard Ruby
77
+ objects to SQL tables and not vice versa. Og provides a meta language
78
+ to describe the relations between objects, a flexible and intuitive api
79
+ for querieng the database, raw access to the SQL language if needed
80
+ (for example to fine tune the automatically generated SQL tables, or
81
+ for custom queries), suports deserialization to Ruby objects or tuples
82
+ and provides a collection of usefull Mixins to synthesize common
83
+ Entities.
84
+
85
+ Og is a combination of the best features of Active Record and the
86
+ former O-R mapping library included in Nitro (NDB). Adapters for
87
+ PostgreSQL and MySQL are included.
76
88
 
77
89
  * Distributed State
78
90
 
@@ -172,11 +184,17 @@ Nitro requires the following applications or libraries:
172
184
  The following applications or libraries are optional:
173
185
 
174
186
  * PostgreSQL (http://www.postgres.org)
175
- Used for Database driven web applications
187
+ Used for Database driven web applications.
176
188
 
189
+ * MySQL (http://www.mysql.org)
190
+ Used for Database driven web applications.
191
+
177
192
  * Ruby-psql (http://www.postgresql.jp/interfaces/ruby/archive/ruby-postgres-0.7.1.tar.gz)
178
193
  Ruby interface to the PostgreSQL RDBMS.
179
194
 
195
+ * Ruby-mysql (http://tmtm.org/ja/ruby/mysql/README_en.html)
196
+ Ruby interface to the MySQL RDBMS.
197
+
180
198
  * Ruby-XSLT (http://gregoire.lejeune.free.fr/ruby-xslt_0.4.0.tar.gz)
181
199
  Used for XSLT based templates.
182
200
 
@@ -233,6 +251,17 @@ $ vi conf/config.rb
233
251
 
234
252
  edit the postgresql user and password
235
253
 
254
+ if you wan to run this application with MySQL
255
+ edit the configuration file to include
256
+
257
+ {
258
+ ...
259
+ :backend => "mysql"
260
+ ...
261
+ }
262
+
263
+ instead.
264
+
236
265
  run the following script to initialize the postgresql database used by
237
266
  the example
238
267
 
data/RELEASES CHANGED
@@ -1,10 +1,19 @@
1
+ == Version 0.3.0 was released on 01/11/2004.
2
+
3
+ An important revision! Nitro now includes the first version
4
+ of a brand new ObjectRelational mapping library called
5
+ Og (ObjectGraph) that combines the best features of Active
6
+ Record and NDB. A fully working MySQL adapter is also provided.
7
+ Moreover the code base is further cleaned up. Small improvements
8
+ to the application configuration system.
9
+
1
10
 
2
11
  == Version 0.2.0 was released on 25/10/2004.
3
12
 
4
13
  Greatly improved RDoc documentation. Cleaned up many source files,
5
14
  and improved the directory structure to be more compatible with
6
15
  other Ruby projects. Introduced a test suite. Important bug fixes
7
- in NDB. Tiny example no longer requires apache so sholud run out
16
+ in NDB. Tiny example no longer requires apache so should run out
8
17
  of the box.
9
18
 
10
19
 
data/Rakefile CHANGED
@@ -25,7 +25,7 @@ task :default => :package
25
25
 
26
26
  Rake::TestTask.new do |t|
27
27
  t.libs << "test"
28
- t.test_files = FileList["test/**/tc*.rb"].exclude("**/tc*db*.rb")
28
+ t.test_files = FileList["test/**/tc*.rb"].exclude("**/tc*og*.rb")
29
29
  t.verbose = true
30
30
  end
31
31
 
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  Rake::TestTask.new(:test_all) do |t|
35
35
  t.libs << "test"
36
- t.test_files = FileList["test/**/tc*.rb"].exclude("**/tc*mysql*.rb")
36
+ t.test_files = FileList["test/**/tc*.rb"]
37
37
  t.verbose = true
38
38
  end
39
39
 
@@ -66,8 +66,9 @@ spec = Gem::Specification.new do |s|
66
66
  s.version = PKG_VERSION
67
67
  s.summary = "Web Engine"
68
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")
69
+ # s.add_dependency("postgres", ">= 0.7.1")
70
+ # s.add_dependency("extensions", ">= 0.5")
71
+ # s.add_dependency("builder")
71
72
  s.required_ruby_version = ">= 1.8.1"
72
73
  s.files = PKG_FILES.to_a
73
74
  s.require_path = "lib"
data/bin/cluster.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: cluster.rb 104 2004-10-22 13:35:03Z gmosx $
5
+ # $Id: cluster.rb 112 2004-10-27 10:59:55Z gmosx $
6
6
 
7
7
  $:.unshift "lib"
8
8
 
@@ -12,7 +12,7 @@ require "monitor"
12
12
  require "n/application"
13
13
  require "n/server"
14
14
  require "n/utils/cache"
15
- require "n/app/session"
15
+ require "n/server/session"
16
16
 
17
17
  module N
18
18
 
@@ -202,7 +202,7 @@ class Cluster < N::Application
202
202
 
203
203
  def run
204
204
  N::Cluster::Clm.new
205
- DRb.start_service("druby://:8001", N::App::SessionManager.new)
205
+ DRb.start_service("druby://:8001", N::SessionManager.new)
206
206
 
207
207
  while true
208
208
  sleep(5000)
@@ -7,7 +7,7 @@
7
7
  # George Moschovitis <gm@navel.gr>
8
8
  #
9
9
  # (c) 2004 Navel, all rights reserved.
10
- # $Id: new-project.rb 86 2004-10-19 13:58:40Z gmosx $
10
+ # $Id: new_app.rb 112 2004-10-27 10:59:55Z gmosx $
11
11
  #++
12
12
 
13
13
  base_dir = ARGV[0]
@@ -0,0 +1,4 @@
1
+ = Og Example
2
+
3
+ A simple example that demonstrates some Og features. The example
4
+ automatically creates a 'test' database.
@@ -0,0 +1,254 @@
1
+ # = Og Example
2
+ #
3
+ # A simple example to demonstrate the Og library.
4
+ #
5
+ # code:
6
+ # * George Moschovitis <gm@navel.gr>
7
+ #
8
+ # (c) 2004 Navel, all rights reserved.
9
+ # $Id: run.rb 124 2004-11-01 12:34:17Z gmosx $
10
+
11
+ $:.unshift "../../lib"
12
+
13
+ require "n/std"
14
+ require "n/logger"
15
+ require "n/og"
16
+
17
+ # Full debug information.
18
+ $DBG = true
19
+
20
+ # = A child class
21
+ #
22
+ class Comment
23
+ prop_accessor String, :body
24
+
25
+ def initialize(body = nil)
26
+ @body = body
27
+ end
28
+
29
+ def to_s
30
+ return @body
31
+ end
32
+ end
33
+
34
+ # forward declaration
35
+ class ArticleComment < Comment; end
36
+
37
+ # forward declaration
38
+ class UserComment < Comment; end
39
+
40
+ # forward declaration
41
+ class Part; end
42
+
43
+ # = A Parent class
44
+ #
45
+ class User
46
+ prop_accessor String, :name
47
+
48
+ has_many UserComment, :comments
49
+
50
+ def initialize(name = nil)
51
+ @name = name
52
+ end
53
+
54
+ def to_s
55
+ return @name
56
+ end
57
+ end
58
+
59
+ # = A parent class
60
+ #
61
+ class Article
62
+ prop_accessor String, :title
63
+ prop_accessor String, :body
64
+ # override the default O->R mapping
65
+ prop_accessor Fixnum, "smallint DEFAULT 1", :level
66
+ # store a Ruby Hash in the Database. Marshal
67
+ # is used for serializing the attribute.
68
+ prop_accessor Hash, :options
69
+ prop_accessor Time, :create_time
70
+
71
+ # define comment relation:
72
+ has_many ArticleComment, :comments
73
+
74
+ has_many Part, :parts
75
+
76
+ # define author relation:
77
+ belongs_to User, :author
78
+
79
+ # this attribute is NOT stored in the db.
80
+ attr_accessor :other_options
81
+
82
+ # Managed object constructors with no args, take *args
83
+ # as parameter to allow for Mixin chaining.
84
+ #
85
+ def initialize(title = nil, body = nil)
86
+ @title, @body = title, body
87
+ @create_time = Time.now
88
+ @options = {}
89
+ @other_options = {}
90
+ end
91
+
92
+ def to_s
93
+ return "#@title: #@body"
94
+ end
95
+ end
96
+
97
+ # = Article comment
98
+ #
99
+ class ArticleComment < Comment
100
+ belongs_to Article, :article
101
+ end
102
+
103
+ # = User comment
104
+ #
105
+ class UserComment < Comment
106
+ belongs_to User, :author
107
+ end
108
+
109
+ # = Another child class
110
+ #
111
+ class Part
112
+ prop_accessor String, :name
113
+ belongs_to Article, :article
114
+
115
+ def initialize(name = nil)
116
+ @name = name
117
+ end
118
+
119
+ def to_s
120
+ return @name
121
+ end
122
+ end
123
+
124
+ # Initialize a logger.
125
+
126
+ $log = Logger.new(STDERR);
127
+
128
+ # Og configuration.
129
+ =begin
130
+ config = {
131
+ :address => "localhost",
132
+ :database => "test",
133
+ :backend => "psql",
134
+ :user => "postgres",
135
+ :password => "navelrulez",
136
+ :connection_count => 1
137
+ }
138
+ =end
139
+ config = {
140
+ :address => "localhost",
141
+ :database => "test",
142
+ :backend => "mysql",
143
+ :user => "root",
144
+ :password => "navelrulez",
145
+ :connection_count => 1
146
+ }
147
+
148
+ # Cleanup the database for earlier executions
149
+
150
+ N::Og.drop_db!(config)
151
+
152
+ # Initialize Og
153
+
154
+ $og = N::Og.new(config)
155
+
156
+ # Define the managed objects
157
+
158
+ $og.manage_classes(Article, User, ArticleComment, UserComment, Part)
159
+
160
+ # Get an Og connection for this thread.
161
+
162
+ $og.get_connection
163
+
164
+ # Create some articles
165
+
166
+ a1 = Article.new("Title1", "Body1")
167
+ a1.save!
168
+
169
+ a2 = Article.new("Title2", "Body2")
170
+ a2.save!
171
+
172
+ puts "\n\n"
173
+ puts "* Get and print all articles:"
174
+ articles = Article.all()
175
+ articles.each { |a| puts a }
176
+
177
+ # Create some comments
178
+
179
+ c1 = ArticleComment.new("Comment 1")
180
+ c1.article = a1
181
+ c1.save!
182
+
183
+ c2 = ArticleComment.new("Comment 2")
184
+ # alternative way to set the parent.
185
+ c2.article_oid = a1.oid
186
+ # an alternative way to save (add to the $og 'virtal collection' of
187
+ # managed objects).
188
+ $og << c2
189
+
190
+ c3 = ArticleComment.new("Comment 3")
191
+ c3.article = a1
192
+ c3.save!
193
+
194
+ puts "\n\n"
195
+ puts "* Print all all comments for article 1:"
196
+ a1.comments.each { |c| puts c }
197
+
198
+ # Most Og commands allow you to fine-tune the low level
199
+ # SQL code by passing extra_sql parameters, here is an
200
+ # example
201
+ puts "\n\n"
202
+ puts "* comments with sql finetunings:"
203
+ # use a standard SQL limit clause
204
+ a1.comments("LIMIT 2").each { |c| puts c }
205
+
206
+
207
+ # Change a managed object
208
+ a1.title = "Changed Title"
209
+ # Og knows that this is a managed object and executes
210
+ # an SQL UPDATE instead of an SQL INSERT
211
+ a1.save!
212
+
213
+ puts "\n\n"
214
+ Article.all.each { |a| puts a }
215
+
216
+ # The previous command updates the whole object. It is used
217
+ # when there are many updates or you dont care about speed.
218
+ # To update only specific fields use pupdate or properties_update
219
+ a2.pupdate! "title='A specific title'"
220
+
221
+ puts "\n\n"
222
+ Article.all.each { |a| puts a }
223
+
224
+ # delete an object
225
+ ArticleComment.delete(c3)
226
+
227
+ puts "\n\n"
228
+ ArticleComment.all.each { |a| puts a }
229
+
230
+
231
+ # Serialize a hash
232
+ a1.options = { "k1" => "val1", "k2" => "val2" }
233
+ a1.save!
234
+
235
+ # lookup an object
236
+ article = Article[a1.oid]
237
+
238
+ puts "\n\n"
239
+ puts article.options.inspect
240
+
241
+ u = User.new("gmosx")
242
+ u.save!
243
+
244
+ article = Article[1]
245
+ # you can also lookup by the name property.
246
+ article.author = User["gmosx"]
247
+ article.save!
248
+
249
+ part = Part.new("admin")
250
+ part.article = article
251
+ part.save!
252
+
253
+ article.parts.each { |pa| puts pa }
254
+