og 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/AUTHORS +14 -4
- data/ChangeLog +192 -1
- data/README.og +2 -1
- data/RELEASES.og +35 -0
- data/Rakefile +1 -1
- data/examples/og/mock_example.rb +6 -9
- data/examples/og/mysql_to_psql.rb +100 -0
- data/examples/og/run.rb +8 -17
- data/lib/glue/array.rb +1 -1
- data/lib/glue/attribute.rb +86 -0
- data/lib/glue/cache.rb +1 -1
- data/lib/glue/hash.rb +1 -1
- data/lib/glue/inflector.rb +1 -1
- data/lib/glue/logger.rb +118 -18
- data/lib/glue/mixins.rb +1 -1
- data/lib/glue/number.rb +1 -1
- data/lib/glue/pool.rb +1 -1
- data/lib/glue/property.rb +48 -31
- data/lib/glue/string.rb +1 -1
- data/lib/glue/time.rb +2 -2
- data/lib/glue/validation.rb +400 -0
- data/lib/glue.rb +7 -8
- data/lib/og/backend.rb +47 -46
- data/lib/og/backends/mysql.rb +64 -63
- data/lib/og/backends/psql.rb +73 -72
- data/lib/og/connection.rb +7 -8
- data/lib/og/enchant.rb +80 -0
- data/lib/og/meta.rb +21 -21
- data/lib/og/mock.rb +31 -88
- data/lib/og/version.rb +6 -5
- data/lib/og.rb +95 -129
- data/test/tc_og.rb +3 -3
- data/vendor/extensions/_base.rb +153 -0
- data/vendor/extensions/_template.rb +36 -0
- data/vendor/extensions/all.rb +21 -0
- data/vendor/extensions/array.rb +68 -0
- data/vendor/extensions/binding.rb +224 -0
- data/vendor/extensions/class.rb +50 -0
- data/vendor/extensions/continuation.rb +71 -0
- data/vendor/extensions/enumerable.rb +250 -0
- data/vendor/extensions/hash.rb +23 -0
- data/vendor/extensions/io.rb +58 -0
- data/vendor/extensions/kernel.rb +42 -0
- data/vendor/extensions/module.rb +114 -0
- data/vendor/extensions/numeric.rb +230 -0
- data/vendor/extensions/object.rb +164 -0
- data/vendor/extensions/ostruct.rb +41 -0
- data/vendor/extensions/string.rb +316 -0
- data/vendor/extensions/symbol.rb +28 -0
- metadata +24 -4
- data/lib/glue/property.rb.old +0 -307
data/AUTHORS
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
MAIN DEVELOPER:
|
2
2
|
|
3
3
|
* George Moschovitis <gm@navel.gr>
|
4
|
-
Project Leader, Architecture and Design, main coder,
|
5
|
-
maintainer.
|
4
|
+
Project Leader, Architecture and Design, main coder,
|
5
|
+
documentation, maintainer.
|
6
6
|
|
7
7
|
IDEAS, ADDITIONAL CODING, SUPPORT:
|
8
8
|
|
@@ -12,8 +12,18 @@ IDEAS, ADDITIONAL CODING, SUPPORT:
|
|
12
12
|
* Elias Athanasopoulos <elathan@navel.gr>
|
13
13
|
Additional coding.
|
14
14
|
|
15
|
-
*
|
16
|
-
|
15
|
+
* Gavin Sinclair <gsinclair@soyabean.com.au>
|
16
|
+
Logger#trace method.
|
17
|
+
|
18
|
+
* Thomas Quas <tquas@yahoo.com>
|
19
|
+
Ideas, bug reports, unit tests.
|
20
|
+
|
21
|
+
* Michael Neumann <mneumann@ntecs.de>
|
22
|
+
Ideas and bug reports.
|
17
23
|
|
18
24
|
* Kostas Nasis <kostas@nasis.com>
|
19
25
|
Ideas and bug reports.
|
26
|
+
|
27
|
+
* Elias Karakoulakis <ekarak@navel.gr>
|
28
|
+
Additional design.
|
29
|
+
|
data/ChangeLog
CHANGED
@@ -1,5 +1,196 @@
|
|
1
|
+
|
2
|
+
12-01-2005 George Moschovitis <gm@navel.gr>
|
3
|
+
|
4
|
+
* RELEASES.og: updated.
|
5
|
+
|
6
|
+
* RELEASES: updated.
|
7
|
+
|
8
|
+
* README: updated.
|
9
|
+
|
10
|
+
* README.og: updated.
|
11
|
+
|
12
|
+
* lib/glue/property.rb (#prop): include N::Validation when appending
|
13
|
+
a managed module.
|
14
|
+
|
15
|
+
* examples/blog/root/entr_form.xhtml: added error reporting.
|
16
|
+
|
17
|
+
* found out NASTY reload bug, temporarily dissabled!
|
18
|
+
|
19
|
+
* lib/glue/logger.rb: (Logger#error): added.
|
20
|
+
|
21
|
+
* lib/server/render.rb: improved source,
|
22
|
+
(#render): dissabled reloading.
|
23
|
+
(#redirect_referer): optional postfix.
|
24
|
+
|
25
|
+
* lib/nitro/markup.rb: fixed namespace,
|
26
|
+
(#expand/#compact): excluded wiki markup from default.
|
27
|
+
|
28
|
+
* examples/blog/config.rb: require markup, validation.
|
29
|
+
|
30
|
+
* examples/blog/root/style.xsl: <x:error> introduced.
|
31
|
+
|
32
|
+
* examples/blog/lib/blog.rb: extend from content,
|
33
|
+
use auto markup functionality,
|
34
|
+
thanks for the magic of auto markup, comments get
|
35
|
+
expanded correctly now, for free :),
|
36
|
+
(#new_entry): added validation/error reporting!
|
37
|
+
(#get_errors): useful prefilter,
|
38
|
+
(Common): made this a module (mixin).
|
39
|
+
|
40
|
+
11-01-2005 George Moschovitis <gm@navel.gr>
|
41
|
+
|
42
|
+
* test/glue/tc_validation.rb (#test_validate_length): implemented.
|
43
|
+
cooler, all tests pass.
|
44
|
+
|
45
|
+
* lib/glue/validation.rb (#validate_length): implemented,
|
46
|
+
allow sprintf style error messages,
|
47
|
+
(#validate_inclusion): implemented.
|
48
|
+
|
49
|
+
10-01-2005 George Moschovitis <gm@navel.gr>
|
50
|
+
|
51
|
+
* test/nitro/builders/tx_xhtml.rb: introduced,
|
52
|
+
yeah, cases pass :)
|
53
|
+
|
54
|
+
* lib/og/enchant.rb (#enchant): #one alias for #select_one [mneumann].
|
55
|
+
|
56
|
+
* lib/nitro/builders/xhtml.rb: introduced.
|
57
|
+
(#options): implemented,
|
58
|
+
(#select): implemented.
|
59
|
+
|
60
|
+
* lib/nitro/builders/xml.rb (#method_missing): added support
|
61
|
+
for blocks in tags,
|
62
|
+
(#comment): implemented.
|
63
|
+
|
64
|
+
09-01-2005 George Moschovitis <gm@navel.gr>
|
65
|
+
|
66
|
+
* test/nitro/builders/tc_xml.rb: introduced,
|
67
|
+
(#test_missing): implemented.
|
68
|
+
|
69
|
+
* lib/nitro/builders/xml.rb: introduced,
|
70
|
+
(#start_tag, #end_tag): implemented.
|
71
|
+
(#method_missing): implemented,
|
72
|
+
(XmlBuilder): implemented.
|
73
|
+
|
74
|
+
* vendor/blankslate.rb: integrated blankslate lib by
|
75
|
+
Jim Weirich <jim@weirichhouse.org> [jweirich].
|
76
|
+
|
77
|
+
08-01-2005 George Moschovitis <gm@navel.gr>
|
78
|
+
|
79
|
+
* lib/glue/vaildation.rb (#validate_confirmation): implemented,
|
80
|
+
(MetaLanguage): customization options,
|
81
|
+
(#validate_value): implemented,
|
82
|
+
|
83
|
+
07-01-2005 George Moschovitis <gm@navel.gr>
|
84
|
+
|
85
|
+
* test/glue/tc_validation.rb: implemented many tests.
|
86
|
+
|
87
|
+
* lib/glue/property.rb (#prop): auto include the N::Validation module
|
88
|
+
in the parent class if defined!
|
89
|
+
(PropertyUtils#get_prop): implemented.
|
90
|
+
|
91
|
+
* lib/glue/validation.rb (Validation::Errors): introduced,
|
92
|
+
empty, size, add methods.
|
93
|
+
recoded validation code and now works!
|
94
|
+
(eval_validate): fixed for multiple objects.
|
95
|
+
(Validation::Errors): keep error strings here.
|
96
|
+
(MetaLanguage): introduced.
|
97
|
+
MEGA: use meta :validations to store validations!
|
98
|
+
(Validation::Errors): each, clear.
|
99
|
+
|
100
|
+
05-01-2005 George Moschovitis <gm@navel.gr>
|
101
|
+
|
102
|
+
* test/*: cleaned up some unit tests.
|
103
|
+
|
104
|
+
* lib/*: removed all $log references!
|
105
|
+
|
106
|
+
* lib/glue/*: use N:: prefix for all files.
|
107
|
+
|
108
|
+
04-01-2005 George Moschovitis <gm@navel.gr>
|
109
|
+
|
110
|
+
* test/glue/tc_attribute.rb: implemented.
|
111
|
+
|
112
|
+
* lib/glue/attribute.rb: introduced,
|
113
|
+
default value for module/class attributes.
|
114
|
+
|
115
|
+
* lib/glue/validation.rb: introduced,
|
116
|
+
(Validation#validate_format): implemented.
|
117
|
+
(Validator): introduced,
|
118
|
+
(Validator#eval_validation_method): introduced.
|
119
|
+
|
120
|
+
* README: running units section.
|
121
|
+
|
122
|
+
03-01-2005 George Moschovitis <gm@navel.gr>
|
123
|
+
|
124
|
+
* lib/nitro/builders/form.rb (#render): emmit id's to make
|
125
|
+
the generated forms more style-able.
|
126
|
+
|
127
|
+
* lib/glue.rb: removed EMPTY_STRING constant [mneumann].
|
128
|
+
|
129
|
+
* Rakefile: include vendor in Og distribution.
|
130
|
+
|
131
|
+
02-01-2005 George Moschovitis <gm@navel.gr>
|
132
|
+
|
133
|
+
* vendor/extensions: integrated extensions library by
|
134
|
+
Gavin Sinclair <gsinclair@soyabean.com.au>
|
135
|
+
|
136
|
+
* test/glue/tc_logger.rb: introduced.
|
137
|
+
|
138
|
+
* lib/og.rb: removed logger methods.
|
139
|
+
|
140
|
+
* lib/glue/logger.rb: added static methods and global logger,
|
141
|
+
(#i, #d): removed.
|
142
|
+
(#trace): added trace method from dev-utils by
|
143
|
+
Gavin Sinclair <gsinclair@soyabean.com.au>,
|
144
|
+
fixed Binding.of_caller bug.
|
145
|
+
(#get): implemented.
|
146
|
+
|
147
|
+
01-01-2005 George Moschovitis <gm@navel.gr>
|
148
|
+
|
149
|
+
* started using the $:.unshift File.join trick.
|
150
|
+
|
151
|
+
30-12-2004 George Moschovitis <gm@navel.gr>
|
152
|
+
|
153
|
+
* lib/og/mock.rb: include Og::Enchant,
|
154
|
+
some more fixes to make this work.
|
155
|
+
|
156
|
+
* lib/og/enchant.rb: introduced, factors out some code used
|
157
|
+
by the MockDatabase.
|
158
|
+
|
159
|
+
* lib/og/*: converted to new code.
|
160
|
+
|
161
|
+
* lib/og/meta.rb: dont use $og. [mneumann]
|
162
|
+
|
163
|
+
* lib/og.rb: made Og a class,
|
164
|
+
removed $og_xx_xx options, use class methods [mneumann]
|
165
|
+
(Og##use): introduced.
|
166
|
+
(#enchant): use Og.db.connection.
|
167
|
+
(Database): create!/drop! aliases,
|
168
|
+
include Og::Enchant.
|
169
|
+
introduced Og.log.
|
170
|
+
|
171
|
+
29-12-2004 George Moschovitis <gm@navel.gr>
|
172
|
+
|
173
|
+
* lib/og/mysql.rb: removed Og::Utils, integrated methods in Backend.
|
174
|
+
|
175
|
+
* lib/og/psql.rb: removed Og::Utils, integrated methods in Backend.
|
176
|
+
|
177
|
+
* lib/og/backend.rb: removed Og::Utils, integrated methods in Backend,
|
178
|
+
to allow for multiple backend is one App [bcandler].
|
179
|
+
|
180
|
+
* lib/og.rb (#enchant): enchant methods DONT use $og anymmore. [mneumann]
|
181
|
+
|
182
|
+
* AUTHORS: updated.
|
183
|
+
|
184
|
+
* examples/og/mysql_to_psql.rb: introduced and implemented.
|
185
|
+
|
1
186
|
27-12-2004 George Moschovitis <gm@navel.gr>
|
2
187
|
|
188
|
+
* lib/parts/content.rb (CreateTime): introduced.
|
189
|
+
|
190
|
+
* lib/parts/README: introduced.
|
191
|
+
|
192
|
+
* --- VERSION 0.7.0 ---
|
193
|
+
|
3
194
|
* lib/og/mock.rb: fix, dont wrap methods.
|
4
195
|
|
5
196
|
* Rakefile: fix.
|
@@ -9,7 +200,7 @@
|
|
9
200
|
* lib/nitro/server/render.rb (#compile_xxx_method): better handling
|
10
201
|
of redirects,
|
11
202
|
(RenderExit): introduced,
|
12
|
-
(#redirect):
|
203
|
+
(#redirect): rewritten, raise RenderExit.
|
13
204
|
|
14
205
|
* lib/nitro/markup.rb (PropertyUtils#prop_setter): override.
|
15
206
|
(#markup): removed.
|
data/README.og
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Og 0.
|
1
|
+
= Og 0.8.0
|
2
2
|
|
3
3
|
Nitro integrates the Og (ObjectGraph) object-relational mapping
|
4
4
|
library. Og provides transparent serialization of object graphs to a RDBMS
|
@@ -40,6 +40,7 @@ The library provides the following features:
|
|
40
40
|
+ Transparent support for cascading deletes for all backends.
|
41
41
|
+ Hierarchical structures (preorder traversal, materialized paths)
|
42
42
|
+ Works safely as part of distributed application.
|
43
|
+
+ Automatic Validation/Constraints.
|
43
44
|
+ Simple implementation < 2k lines of code.
|
44
45
|
|
45
46
|
== Download
|
data/RELEASES.og
CHANGED
@@ -1,3 +1,38 @@
|
|
1
|
+
== Version 0.8 was released on 12/01/2005.
|
2
|
+
|
3
|
+
A snapshot of the latest code. Cool new features,
|
4
|
+
many fixes and improvements in older features. Many thanks
|
5
|
+
to Michael Neumann for giving intelligent suggestions
|
6
|
+
and finding small bugs.
|
7
|
+
|
8
|
+
Most notable additions:
|
9
|
+
|
10
|
+
* New automatic validation system:
|
11
|
+
|
12
|
+
class User
|
13
|
+
prop_accessor :name, :password, String
|
14
|
+
validate_confirmation :password
|
15
|
+
validate_length :name, :range => 2..12
|
16
|
+
end
|
17
|
+
|
18
|
+
u = User.new(...)
|
19
|
+
unless u.valid?
|
20
|
+
p u.errors.on(:name)
|
21
|
+
p u.errors[:password]
|
22
|
+
end
|
23
|
+
|
24
|
+
* No global variables in Og.
|
25
|
+
|
26
|
+
* Recoded Og to allow for future support of multiple databases
|
27
|
+
(even on different RDBMS systems) on a single application.
|
28
|
+
|
29
|
+
* cleaned up backend code.
|
30
|
+
|
31
|
+
* More unit tests.
|
32
|
+
|
33
|
+
* Supports Ruby 1.8.2
|
34
|
+
|
35
|
+
|
1
36
|
== Version 0.7 was released on 27/12/2004.
|
2
37
|
|
3
38
|
A snapshot of the latest code. Many fixes and new features result
|
data/Rakefile
CHANGED
@@ -91,7 +91,7 @@ else
|
|
91
91
|
PKG_FILES = FileList[
|
92
92
|
"README.og", "RELEASES.og", "LICENSE", "AUTHORS", "Rakefile", "ChangeLog*",
|
93
93
|
"examples/og/*", "lib/glue.rb", "lib/glue/**/*", "lib/og/**/*", "lib/og.rb",
|
94
|
-
"test/*og*.rb", "test/og/*"
|
94
|
+
"test/*og*.rb", "test/og/*", "vendor/extensions/**/*"
|
95
95
|
].exclude(".svn/**/*").exclude("**/*.log")
|
96
96
|
|
97
97
|
spec = Gem::Specification.new do |s|
|
data/examples/og/mock_example.rb
CHANGED
@@ -9,15 +9,12 @@
|
|
9
9
|
# (c) 2004 Navel, all rights reserved.
|
10
10
|
# $Id: run.rb 185 2004-12-10 13:29:09Z gmosx $
|
11
11
|
|
12
|
-
|
12
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
13
13
|
|
14
14
|
require 'rubygems'
|
15
15
|
require 'flexmock'
|
16
16
|
require 'og'
|
17
17
|
require 'og/mock'
|
18
|
-
require 'logger'
|
19
|
-
|
20
|
-
$log = Logger.new($stderr)
|
21
18
|
|
22
19
|
class Article
|
23
20
|
prop_accessor :body, String
|
@@ -30,11 +27,11 @@ end
|
|
30
27
|
class SimpleTest < Test::Unit::TestCase
|
31
28
|
|
32
29
|
def setup
|
33
|
-
|
30
|
+
@og = Og::MockDatabase.new
|
34
31
|
end
|
35
32
|
|
36
33
|
def teardown
|
37
|
-
|
34
|
+
@og = nil
|
38
35
|
end
|
39
36
|
|
40
37
|
def test_me
|
@@ -43,15 +40,15 @@ class SimpleTest < Test::Unit::TestCase
|
|
43
40
|
Article.new('body2'),
|
44
41
|
Article.new('body3')
|
45
42
|
]
|
46
|
-
|
43
|
+
@og.mock_handle(:load_all) { |klass, extrasql| mocks }
|
47
44
|
|
48
45
|
# differnt ways to call the mocked method...
|
49
46
|
puts 'Here are the articles:', Article.all
|
50
47
|
puts 'Here are the articles:', Article.load_all
|
51
|
-
puts 'Here are the articles:',
|
48
|
+
puts 'Here are the articles:', @og.load_all(Article)
|
52
49
|
|
53
50
|
# 3 times called
|
54
|
-
assert_equal(3,
|
51
|
+
assert_equal(3, @og.mock_count(:load_all))
|
55
52
|
end
|
56
53
|
|
57
54
|
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# = Og Mysql to PostgreSQL copy example
|
2
|
+
#
|
3
|
+
# A simple example to demonstrate the flexibility of
|
4
|
+
# Og. Two connections to different databases are
|
5
|
+
# created and data is copied from a MySQL database
|
6
|
+
# to a PostgreSQL database.
|
7
|
+
#
|
8
|
+
# Og makes it easier to switch to a REAL database :)
|
9
|
+
#
|
10
|
+
# code:
|
11
|
+
# * George Moschovitis <gm@navel.gr>
|
12
|
+
#
|
13
|
+
# (c) 2004 Navel, all rights reserved.
|
14
|
+
# $Id$
|
15
|
+
|
16
|
+
raise 'WARNING, this example does not work yet, for the moment ' +
|
17
|
+
'just have a look at the source code.'
|
18
|
+
|
19
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
20
|
+
|
21
|
+
require 'og'
|
22
|
+
|
23
|
+
# An example managed object.
|
24
|
+
# Looks like an ordinary Ruby object.
|
25
|
+
#
|
26
|
+
class Article
|
27
|
+
prop_accessor :name, :body, String
|
28
|
+
|
29
|
+
def initialize(name = nil, body = nil)
|
30
|
+
@name, @body = name, body
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Configure databases.
|
35
|
+
|
36
|
+
psql_config = {
|
37
|
+
:address => 'localhost',
|
38
|
+
:database => 'test',
|
39
|
+
:backend => 'psql',
|
40
|
+
:user => 'postgres',
|
41
|
+
:password => 'navelrulez',
|
42
|
+
:connection_count => 1
|
43
|
+
}
|
44
|
+
|
45
|
+
mysql_config = {
|
46
|
+
:address => 'localhost',
|
47
|
+
:database => 'mysql',
|
48
|
+
:backend => 'psql',
|
49
|
+
:user => 'postgres',
|
50
|
+
:password => 'navelrulez',
|
51
|
+
:connection_count => 1
|
52
|
+
}
|
53
|
+
=begin
|
54
|
+
mysql_config = {
|
55
|
+
:address => 'localhost',
|
56
|
+
:database => 'test',
|
57
|
+
:backend => 'mysql',
|
58
|
+
:user => 'root',
|
59
|
+
:password => 'navelrulez',
|
60
|
+
:connection_count => 1
|
61
|
+
}
|
62
|
+
=end
|
63
|
+
|
64
|
+
# Cleanup the databases, remove data from
|
65
|
+
# earlier executions.
|
66
|
+
|
67
|
+
Og::Database.drop!(psql_config)
|
68
|
+
Og::Database.drop!(mysql_config)
|
69
|
+
|
70
|
+
# Initialize Og.
|
71
|
+
|
72
|
+
psql = Og::Database.new(psql_config)
|
73
|
+
mysql = Og::Database.new(mysql_config)
|
74
|
+
|
75
|
+
# First populate the mysql database.
|
76
|
+
|
77
|
+
Og.use(mysql)
|
78
|
+
|
79
|
+
a1 = Article.create('name1', 'body1')
|
80
|
+
a1 = Article.create('name1', 'body1')
|
81
|
+
a1 = Article.create('name1', 'body1')
|
82
|
+
|
83
|
+
# Read all articles from Mysql.
|
84
|
+
|
85
|
+
articles = Article.all
|
86
|
+
|
87
|
+
# Switch to PostgreSQL.
|
88
|
+
|
89
|
+
Og.use(psql)
|
90
|
+
|
91
|
+
# Store all articles.
|
92
|
+
|
93
|
+
for article in articles
|
94
|
+
article.save!
|
95
|
+
end
|
96
|
+
|
97
|
+
# Fetch an article from PostgreSQL
|
98
|
+
# as an example. Lookup by name.
|
99
|
+
|
100
|
+
article = Article['name1']
|
data/examples/og/run.rb
CHANGED
@@ -8,10 +8,9 @@
|
|
8
8
|
# (c) 2004 Navel, all rights reserved.
|
9
9
|
# $Id: run.rb 198 2004-12-22 11:26:59Z gmosx $
|
10
10
|
|
11
|
-
$:.unshift
|
11
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
12
12
|
|
13
|
-
require
|
14
|
-
require "og"
|
13
|
+
require 'og'
|
15
14
|
|
16
15
|
# Full debug information.
|
17
16
|
$DBG = true
|
@@ -138,9 +137,6 @@ class Part
|
|
138
137
|
end
|
139
138
|
end
|
140
139
|
|
141
|
-
# Initialize a logger.
|
142
|
-
|
143
|
-
$log = Logger.new(STDERR);
|
144
140
|
# Og configuration.
|
145
141
|
config = {
|
146
142
|
:address => "localhost",
|
@@ -162,23 +158,19 @@ config = {
|
|
162
158
|
=end
|
163
159
|
# Cleanup the database for earlier executions
|
164
160
|
|
165
|
-
Og::Database.
|
161
|
+
Og::Database.drop!(config)
|
166
162
|
|
167
163
|
# Initialize Og
|
168
164
|
|
169
|
-
|
170
|
-
|
171
|
-
# Get an Og connection for this thread.
|
172
|
-
|
173
|
-
$og.get_connection
|
165
|
+
db = Og::Database.new(config)
|
174
166
|
|
175
167
|
# Create some articles
|
176
168
|
|
177
169
|
a1 = Article.new("Title1", "Body1")
|
178
170
|
a1.save!
|
179
171
|
|
180
|
-
|
181
|
-
a2.
|
172
|
+
# shortcut
|
173
|
+
a2 = Article.create("Title2", "Body2")
|
182
174
|
|
183
175
|
puts "\n\n"
|
184
176
|
puts "* Get and print all articles:"
|
@@ -194,9 +186,8 @@ c1.save!
|
|
194
186
|
c2 = ArticleComment.new("Comment 2")
|
195
187
|
# alternative way to set the parent.
|
196
188
|
c2.article_oid = a1.oid
|
197
|
-
# an alternative way to save
|
198
|
-
|
199
|
-
$og << c2
|
189
|
+
# an alternative way to save
|
190
|
+
db << c2
|
200
191
|
|
201
192
|
# an alternative (easier and cooler) way to add children in a
|
202
193
|
# has_many relation:
|
data/lib/glue/array.rb
CHANGED
@@ -0,0 +1,86 @@
|
|
1
|
+
# code:
|
2
|
+
# * George Moschovitis <gm@navel.gr>
|
3
|
+
#
|
4
|
+
# Original code from Rails distribution.
|
5
|
+
# http://www.rubyonrails.com
|
6
|
+
#
|
7
|
+
# $Id$
|
8
|
+
|
9
|
+
#--
|
10
|
+
# Extends the module object with module and instance accessors
|
11
|
+
# for class attributes, just like the native attr* accessors for
|
12
|
+
# instance attributes. Aliases for classes are also provided.
|
13
|
+
#
|
14
|
+
# Example:
|
15
|
+
#
|
16
|
+
# mattr_accessor :my_attr, 'Default value'
|
17
|
+
#++
|
18
|
+
class Module # :nodoc:
|
19
|
+
|
20
|
+
def mattr_reader(*params)
|
21
|
+
default = if params.last.is_a?(Symbol) then nil else params.pop end
|
22
|
+
|
23
|
+
|
24
|
+
for sym in params
|
25
|
+
module_eval <<-"end_eval", __FILE__, __LINE__
|
26
|
+
|
27
|
+
if not defined?(@@#{sym.id2name})
|
28
|
+
@@#{sym.id2name} = #{default.inspect}
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.#{sym.id2name}
|
32
|
+
@@#{sym}
|
33
|
+
end
|
34
|
+
|
35
|
+
def #{sym.id2name}
|
36
|
+
@@#{sym}
|
37
|
+
end
|
38
|
+
|
39
|
+
def call_#{sym.id2name}
|
40
|
+
case @@#{sym.id2name}
|
41
|
+
when Symbol then send(@@#{sym})
|
42
|
+
when Proc then @@#{sym}.call(self)
|
43
|
+
when String then @@#{sym}
|
44
|
+
else nil
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end_eval
|
49
|
+
end
|
50
|
+
end
|
51
|
+
alias_method :cattr_reader, :mattr_reader
|
52
|
+
|
53
|
+
def mattr_writer(*params)
|
54
|
+
default = if params.last.is_a?(Symbol) then nil else params.pop end
|
55
|
+
|
56
|
+
for sym in params
|
57
|
+
module_eval <<-"end_eval", __FILE__, __LINE__
|
58
|
+
|
59
|
+
if not defined?(@@#{sym.id2name})
|
60
|
+
@@#{sym.id2name} = #{default.inspect.inspect}
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.#{sym.id2name}=(obj)
|
64
|
+
@@#{sym.id2name} = obj
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.set_#{sym.id2name}(obj)
|
68
|
+
@@#{sym.id2name} = obj
|
69
|
+
end
|
70
|
+
|
71
|
+
def #{sym.id2name}=(obj)
|
72
|
+
@@#{sym} = obj
|
73
|
+
end
|
74
|
+
|
75
|
+
end_eval
|
76
|
+
end
|
77
|
+
end
|
78
|
+
alias_method :cattr_writer, :cattr_writer
|
79
|
+
|
80
|
+
def mattr_accessor(*syms)
|
81
|
+
mattr_reader(*syms)
|
82
|
+
mattr_writer(*syms)
|
83
|
+
end
|
84
|
+
alias_method :cattr_accessor, :mattr_accessor
|
85
|
+
|
86
|
+
end
|
data/lib/glue/cache.rb
CHANGED
data/lib/glue/hash.rb
CHANGED
data/lib/glue/inflector.rb
CHANGED