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
@@ -1,30 +0,0 @@
1
- # = L10N, Localization support
2
- #
3
- # code: gmosx
4
- #
5
- # (c) 2002-2003 Navel, all rights reserved.
6
- # $Id: l10n.rb 185 2004-12-10 13:29:09Z gmosx $
7
-
8
- require 'nitro/filters'
9
-
10
- $lc_en = {}
11
- $lc_el = {}
12
-
13
- # = Configuration
14
- #
15
- # Override as needed in your application.
16
- #
17
- $lc_map = {
18
- "en" => $lc_en,
19
- "el" => $lc_el
20
- }
21
-
22
- # The locales to use for this application.
23
- $lc_use = %w{lc-en lc-el}
24
-
25
- module LocalizationFilter
26
- def localize
27
- @lc = @session[:LC] || $lc_en
28
- end
29
- end
30
-
@@ -1,59 +0,0 @@
1
- # code:
2
- # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
5
- # $Id: server.rb 155 2004-11-13 20:32:12Z gmosx $
6
-
7
- require "nitro/application"
8
-
9
- module N
10
-
11
- # = Server
12
- #
13
- # Base server class, provides generic server
14
- # infrastructure.
15
- #
16
- class Server < N::Application
17
- # the listening address/port for this server.
18
- attr_reader :address, :port
19
-
20
- def initialize(name = "Server")
21
- super
22
- end
23
-
24
- # Start the server
25
- #
26
- def start
27
- super
28
- end
29
-
30
- # Stop the server
31
- #
32
- def stop
33
- super
34
- end
35
-
36
- # The main server loop
37
- #
38
- def run
39
- begin
40
- while :RUNNING == @status
41
- if live = IO.select(@ios, nil, nil, 2.0)
42
-
43
- end
44
- end
45
- rescue
46
-
47
- end
48
- end
49
-
50
- # Override this method in your custom server. This method is very
51
- # flexible, you can spawn threads, use keep alive connections,
52
- # handle+close, use handler pools, anything.
53
- #
54
- def handle
55
- end
56
-
57
- end
58
-
59
- end # module
@@ -1,67 +0,0 @@
1
- # code:
2
- # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
5
- # $Id: appserver.rb 167 2004-11-23 14:03:10Z gmosx $
6
-
7
- require "drb"
8
-
9
- require "nitro/application"
10
- require "nitro/server"
11
- require "nitro/server/session"
12
-
13
- module N
14
-
15
- # = ServerMixin
16
- #
17
- # Usefull application server related methods.
18
- #
19
- module AppServerMixin
20
-
21
- def initialize_app
22
-
23
- if $drb_state
24
- # Cluster mode: use distributed Ruby objects.
25
- $lm = N::Cluster::Slm.new($drb_lm_server, "druby://:8000")
26
- $sessions = DRbObject.new(nil, $drb_sessions_cluster)
27
- else
28
- # NoCluster mode: use standard Ruby onjects.
29
- $lm = N::SafeHash.new
30
- $sessions = N::SessionManager.new
31
- end
32
-
33
- # initialize app
34
- initialize_sitemap()
35
- initialize_shaders()
36
- initialize_events()
37
- end
38
-
39
- def initialize_sitemap
40
- end
41
-
42
- def initialize_shaders
43
- end
44
-
45
- def initialize_events
46
- end
47
- end
48
-
49
- # = AppServer
50
- #
51
- # The Application Server. Handles dynamic requests in a web application.
52
- # Dont keepalive (or use a VERY SMALL keepalive). Typically this server
53
- # is used along with a standars http server that handles other resources.
54
- #
55
- class AppServer < N::Server
56
- include N::AppServerMixin
57
-
58
- def initialize(name = "AppServer")
59
- super
60
- initialize_app()
61
-
62
- Logger.info "Web Server listening at #$srv_url"
63
- Logger.info "App Server listening at http://#$appsrv_address:#$appsrv_port"
64
- end
65
- end
66
-
67
- end # module
@@ -1,87 +0,0 @@
1
- # code:
2
- # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
5
- # $Id: cookie.rb 112 2004-10-27 10:59:55Z gmosx $
6
-
7
- require "cgi"
8
-
9
- class CGI
10
-
11
- # Override the default class.
12
-
13
- class Cookie
14
-
15
- =begin
16
- # Override default implementation to convert a single value
17
- # array to a simple value.
18
-
19
- def value
20
- val = @value
21
-
22
- if 1 == val.size
23
- return val.first
24
- else
25
- return val
26
- end
27
- end
28
- =end
29
-
30
- end
31
-
32
- end # class CGI
33
-
34
- module N
35
-
36
- # = Cookie
37
- #
38
- # An encapsulation of the standard HTTP Cookie.
39
- #
40
- # === Design
41
- #
42
- # Ruby's default cgi library implements the functionality,
43
- # so we reuse it here!
44
- #
45
- # The http request contains only key/values pairs so we
46
- # dont keep a full object.
47
- #
48
- # === Future
49
- #
50
- # - switch to libapreq!
51
- #
52
- class Cookie < CGI::Cookie
53
-
54
- # Override default implementation
55
- #
56
- def initialize(name, *value)
57
- super
58
-
59
- # this is a temporal fix! We should switch to libapreq,
60
- # or a custom implementation anyway, because cgi.rb
61
- # sucks.
62
- @path = "/"
63
- end
64
-
65
- # parse:
66
- # parses cookies from a header string
67
- #
68
- # Example cookie string, all cookies in one line separated by ;
69
- #
70
- # Cookie: nsid=293230807; nauth=gmosx:meMXs0ifW7JBQ; multi=123&456
71
- #
72
- # Input:
73
- # the header string
74
- # Output:
75
- # a hash object containing key-values pairs. notice that multiple
76
- # values can be assigned to one key, so values is an array. The
77
- # separator for mulriple values is '&'
78
- #
79
- # uses the default CGI implementation
80
- #
81
- # === Todo:
82
- #
83
- # - change this to return an array of Cookie objects!
84
-
85
- end
86
-
87
- end # module
@@ -1,62 +0,0 @@
1
- # code:
2
- # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
5
- # $Id: dispatcher.rb 200 2004-12-27 11:24:41Z gmosx $
6
-
7
- require 'nitro/server/render'
8
-
9
- module N
10
-
11
- # = Dispatcher
12
- #
13
- module Dispatcher
14
- include N::Render
15
-
16
- def process(request, response)
17
- begin
18
- # gmosx, INVESTIGATE: this is not really needed.
19
- $og.get_connection if $og
20
-
21
- session = create_session(request, response)
22
- render(request.request_uri.path, request, response, session)
23
- response.body = @out
24
- rescue Exception, StandardError => e
25
- Logger.error "error while handling the request #{request.request_uri}"
26
- Logger.error pp_exception(e)
27
-
28
- if $error_page_url
29
- # gmosx: SOS: TEST ME!
30
- # internal redirect to error page.
31
- request.request_uri.path = $error_page_url
32
- retry
33
- else
34
- # no custom error page defined. Presen a simple yet
35
- # useful error screen.
36
- response.header['Content-Type'] = 'text/html'
37
- body = %{
38
- <h1>ERROR</h1>
39
- <p>Click <a href="#{request.referer}">here</a> to return
40
- to the previous page.</p>
41
- }
42
- if @rendering_errors
43
- body << %{
44
- <h3>Rendering errors</h3>
45
- <pre>#{@rendering_errors.join("\n")}</pre>
46
- }
47
- end
48
- body << %{
49
- <h3>Exception</h3>
50
- <pre>#{pp_exception(e)}</pre>
51
- }
52
- response.body = body
53
- end
54
- ensure
55
- $og.put_connection if $og
56
- end
57
- end
58
-
59
- end
60
-
61
- end # module
62
-
@@ -1,75 +0,0 @@
1
- # code:
2
- # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 20024 Navel, all rights reserved.
5
- # $Id: filters.rb 133 2004-11-10 19:08:29Z gmosx $
6
-
7
- require "socket"
8
- require "thread"
9
- require "sync"
10
-
11
- module N
12
-
13
- # == Filter
14
- #
15
- # A server serves client requests by feeding the request/request pair
16
- # to a pipeline of processing filters. This is not a simple linear pipeline.
17
- # Instead it is what we call a 'folding' (hierarchical) pipeline: each
18
- # filter encapsulates the next. In effect, the pipeline is a generalized
19
- # filter!
20
- #
21
- # === Design:
22
- #
23
- # Filters are NOT singleton classes. This way we can assign one filter
24
- # class to multiple resources, and keep statistics and metrics for
25
- # each resource.
26
- # A filter may contain state (attributes) for example metrics.
27
- #
28
- class ServerFilter
29
- # the next filter in the pipeline.
30
- attr_reader :next_filter
31
-
32
- # set the filters next.
33
- #
34
- # example:
35
- # LogFilter.new(TimeFilter.new(PageFilter.new))
36
- #
37
- def initialize(next_filter = nil)
38
- @next_filter = next_filter
39
- end
40
-
41
- # set the filters next (next_filter).
42
- #
43
- # example:
44
- # LogFilter.new << TimeFilter.new << PageFilter.new
45
- #
46
- def << (next_filter = nil)
47
- @next_filter = next_filter
48
- end
49
-
50
- # Override this method to implement your filter.
51
- #
52
- def process(request)
53
- # preprocessing comes here...
54
-
55
- # walk the pipeline
56
- return process_next(request)
57
-
58
- # postprocessing comes here...
59
-
60
- # return the result...
61
- end
62
-
63
- # Process the next filter in the pipeline
64
- #
65
- def process_next(request)
66
- if @next_filter
67
- return @next_filter.process(request)
68
- else
69
- return nil
70
- end
71
- end
72
-
73
- end
74
-
75
- end # module
@@ -1,51 +0,0 @@
1
- # code:
2
- # * George Moschovitis
3
- #
4
- # (c) 2004 Navel, all rights reserved.
5
- # $Id: autologin.rb 167 2004-11-23 14:03:10Z gmosx $
6
-
7
- require "glue/string"
8
- require "nitro/server/filters"
9
-
10
- require_part "users"
11
-
12
- module N
13
-
14
- # = AutoLoginFilter
15
- #
16
- # Automatically login a user with valid authentication cookie.
17
- # Uses some n1 code at the moment.
18
- #
19
- class AutoLoginFilter < N::ServerFilter
20
-
21
- # Perform the actual work of auto logging in the user
22
- #
23
- def process(request)
24
- if request.is_top?
25
- # only try to autologin for top level requests
26
- # there is NO need for the older SKIP_AUTOLOGIN session flag.
27
- if (request.session.user.anonymous?) and
28
- cookie = request.get_cookie($users_auth_cookie)
29
-
30
- username, password_crypted = cookie.split(",")
31
-
32
- if user = $og.load_by_name(username, N::User) and
33
- password_crypted == user.password
34
- if request.session.login(request, user)
35
- # user logged in
36
- else
37
- # stale cookie, remove it
38
- request.del_cookie($users_auth_cookie)
39
- end
40
- else
41
- Logger.warn "Unknown user or wrong password in auth-cookie: #{cookie} from IP: #{request.remote_addr}"
42
- end
43
- end
44
- end
45
-
46
- return @next_filter.process(request) if @next_filter
47
- end
48
-
49
- end
50
-
51
- end # module
@@ -1,70 +0,0 @@
1
- # code:
2
- # * George Moschovitis <gm@navel.gr>
3
- #
4
- # (c) 2004 Navel, all rights reserved.
5
- # $Id: fragment.rb 167 2004-11-23 14:03:10Z gmosx $
6
-
7
- require "glue/cache"
8
- require "glue/mixins"
9
-
10
- module N
11
-
12
- # = Fragment
13
- #
14
- # A Fragment is the output of a rendered script. Additional metadata
15
- # such as lastmodified and expire times are stored to facilitate
16
- # fragment processing (for example caching).
17
- #
18
- # === Design:
19
- #
20
- # Fragments are cached in the filesystem to allow for a cluster of
21
- # server to access them. Benefits over the older memory cache scheme:
22
- #
23
- # - each fragment is processed once by one server
24
- # - easier visualisation of the fragments.
25
- # - can clear the cache for all server
26
- # - can selectively invalidate one fragment!
27
- # - less memory per server
28
- # - can run background cron scripts over the fragments (compression)
29
- #
30
- class Fragment
31
- include N::Expirable
32
- include N::LRUCache::Item
33
-
34
- # precompiled flags for fragment key "customization"
35
-
36
- ADMIN_FLAG = "-a"
37
- OWNER_FLAG = "-o"
38
- EDITOR_FLAG = "-e"
39
- VIEWER_FLAG = "-f"
40
- MY_FLAG = "-m"
41
- ANONYMOUS_FLAG = "-n"
42
-
43
- attr_accessor :body, :lm
44
-
45
- # another method for invalidation, allows for more flexible
46
- # invalidation strategies. also used by the legacy autoinvalidate
47
- # code.
48
- attr_accessor :expires
49
-
50
- def initialize(body = "", lm = Time.now)
51
- @body = body
52
- @lm = lm
53
- end
54
-
55
- def expires_after!(ea = (60*60*24))
56
- @expires = @lm + ea
57
- end
58
-
59
- # Is the fragment expired?
60
- #
61
- def expired?
62
- return true if @expires.nil? || (Time.now > @expires)
63
- end
64
-
65
- def to_str
66
- return @body
67
- end
68
- end
69
-
70
- end # module