nitro 0.8.0 → 0.9.3

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 (198) hide show
  1. data/AUTHORS +3 -4
  2. data/ChangeLog +418 -0
  3. data/LICENSE +1 -1
  4. data/README +157 -89
  5. data/RELEASES +50 -0
  6. data/Rakefile +5 -7
  7. data/benchmark/nitro/bench.rb +5 -0
  8. data/benchmark/nitro/simple-webrick-n-200.txt +44 -0
  9. data/benchmark/nitro/static-webrick-n-200.txt +43 -0
  10. data/benchmark/nitro/tiny-lhttpd-n-200-c-5.txt +43 -0
  11. data/benchmark/nitro/tiny-webrick-n-200-c-5.txt +44 -0
  12. data/benchmark/nitro/tiny-webrick-n-200.txt +44 -0
  13. data/benchmark/nitro/tiny2-webrick-n-200.txt +44 -0
  14. data/{lib/nitro/server/cluster.rb → bin/cluster} +26 -30
  15. data/bin/proto/README +2 -2
  16. data/bin/proto/{apache.conf → conf/apache.conf} +0 -0
  17. data/bin/proto/conf/app.conf.rb +22 -0
  18. data/bin/proto/conf/lhttpd.conf +236 -0
  19. data/bin/proto/ctl +4 -0
  20. data/bin/proto/lib/README +5 -0
  21. data/bin/proto/log/README +3 -0
  22. data/bin/proto/root/fcgi.rb +6 -0
  23. data/bin/proto/root/index.xhtml +65 -7
  24. data/bin/proto/root/m/nitro.png +0 -0
  25. data/examples/blog/README +7 -5
  26. data/examples/blog/{apache.conf → conf/apache.conf} +0 -0
  27. data/examples/blog/conf/app.conf.rb +56 -0
  28. data/examples/blog/conf/lhttpd.conf +236 -0
  29. data/examples/blog/ctl +4 -0
  30. data/examples/blog/lib/blog.rb +11 -136
  31. data/examples/blog/lib/blog/controller.rb +99 -0
  32. data/examples/blog/lib/blog/model.rb +39 -0
  33. data/examples/blog/log/README +3 -0
  34. data/examples/blog/root/comments.xhtml +2 -2
  35. data/examples/blog/root/fcgi.rb +6 -0
  36. data/examples/blog/root/index.xhtml +4 -5
  37. data/examples/blog/root/login.xhtml +2 -2
  38. data/examples/blog/root/style.xsl +9 -9
  39. data/examples/blog/root/view_entry.xhtml +2 -2
  40. data/examples/flash/conf/app.conf.rb +23 -0
  41. data/examples/flash/ctl +4 -0
  42. data/examples/flash/log/README +3 -0
  43. data/examples/flash/root/index.xhtml +0 -9
  44. data/examples/flash/root/show_inline_text.xhtml +10 -5
  45. data/examples/no_xsl_blog/README +12 -0
  46. data/examples/no_xsl_blog/conf/apache.conf +0 -0
  47. data/examples/no_xsl_blog/conf/app.conf.rb +57 -0
  48. data/examples/no_xsl_blog/conf/lhttpd.conf +236 -0
  49. data/examples/no_xsl_blog/ctl +4 -0
  50. data/examples/no_xsl_blog/lib/blog.rb +20 -0
  51. data/examples/no_xsl_blog/lib/blog/controller.rb +102 -0
  52. data/examples/no_xsl_blog/lib/blog/model.rb +39 -0
  53. data/examples/no_xsl_blog/lib/blog/template.rb +134 -0
  54. data/examples/no_xsl_blog/log/README +3 -0
  55. data/examples/no_xsl_blog/root/comments.xhtml +41 -0
  56. data/examples/no_xsl_blog/root/entry_form.xhtml +22 -0
  57. data/examples/no_xsl_blog/root/fcgi.rb +6 -0
  58. data/examples/no_xsl_blog/root/index.xhtml +39 -0
  59. data/examples/no_xsl_blog/root/login.xhtml +21 -0
  60. data/examples/no_xsl_blog/root/m/bubbles.gif +0 -0
  61. data/examples/no_xsl_blog/root/m/comments_curve.gif +0 -0
  62. data/examples/no_xsl_blog/root/m/down.gif +0 -0
  63. data/examples/no_xsl_blog/root/m/footer_bg.gif +0 -0
  64. data/examples/no_xsl_blog/root/m/garrow.gif +0 -0
  65. data/examples/no_xsl_blog/root/m/gbull.gif +0 -0
  66. data/examples/no_xsl_blog/root/m/grbull.gif +0 -0
  67. data/examples/no_xsl_blog/root/m/h1_bg.gif +0 -0
  68. data/examples/no_xsl_blog/root/m/header_bg.gif +0 -0
  69. data/examples/no_xsl_blog/root/m/nitro.gif +0 -0
  70. data/examples/no_xsl_blog/root/m/obull.gif +0 -0
  71. data/examples/no_xsl_blog/root/m/page_bg.gif +0 -0
  72. data/examples/no_xsl_blog/root/m/rss.gif +0 -0
  73. data/examples/no_xsl_blog/root/m/side_title_bg.gif +0 -0
  74. data/examples/no_xsl_blog/root/m/sidebar_bg.gif +0 -0
  75. data/examples/no_xsl_blog/root/recent_posts.xhtml +14 -0
  76. data/examples/no_xsl_blog/root/style.css +301 -0
  77. data/examples/no_xsl_blog/root/view_entry.xhtml +25 -0
  78. data/examples/no_xsl_blog/root/view_entry.xml +12 -0
  79. data/examples/og/run.rb +2 -2
  80. data/examples/tiny/README +2 -2
  81. data/examples/tiny/conf/apache.conf +5 -0
  82. data/examples/tiny/conf/app.conf.rb +21 -0
  83. data/examples/tiny/conf/lhttpd.conf +236 -0
  84. data/examples/tiny/ctl +4 -0
  85. data/examples/tiny/log/README +3 -0
  86. data/examples/tiny/root/fcgi.rb +6 -0
  87. data/examples/tiny/root/index.xhtml +7 -4
  88. data/examples/tiny/root/nitro.png +0 -0
  89. data/lib/glue.rb +13 -9
  90. data/lib/glue/array.rb +1 -1
  91. data/lib/glue/cache.rb +1 -1
  92. data/lib/glue/flexob.rb +12 -0
  93. data/lib/glue/hash.rb +1 -1
  94. data/lib/glue/inflector.rb +2 -2
  95. data/lib/glue/logger.rb +4 -8
  96. data/lib/glue/misc.rb +14 -0
  97. data/lib/glue/number.rb +1 -1
  98. data/lib/glue/object.rb +26 -0
  99. data/lib/glue/pool.rb +1 -1
  100. data/lib/glue/property.rb +84 -91
  101. data/lib/glue/string.rb +1 -1
  102. data/lib/glue/time.rb +1 -1
  103. data/lib/glue/validation.rb +1 -1
  104. data/lib/nitro.rb +18 -6
  105. data/lib/nitro/adaptors/cgi.rb +291 -0
  106. data/lib/nitro/adaptors/fastcgi.rb +42 -0
  107. data/lib/nitro/adaptors/runner.rb +123 -0
  108. data/lib/nitro/adaptors/webrick.rb +110 -0
  109. data/lib/nitro/buffering.rb +43 -0
  110. data/lib/nitro/builders/form.rb +1 -1
  111. data/lib/nitro/builders/rss.rb +1 -1
  112. data/{bin → lib/nitro}/cluster.rb +26 -30
  113. data/lib/nitro/context.rb +82 -0
  114. data/lib/nitro/controller.rb +50 -0
  115. data/lib/nitro/cookie.rb +46 -0
  116. data/lib/nitro/dispatcher.rb +105 -0
  117. data/lib/nitro/filters.rb +9 -10
  118. data/lib/nitro/localization.rb +42 -0
  119. data/lib/nitro/mail.rb +11 -14
  120. data/lib/nitro/render.rb +275 -0
  121. data/lib/nitro/request.rb +128 -0
  122. data/lib/nitro/response.rb +38 -0
  123. data/lib/nitro/scaffold.rb +11 -11
  124. data/lib/nitro/session.rb +84 -0
  125. data/lib/nitro/{server/shaders.rb → shaders.rb} +56 -36
  126. data/lib/nitro/ui/pager.rb +23 -26
  127. data/lib/nitro/{sitemap.rb → ui/sitemap.rb} +4 -12
  128. data/lib/nitro/uri.rb +1 -1
  129. data/lib/nitro/version.rb +10 -8
  130. data/lib/og.rb +66 -65
  131. data/lib/og/backend.rb +1 -1
  132. data/lib/og/backends/mysql.rb +48 -52
  133. data/lib/og/backends/psql.rb +34 -37
  134. data/lib/og/connection.rb +15 -15
  135. data/lib/og/enchant.rb +16 -9
  136. data/lib/og/meta.rb +127 -54
  137. data/lib/og/mock.rb +18 -18
  138. data/lib/og/version.rb +6 -4
  139. data/lib/parts/content.rb +4 -8
  140. data/test/glue/tc_logger.rb +3 -0
  141. data/test/glue/tc_property.rb +19 -3
  142. data/test/nitro/adaptors/tc_cgi.rb +63 -0
  143. data/test/nitro/adaptors/tc_webrick.rb +15 -0
  144. data/test/nitro/builders/tc_xml.rb +2 -2
  145. data/test/nitro/tc_context.rb +13 -0
  146. data/test/nitro/tc_controller.rb +47 -0
  147. data/test/nitro/tc_dispatcher.rb +64 -0
  148. data/test/nitro/tc_session.rb +20 -0
  149. data/test/nitro/{tc_sitemap.rb → ui/tc_sitemap.rb} +1 -1
  150. data/test/root/blog/list.xhtml +6 -0
  151. data/test/tc_og.rb +41 -4
  152. metadata +115 -59
  153. data/bin/proto/app.rb +0 -20
  154. data/bin/proto/config.rb +0 -77
  155. data/examples/blog/app.rb +0 -21
  156. data/examples/blog/config.rb +0 -95
  157. data/examples/blog/env.rb +0 -22
  158. data/examples/flash/README +0 -34
  159. data/examples/flash/app.rb +0 -20
  160. data/examples/flash/config.rb +0 -38
  161. data/examples/flash/lib/flash.rb +0 -40
  162. data/examples/flash/tmp.swf +0 -0
  163. data/examples/tiny/app.rb +0 -19
  164. data/examples/tiny/config.rb +0 -29
  165. data/examples/tiny/root/nitro-small.png +0 -0
  166. data/lib/nitro/application.rb +0 -217
  167. data/lib/nitro/config.rb +0 -128
  168. data/lib/nitro/events.rb +0 -122
  169. data/lib/nitro/html.rb +0 -151
  170. data/lib/nitro/http.rb +0 -102
  171. data/lib/nitro/l10n.rb +0 -30
  172. data/lib/nitro/server.rb +0 -59
  173. data/lib/nitro/server/appserver.rb +0 -67
  174. data/lib/nitro/server/cookie.rb +0 -87
  175. data/lib/nitro/server/dispatcher.rb +0 -62
  176. data/lib/nitro/server/filters.rb +0 -75
  177. data/lib/nitro/server/filters/autologin.rb +0 -51
  178. data/lib/nitro/server/fragment.rb +0 -70
  179. data/lib/nitro/server/handlers.rb +0 -127
  180. data/lib/nitro/server/render.rb +0 -426
  181. data/lib/nitro/server/request.rb +0 -658
  182. data/lib/nitro/server/requestpart.rb +0 -54
  183. data/lib/nitro/server/script.rb +0 -387
  184. data/lib/nitro/server/server.rb +0 -57
  185. data/lib/nitro/server/session.rb +0 -220
  186. data/lib/nitro/server/user.rb +0 -46
  187. data/lib/nitro/server/webrick.rb +0 -180
  188. data/lib/nitro/service.rb +0 -26
  189. data/lib/xsl/ui.xsl +0 -51
  190. data/lib/xsl/xforms.xsl +0 -28
  191. data/test/nitro/server/tc_cookie.rb +0 -34
  192. data/test/nitro/server/tc_filters.rb +0 -38
  193. data/test/nitro/server/tc_request.rb +0 -70
  194. data/test/nitro/server/tc_requestpart.rb +0 -28
  195. data/test/nitro/server/tc_session.rb +0 -34
  196. data/test/nitro/tc_events.rb +0 -44
  197. data/test/nitro/tc_html.rb +0 -79
  198. data/test/nitro/tc_http.rb +0 -18
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
4
+ require 'nitro/adaptors/runner'
@@ -0,0 +1,3 @@
1
+ = Logs
2
+
3
+ Various logs come here.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'conf', 'app.conf.rb')
4
+ require 'nitro/adaptors/fastcgi'
5
+
6
+ N::FastCGI.start($conf)
@@ -5,7 +5,7 @@
5
5
  <?r
6
6
  # the code that populates the template comes here
7
7
 
8
- unless name = params['name']
8
+ unless name = context['name']
9
9
  name = 'World'
10
10
  end
11
11
 
@@ -16,12 +16,14 @@
16
16
  <!-- the template comes here -->
17
17
 
18
18
  <p>
19
- <img src="nitro-small.png" />
19
+ <img src="nitro.png" />
20
20
  </p>
21
21
 
22
22
 
23
23
  <strong>Hello #{name}</strong>
24
-
24
+ <!--
25
+ <p>#{context.headers.collect { |h| "#{h}<br/>" }}</p>
26
+ -->
25
27
  <p>
26
28
  <form id="my_form">
27
29
  <strong>Enter your name:</strong>
@@ -34,6 +36,7 @@
34
36
  Counter: #{session[:counter]}
35
37
  </p>
36
38
  <br />
37
- <?include href="include.xhtml"?>
39
+
40
+ <render href="include" />
38
41
 
39
42
  </html>
@@ -1,12 +1,10 @@
1
- # = Glue
2
- #
3
1
  # General libraries used by various projects.
4
2
  #
5
- # code:
6
- # * George Moschovitis <gm@navel.gr>
7
- #
3
+ #--
4
+ # George Moschovitis <gm@navel.gr>
8
5
  # (c) 2004-2005 Navel, all rights reserved.
9
- # $Id: glue.rb 175 2004-11-26 16:11:27Z gmosx $
6
+ # $Id: glue.rb 215 2005-01-24 10:44:05Z gmosx $
7
+ #++
10
8
 
11
9
  require 'English'
12
10
  require 'pp'
@@ -14,10 +12,15 @@ require 'pp'
14
12
  require 'glue/property'
15
13
  require 'glue/attribute'
16
14
 
15
+ # The standard namespace module.
16
+
17
+ module N; end
18
+
17
19
  class NilClass
20
+
18
21
  # quite usefull for error tolerant apps.
19
22
  # a bit dangerous? Will have to rethink this.
20
- #
23
+
21
24
  def empty?
22
25
  return true
23
26
  end
@@ -27,6 +30,7 @@ class Class
27
30
  #--
28
31
  # gmosx: is this really needed?
29
32
  #++
33
+
30
34
  def to_i
31
35
  return self.hash
32
36
  end
@@ -34,7 +38,7 @@ end
34
38
 
35
39
  module Kernel
36
40
 
37
- # pretty prints an exception/error object
41
+ # Pretty prints an exception/error object
38
42
  # usefull for helpfull debug messages
39
43
  #
40
44
  # Input:
@@ -42,7 +46,7 @@ module Kernel
42
46
  #
43
47
  # Output:
44
48
  # the pretty printed string
45
- #
49
+
46
50
  def pp_exception(ex)
47
51
  return %{#{ex.message}\n\tBACKTRACE:\n\t#{ex.backtrace.join("\n\t")}\n\tLOGGED FROM:\n\t#{caller[0]}}
48
52
  end
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2002-2003 Navel, all rights reserved.
5
- # $Id: array.rb 165 2004-11-18 12:04:04Z gmosx $
5
+ # $Id: array.rb 202 2005-01-17 10:44:13Z gmosx $
6
6
 
7
7
  require "sync"
8
8
 
@@ -3,7 +3,7 @@
3
3
  # * Anastasios Koutoumanos <ak@navel.gr>
4
4
  #
5
5
  # (c) 2004 Navel, all rights reserved.
6
- # $Id: cache.rb 167 2004-11-23 14:03:10Z gmosx $
6
+ # $Id: cache.rb 202 2005-01-17 10:44:13Z gmosx $
7
7
 
8
8
  module N;
9
9
 
@@ -0,0 +1,12 @@
1
+ # * George Moschovitis <gm@navel.gr>
2
+ # (c) 2004-2005 Navel, all rights reserved.
3
+ # $Id$
4
+
5
+ require 'ostruct'
6
+
7
+ # A flexible Object.
8
+ # Temporarily implemented as a simple OpenStruct.
9
+
10
+ class Flexob < OpenStruct
11
+
12
+ end
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: hash.rb 167 2004-11-23 14:03:10Z gmosx $
5
+ # $Id: hash.rb 202 2005-01-17 10:44:13Z gmosx $
6
6
 
7
7
  require "sync"
8
8
 
@@ -44,13 +44,13 @@ module Inflector
44
44
  end
45
45
 
46
46
  # Convert a class to a name.
47
- #
47
+
48
48
  def name(klass)
49
49
  Inflector.underscore(Inflector.demodulize(klass.to_s))
50
50
  end
51
51
 
52
52
  # Convert a class to a name in plural
53
- #
53
+
54
54
  def plural_name(klass)
55
55
  Inflector.pluralize(Inflector.underscore(Inflector.demodulize(klass.to_s)))
56
56
  end
@@ -1,16 +1,12 @@
1
- # code:
2
1
  # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
5
- # $Id: logger.rb 161 2004-11-18 10:51:51Z gmosx $
2
+ # (c) 2004-2005 Navel, all rights reserved.
3
+ # $Id: logger.rb 248 2005-01-31 13:38:34Z gmosx $
6
4
 
7
5
  require 'logger'
8
6
 
9
- # = Logger
10
- #
11
7
  # A simple wrapper arround the Ruby logger. Mainly for
12
8
  # compatibility purposes.
13
- #
9
+
14
10
  class Logger
15
11
  alias_method :devel, :debug
16
12
  alias_method :fine, :debug
@@ -42,7 +38,7 @@ class Logger
42
38
  #
43
39
  # This code comes straight from the dev-utils Gem.
44
40
  # Author: Gavin Sinclair <gsinclair@soyabean.com.au>
45
- #
41
+
46
42
  def trace(expr, style=:p)
47
43
  unless expr.respond_to? :to_str
48
44
  warn "trace: Can't evaluate the given value: #{caller.first}"
@@ -0,0 +1,14 @@
1
+ # * George Moschovitis <gm@navel.gr>
2
+ # (c) 2004-2005 Navel, all rights reserved.
3
+ # $Id$
4
+
5
+ # Executes a Ruby block without warnings.
6
+
7
+ def silence_warnings
8
+ old_verbose, $VERBOSE = $VERBOSE, nil
9
+ begin
10
+ yield
11
+ ensure
12
+ $VERBOSE = old_verbose
13
+ end
14
+ end
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: number.rb 167 2004-11-23 14:03:10Z gmosx $
5
+ # $Id: number.rb 202 2005-01-17 10:44:13Z gmosx $
6
6
 
7
7
  module N;
8
8
 
@@ -0,0 +1,26 @@
1
+ # $Id$
2
+
3
+ class Object #:nodoc:
4
+ def remove_subclasses_of(superclass)
5
+ subclasses_of(superclass).each { |subclass| Object.send(:remove_const, subclass) rescue nil }
6
+ end
7
+
8
+ def subclasses_of(superclass)
9
+ subclasses = []
10
+ ObjectSpace.each_object(Class) do |k|
11
+ next if !k.ancestors.include?(superclass) || superclass == k || k.to_s.include?("::") || subclasses.include?(k.to_s)
12
+ subclasses << k.to_s
13
+ end
14
+ subclasses
15
+ end
16
+ end
17
+
18
+ class Class #:nodoc:
19
+ def remove_subclasses
20
+ Object.remove_subclasses_of(self)
21
+ end
22
+
23
+ def subclasses
24
+ Object.subclasses_of(self)
25
+ end
26
+ end
@@ -2,7 +2,7 @@
2
2
  # * George Moschovitis <gm@navel.gr>
3
3
  #
4
4
  # (c) 2004 Navel, all rights reserved.
5
- # $Id: pool.rb 167 2004-11-23 14:03:10Z gmosx $
5
+ # $Id: pool.rb 202 2005-01-17 10:44:13Z gmosx $
6
6
 
7
7
  require "thread"
8
8
  require "monitor"
@@ -1,21 +1,19 @@
1
- # code:
2
1
  # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
5
- # $Id: property.rb 200 2004-12-27 11:24:41Z gmosx $
2
+ # * Michael Neumann <mneumann@ntecs.de>
3
+ # (c) 2004-2005 Navel, all rights reserved.
4
+ # $Id: property.rb 248 2005-01-31 13:38:34Z gmosx $
6
5
 
7
6
  require 'glue/array'
8
7
  require 'glue/hash'
9
8
 
10
9
  module N
11
10
 
12
- # = Property
13
- #
14
- # Ruby attributes are typeless and generally this is good. Some times
15
- # we need extra metadata though, for example in relational mapping,
16
- # or web form population.
11
+ # Ruby attributes are typeless and generally this is good.
12
+ # Some times we need extra metadata though, for example in
13
+ # relational mapping, or web form population.
17
14
  #
18
- # Only Fixnums, Strings, Floats, Times, Booleans are converted.
15
+ # Only Fixnums, Strings, Floats, Times, Booleans are
16
+ # converted.
19
17
  #
20
18
  # The default = methods do not force the types. A special
21
19
  # __force_set method should be used instead.
@@ -24,14 +22,23 @@ module N
24
22
  # TODO:
25
23
  # Perhaps a sync is needed in evals (!!!!)
26
24
  #++
25
+
27
26
  class Property
27
+
28
28
  # the symbol of the property
29
+
29
30
  attr_accessor :symbol
31
+
30
32
  # the string representation of the symbol
33
+
31
34
  attr_accessor :name
35
+
32
36
  # the class of the property
37
+
33
38
  attr_accessor :klass
39
+
34
40
  # additional metadata (like sql declaration, sql index, etc)
41
+
35
42
  attr_accessor :meta
36
43
 
37
44
  def initialize(symbol, klass, meta = {})
@@ -53,7 +60,7 @@ end
53
60
  # = PropertyUtils
54
61
  #
55
62
  # A collection of Property related utility methods.
56
- #
63
+
57
64
  module PropertyUtils
58
65
 
59
66
  # Add accessors to the properties to the given target
@@ -65,6 +72,7 @@ module PropertyUtils
65
72
  #--
66
73
  # gmosx: Perhaps we 'll optimize this in the future.
67
74
  #++
75
+
68
76
  def self.enchant(target, force = false)
69
77
  unless target.singleton_methods.include?('__props')
70
78
  target.module_eval <<-"end_eval", __FILE__, __LINE__
@@ -91,7 +99,7 @@ module PropertyUtils
91
99
  end
92
100
 
93
101
  # Copy properties from src (Module or Class) to dest.
94
- #
102
+
95
103
  def self.copy_props(src, dest)
96
104
  src.__props.each do |p|
97
105
  add_prop(dest, p)
@@ -105,7 +113,7 @@ module PropertyUtils
105
113
  end
106
114
 
107
115
  # Add the property to the target (Class or Module)
108
- #
116
+
109
117
  def self.add_prop(target, prop)
110
118
  if idx = target.__props.index(prop)
111
119
  # override in case of duplicates. Keep the order of the props.
@@ -128,6 +136,7 @@ module PropertyUtils
128
136
 
129
137
  # gmosx: __force_xxx reuses xxx= to allow for easier
130
138
  # overrides.
139
+
131
140
  if prop.meta[:writer]
132
141
  target.module_eval %{
133
142
  #{prop_setter(prop)}
@@ -154,7 +163,7 @@ module PropertyUtils
154
163
 
155
164
  # Generates the property setter code. Can be overriden
156
165
  # to support extra functionality (example: markup)
157
- #
166
+
158
167
  def self.prop_setter(prop)
159
168
  s = prop.symbol
160
169
  %{
@@ -165,11 +174,53 @@ module PropertyUtils
165
174
  end
166
175
 
167
176
  # Get the property metadata for the given symbol.
168
- #
177
+
169
178
  def self.get_prop(klass, sym)
170
179
  return klass.__props.find { |p| p.symbol == sym }
171
180
  end
172
181
 
182
+ # Include meta-language mixins
183
+
184
+ def self.include_meta_mixins(target)
185
+ target.module_eval %{ include N::Validation } if defined?(N::Validation)
186
+ # gmosx: TODO, make Og::MetaLanguage equivalent to Validation.
187
+ target.module_eval %{ extend Og::MetaLanguage } if defined?(Og::MetaLanguage)
188
+ end
189
+
190
+ # Resolves the parameters passed to the propxxx macros
191
+ # to generate the meta, klass and symbols variables. This
192
+ # way the common functionality is factored out.
193
+ #
194
+ # [+params+]
195
+ # The params to resolve.
196
+ # [+one_symbol+]
197
+ # If true, only resolves one symbol (used in prop).
198
+
199
+ def self.resolve_prop_params(*params)
200
+ meta = {}
201
+ klass = Object
202
+ symbols = []
203
+
204
+ for param in params.flatten
205
+ if param.is_a?(Class)
206
+ klass = param
207
+ elsif param.is_a?(Symbol)
208
+ symbols << param
209
+ elsif param.is_a?(TrueClass) or param.is_a?(TrueClass)
210
+ writer = param
211
+ elsif param.is_a?(Hash)
212
+ # the meta hash.
213
+ meta.update(param) { |k, a, b| [a,b].join(' ') }
214
+ else
215
+ raise 'Error when defining property!'
216
+ end
217
+ end
218
+
219
+ raise 'No symbols provided!' if symbols.empty?
220
+
221
+ return meta, klass, symbols
222
+ end
223
+
173
224
  end
174
225
 
175
226
  end # module
@@ -188,33 +239,19 @@ class Module
188
239
  # --> creates only writer.
189
240
  # prop Fixnum, :oid, writer = true, :sql => "integer PRIMARY KEY"
190
241
  # --> creates reader and writer.
191
- #
242
+
192
243
  def prop(*params)
193
-
194
- meta = {}
195
- klass = Object
196
-
197
- for param in params
198
- if param.is_a?(Class)
199
- klass = param
200
- elsif param.is_a?(Symbol)
201
- symbol = param
202
- elsif param.is_a?(TrueClass) or param.is_a?(TrueClass)
203
- writer = param
204
- elsif param.is_a?(Hash)
205
- # the meta hash.
206
- meta = param
207
- else
208
- raise "Error when defining property!"
209
- end
210
- end
244
+ meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
245
+ symbol = symbols.first
211
246
 
247
+
212
248
  N::PropertyUtils.enchant(self)
213
249
 
214
250
  if self.is_a?(Class)
215
251
 
216
252
  # Add some extra code to append features to
217
253
  # subclasses.
254
+
218
255
  self.module_eval <<-"end_eval", __FILE__, __LINE__
219
256
 
220
257
  def self.inherited(sub)
@@ -231,17 +268,17 @@ class Module
231
268
 
232
269
  # Add some extra code for modules to append
233
270
  # their features to classes that include it.
271
+
234
272
  self.module_eval <<-"end_eval", __FILE__, __LINE__
235
273
 
236
274
  def self.append_features(base)
237
275
  N::PropertyUtils.enchant(base)
238
276
  N::PropertyUtils.copy_props(self, base)
277
+
239
278
  # gmosx: We have to define @@__props first to avoid reusing
240
279
  # the hash from the module. super must stay at the end.
241
-
242
- unless base.included_modules.include?(N::Validation)
243
- base.module_eval %{ include N::Validation }
244
- end if defined?(N::Validation)
280
+
281
+ N::PropertyUtils.include_meta_mixins(base)
245
282
 
246
283
  super
247
284
  end
@@ -265,7 +302,8 @@ class Module
265
302
  N::PropertyUtils.add_prop(self, property)
266
303
 
267
304
  # gmosx: should be placed AFTER enchant!
268
- module_eval %{ include N::Validation } if defined?(N::Validation)
305
+
306
+ N::PropertyUtils.include_meta_mixins(self)
269
307
  end
270
308
 
271
309
  # Helper method. Accepts a collection of symbols and generates
@@ -273,24 +311,9 @@ class Module
273
311
  #
274
312
  # Example:
275
313
  # prop_reader String, :name, :title, :body, :sql => "char(32)"
276
- #
314
+
277
315
  def prop_reader(*params)
278
- meta = {}
279
- klass = Object
280
- symbols = []
281
-
282
- for param in params
283
- if param.is_a?(Class)
284
- klass = param
285
- elsif param.is_a?(Symbol)
286
- symbols << param
287
- elsif param.is_a?(Hash)
288
- # the meta hash.
289
- meta = param
290
- else
291
- raise "Error when defining property!"
292
- end
293
- end
316
+ meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
294
317
 
295
318
  meta[:reader] = true
296
319
  meta[:writer] = false
@@ -305,25 +328,10 @@ class Module
305
328
  #
306
329
  # Example:
307
330
  # prop_writer String, :name, :title, :body, :sql => "char(32)"
308
- #
331
+
309
332
  def prop_writer(*params)
310
- meta = {}
311
- klass = Object
312
- symbols = []
333
+ meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
313
334
 
314
- for param in params
315
- if param.is_a?(Class)
316
- klass = param
317
- elsif param.is_a?(Symbol)
318
- symbols << param
319
- elsif param.is_a?(Hash)
320
- # the meta hash.
321
- meta = param
322
- else
323
- raise 'Error when defining property!'
324
- end
325
- end
326
-
327
335
  meta[:reader] = false
328
336
  meta[:writer] = true
329
337
 
@@ -337,25 +345,10 @@ class Module
337
345
  #
338
346
  # Example:
339
347
  # prop_accessor String, :name, :title, :body, :sql => "char(32)"
340
- #
348
+
341
349
  def prop_accessor(*params)
342
- meta = {}
343
- klass = Object
344
- symbols = []
350
+ meta, klass, symbols = N::PropertyUtils.resolve_prop_params(params)
345
351
 
346
- for param in params
347
- if param.is_a?(Class)
348
- klass = param
349
- elsif param.is_a?(Symbol)
350
- symbols << param
351
- elsif param.is_a?(Hash)
352
- # the meta hash.
353
- meta = param
354
- else
355
- raise "Error when defining property!"
356
- end
357
- end
358
-
359
352
  meta[:reader] = true
360
353
  meta[:writer] = true
361
354
 
@@ -371,6 +364,7 @@ class Module
371
364
  #--
372
365
  # gmosx: crappy implementation, recode.
373
366
  #++
367
+
374
368
  def meta(key, val)
375
369
  self.module_eval <<-"end_eval", __FILE__, __LINE__
376
370
  @@__meta[key] ||= []
@@ -380,4 +374,3 @@ class Module
380
374
  end
381
375
 
382
376
  end
383
-