nitro 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. data/{ChangeLog → CHANGELOG} +137 -0
  2. data/INSTALL +1 -2
  3. data/README +1 -1
  4. data/Rakefile +10 -61
  5. data/benchmark/{nitro/bench.rb → bench.rb} +1 -1
  6. data/benchmark/{nitro/simple-webrick-n-200.txt → simple-webrick-n-200.txt} +0 -0
  7. data/benchmark/{nitro/static-webrick-n-200.txt → static-webrick-n-200.txt} +0 -0
  8. data/benchmark/{nitro/tiny-lhttpd-n-200-c-5.txt → tiny-lhttpd-n-200-c-5.txt} +0 -0
  9. data/benchmark/{nitro/tiny-webrick-n-200-c-5.txt → tiny-webrick-n-200-c-5.txt} +0 -0
  10. data/benchmark/{nitro/tiny-webrick-n-200.txt → tiny-webrick-n-200.txt} +0 -0
  11. data/benchmark/{nitro/tiny2-webrick-n-200.txt → tiny2-webrick-n-200.txt} +0 -0
  12. data/doc/{ChangeLog.1 → CHANGELOG.1} +0 -0
  13. data/{RELEASES → doc/RELEASES} +46 -0
  14. data/doc/faq.txt +7 -0
  15. data/examples/README.windows +1 -1
  16. data/examples/ajax/controller.rb +21 -0
  17. data/examples/ajax/public/index.xhtml +70 -0
  18. data/examples/ajax/public/js/ajax.js +64 -0
  19. data/examples/ajax/run.rb +16 -0
  20. data/examples/blog/README +6 -3
  21. data/examples/blog/conf/apache.conf +2 -2
  22. data/examples/blog/conf/lhttpd.conf +2 -2
  23. data/examples/blog/log/apache.error_log +777 -0
  24. data/examples/blog/{root → public}/base.xsl +0 -0
  25. data/examples/blog/{root → public}/fcgi.rb +0 -0
  26. data/examples/blog/{root → public}/m/bubbles.gif +0 -0
  27. data/examples/blog/{root → public}/m/comments_curve.gif +0 -0
  28. data/examples/blog/{root → public}/m/down.gif +0 -0
  29. data/examples/blog/{root → public}/m/footer_bg.gif +0 -0
  30. data/examples/blog/{root → public}/m/garrow.gif +0 -0
  31. data/examples/blog/{root → public}/m/gbull.gif +0 -0
  32. data/examples/blog/{root → public}/m/grbull.gif +0 -0
  33. data/examples/blog/{root → public}/m/h1_bg.gif +0 -0
  34. data/examples/blog/{root → public}/m/header_bg.gif +0 -0
  35. data/examples/blog/{root → public}/m/nitro.gif +0 -0
  36. data/examples/blog/{root → public}/m/obull.gif +0 -0
  37. data/examples/blog/{root → public}/m/page_bg.gif +0 -0
  38. data/examples/blog/{root → public}/m/rss.gif +0 -0
  39. data/examples/blog/{root → public}/m/side_title_bg.gif +0 -0
  40. data/examples/blog/{root → public}/m/sidebar_bg.gif +0 -0
  41. data/examples/{no_xsl_blog/root → blog/public}/style.css +6 -0
  42. data/examples/blog/run.rb +10 -12
  43. data/examples/blog/{lib → src}/blog.rb +3 -3
  44. data/examples/blog/{lib/blog → src}/controller.rb +13 -2
  45. data/examples/blog/src/mailer.rb +23 -0
  46. data/examples/blog/{lib/blog/model.rb → src/models/blog.rb} +4 -7
  47. data/examples/blog/src/models/content.rb +52 -0
  48. data/examples/blog/src/views/blog_entry_email.xhtml +16 -0
  49. data/examples/blog/{root → src/views}/comments.xhtml +0 -0
  50. data/examples/blog/{root → src/views}/entry_form.xhtml +0 -0
  51. data/examples/blog/{root → src/views}/error.xhtml +0 -0
  52. data/examples/blog/{root → src/views}/index.xhtml +0 -0
  53. data/examples/blog/{root → src/views}/login.xhtml +0 -0
  54. data/examples/blog/{root → src/views}/recent_posts.xhtml +0 -0
  55. data/examples/blog/{root → src/views}/view_entry.xhtml +8 -0
  56. data/examples/blog/{root → src/views}/view_entry.xml +0 -0
  57. data/examples/blog/src/xsl/base.xsl +153 -0
  58. data/examples/blog/{root → src/xsl}/style.xsl +2 -2
  59. data/examples/no_xsl_blog/README +5 -1
  60. data/examples/no_xsl_blog/conf/apache.conf +2 -2
  61. data/examples/no_xsl_blog/conf/lhttpd.conf +2 -2
  62. data/examples/no_xsl_blog/lib/blog/model.rb +1 -1
  63. data/{lib/parts → examples/no_xsl_blog/lib}/content.rb +1 -11
  64. data/examples/no_xsl_blog/log/apache.error_log +405 -0
  65. data/examples/no_xsl_blog/{root → public}/comments.xhtml +0 -0
  66. data/examples/no_xsl_blog/{root → public}/entry_form.xhtml +0 -0
  67. data/examples/no_xsl_blog/{root → public}/fcgi.rb +0 -0
  68. data/examples/no_xsl_blog/{root → public}/index.xhtml +0 -0
  69. data/examples/no_xsl_blog/{root → public}/login.xhtml +0 -0
  70. data/examples/no_xsl_blog/{root → public}/m/bubbles.gif +0 -0
  71. data/examples/no_xsl_blog/{root → public}/m/comments_curve.gif +0 -0
  72. data/examples/no_xsl_blog/{root → public}/m/down.gif +0 -0
  73. data/examples/no_xsl_blog/{root → public}/m/footer_bg.gif +0 -0
  74. data/examples/no_xsl_blog/{root → public}/m/garrow.gif +0 -0
  75. data/examples/no_xsl_blog/{root → public}/m/gbull.gif +0 -0
  76. data/examples/no_xsl_blog/{root → public}/m/grbull.gif +0 -0
  77. data/examples/no_xsl_blog/{root → public}/m/h1_bg.gif +0 -0
  78. data/examples/no_xsl_blog/{root → public}/m/header_bg.gif +0 -0
  79. data/examples/no_xsl_blog/{root → public}/m/nitro.gif +0 -0
  80. data/examples/no_xsl_blog/{root → public}/m/obull.gif +0 -0
  81. data/examples/no_xsl_blog/{root → public}/m/page_bg.gif +0 -0
  82. data/examples/no_xsl_blog/{root → public}/m/rss.gif +0 -0
  83. data/examples/no_xsl_blog/{root → public}/m/side_title_bg.gif +0 -0
  84. data/examples/no_xsl_blog/{root → public}/m/sidebar_bg.gif +0 -0
  85. data/examples/no_xsl_blog/{root → public}/recent_posts.xhtml +0 -0
  86. data/examples/{blog/root → no_xsl_blog/public}/style.css +0 -0
  87. data/examples/no_xsl_blog/{root → public}/view_entry.xhtml +0 -0
  88. data/examples/no_xsl_blog/{root → public}/view_entry.xml +0 -0
  89. data/examples/tiny/conf/apache.conf +2 -2
  90. data/examples/tiny/log/apache.error_log +100 -0
  91. data/examples/tiny/{root → public}/fcgi.rb +0 -0
  92. data/examples/tiny/{root → public}/include.xhtml +0 -0
  93. data/examples/tiny/{root → public}/index.xhtml +0 -0
  94. data/{bin/proto/root/m → examples/tiny/public}/nitro.png +0 -0
  95. data/examples/tiny/{root → public}/upload.xhtml +0 -0
  96. data/examples/tiny/run.rb +1 -2
  97. data/examples/why_wiki/wiki.yml +1 -0
  98. data/install.rb +5 -2
  99. data/lib/nitro.rb +2 -6
  100. data/lib/nitro/adapters/fastcgi.rb +2 -2
  101. data/lib/nitro/adapters/webrick.rb +4 -4
  102. data/lib/nitro/conf.rb +5 -2
  103. data/lib/nitro/controller.rb +2 -2
  104. data/lib/nitro/dispatcher.rb +19 -8
  105. data/lib/nitro/mail.rb +252 -8
  106. data/lib/nitro/render.rb +24 -21
  107. data/lib/nitro/runner.rb +1 -1
  108. data/lib/nitro/scaffold.rb +2 -5
  109. data/lib/nitro/simple.rb +2 -1
  110. data/lib/nitro/template.rb +42 -2
  111. data/test/nitro/tc_controller.rb +9 -4
  112. data/test/nitro/tc_dispatcher.rb +4 -6
  113. data/test/nitro/tc_mail.rb +95 -0
  114. data/test/{root → public}/blog/list.xhtml +0 -0
  115. data/test/public/dummy_mailer/registration.xhtml +5 -0
  116. data/vendor/README +0 -1
  117. metadata +136 -181
  118. data/benchmark/og/bench.rb +0 -75
  119. data/benchmark/og/sqlite-no-prepare.1.txt +0 -13
  120. data/benchmark/og/sqlite-no-prepare.2.txt +0 -13
  121. data/benchmark/og/sqlite-prepare.1.txt +0 -13
  122. data/benchmark/og/sqlite-prepare.2.txt +0 -13
  123. data/bin/proto/README +0 -34
  124. data/bin/proto/conf/apache.conf +0 -1
  125. data/bin/proto/conf/app.conf.rb +0 -14
  126. data/bin/proto/conf/lhttpd.conf +0 -236
  127. data/bin/proto/ctl +0 -4
  128. data/bin/proto/lib/README +0 -5
  129. data/bin/proto/log/README +0 -3
  130. data/bin/proto/root/fcgi.rb +0 -6
  131. data/bin/proto/root/index.xhtml +0 -69
  132. data/bin/proto/root/style.css +0 -152
  133. data/bin/proto/root/style.xsl +0 -99
  134. data/doc/og_config.txt +0 -35
  135. data/doc/og_tutorial.txt +0 -595
  136. data/examples/og/README +0 -11
  137. data/examples/og/mock_example.rb +0 -50
  138. data/examples/og/mysql_to_psql.rb +0 -96
  139. data/examples/og/run.rb +0 -286
  140. data/examples/tiny/root/nitro.png +0 -0
  141. data/lib/glue.rb +0 -55
  142. data/lib/glue/array.rb +0 -61
  143. data/lib/glue/attribute.rb +0 -83
  144. data/lib/glue/cache.rb +0 -138
  145. data/lib/glue/flexob.rb +0 -12
  146. data/lib/glue/hash.rb +0 -122
  147. data/lib/glue/inflector.rb +0 -91
  148. data/lib/glue/logger.rb +0 -147
  149. data/lib/glue/misc.rb +0 -14
  150. data/lib/glue/mixins.rb +0 -36
  151. data/lib/glue/number.rb +0 -24
  152. data/lib/glue/object.rb +0 -32
  153. data/lib/glue/pool.rb +0 -60
  154. data/lib/glue/property.rb +0 -408
  155. data/lib/glue/string.rb +0 -162
  156. data/lib/glue/time.rb +0 -85
  157. data/lib/glue/validation.rb +0 -394
  158. data/lib/og.rb +0 -185
  159. data/lib/og/adapter.rb +0 -513
  160. data/lib/og/adapters/filesys.rb +0 -121
  161. data/lib/og/adapters/mysql.rb +0 -347
  162. data/lib/og/adapters/oracle.rb +0 -375
  163. data/lib/og/adapters/psql.rb +0 -273
  164. data/lib/og/adapters/sqlite.rb +0 -262
  165. data/lib/og/backend.rb +0 -297
  166. data/lib/og/connection.rb +0 -304
  167. data/lib/og/database.rb +0 -282
  168. data/lib/og/enchant.rb +0 -125
  169. data/lib/og/meta.rb +0 -373
  170. data/lib/og/mock.rb +0 -165
  171. data/lib/og/observer.rb +0 -53
  172. data/lib/og/typemacros.rb +0 -23
  173. data/lib/parts/README +0 -9
  174. data/test/glue/tc_attribute.rb +0 -22
  175. data/test/glue/tc_cache.rb +0 -45
  176. data/test/glue/tc_hash.rb +0 -38
  177. data/test/glue/tc_logger.rb +0 -39
  178. data/test/glue/tc_numbers.rb +0 -20
  179. data/test/glue/tc_property.rb +0 -89
  180. data/test/glue/tc_property_mixins.rb +0 -93
  181. data/test/glue/tc_property_type_checking.rb +0 -35
  182. data/test/glue/tc_strings.rb +0 -103
  183. data/test/glue/tc_validation.rb +0 -188
  184. data/test/og/tc_filesys.rb +0 -83
  185. data/test/og/tc_lifecycle.rb +0 -104
  186. data/test/og/tc_many_to_many.rb +0 -62
  187. data/test/og/tc_meta.rb +0 -55
  188. data/test/og/tc_observer.rb +0 -85
  189. data/test/og/tc_sqlite.rb +0 -87
  190. data/test/tc_og.rb +0 -355
  191. data/vendor/composite_sexp_processor.rb +0 -43
  192. data/vendor/parse_tree.rb +0 -745
  193. data/vendor/sexp_processor.rb +0 -453
data/lib/glue.rb DELETED
@@ -1,55 +0,0 @@
1
- # General libraries used by various projects.
2
- #
3
- #--
4
- # George Moschovitis <gm@navel.gr>
5
- # (c) 2004-2005 Navel, all rights reserved.
6
- # $Id: glue.rb 215 2005-01-24 10:44:05Z gmosx $
7
- #++
8
-
9
- require 'English'
10
- require 'pp'
11
-
12
- require 'glue/property'
13
- require 'glue/attribute'
14
-
15
- # The standard namespace module.
16
-
17
- module N; end
18
-
19
- class NilClass
20
-
21
- # quite usefull for error tolerant apps.
22
- # a bit dangerous? Will have to rethink this.
23
-
24
- def empty?
25
- return true
26
- end
27
- end
28
-
29
- class Class
30
- #--
31
- # gmosx: is this really needed?
32
- #++
33
-
34
- def to_i
35
- return self.hash
36
- end
37
- end
38
-
39
- module Kernel
40
-
41
- # Pretty prints an exception/error object
42
- # usefull for helpfull debug messages
43
- #
44
- # Input:
45
- # The Exception/StandardError object
46
- #
47
- # Output:
48
- # the pretty printed string
49
-
50
- def pp_exception(ex)
51
- return %{#{ex.message}\n\tBACKTRACE:\n\t#{ex.backtrace.join("\n\t")}\n\tLOGGED FROM:\n\t#{caller[0]}}
52
- end
53
-
54
- end
55
-
data/lib/glue/array.rb DELETED
@@ -1,61 +0,0 @@
1
- # * George Moschovitis <gm@navel.gr>
2
- # (c) 2002-2005 Navel, all rights reserved.
3
- # $Id: array.rb 266 2005-02-28 14:50:48Z gmosx $
4
-
5
- require 'sync'
6
-
7
- module N
8
-
9
- # A thread-safe array. We use a sync object instead of a
10
- # mutex, because it is re-entrant. An exclusive lock is
11
- # needed when writing, a shared lock IS NEEDED when reading.
12
-
13
- class SafeArray < Array
14
-
15
- attr :sync
16
-
17
- # gmosx: delegator is not used.
18
-
19
- def initialize(delegator = nil)
20
- @sync = Sync.new()
21
- end
22
-
23
- def << (value)
24
- return @sync.synchronize(Sync::SH) { super }
25
- end
26
-
27
- def delete_if(&block)
28
- return @sync.synchronize(Sync::SH) { super }
29
- end
30
-
31
- def [](key)
32
- return @sync.synchronize(Sync::SH) { super }
33
- end
34
-
35
- def []=(key, value)
36
- return @sync.synchronize(Sync::EX) { super }
37
- end
38
-
39
- def delete(key)
40
- return @sync.synchronize(Sync::EX) { super }
41
- end
42
-
43
- def clear
44
- @sync.synchronize(Sync::EX) { super }
45
- end
46
-
47
- def size
48
- return @sync.synchronize(Sync::SH) { super }
49
- end
50
-
51
- def shift
52
- return @sync.synchronize(::Sync::EX) { super }
53
- end
54
-
55
- def unshift(el)
56
- return @sync.synchronize(::Sync::EX) { super }
57
- end
58
-
59
- end
60
-
61
- end
@@ -1,83 +0,0 @@
1
- # * George Moschovitis <gm@navel.gr>
2
- # Original code from Rails distribution.
3
- # http://www.rubyonrails.com
4
- # $Id$
5
-
6
- #--
7
- # Extends the module object with module and instance accessors
8
- # for class attributes, just like the native attr* accessors for
9
- # instance attributes. Aliases for classes are also provided.
10
- #
11
- # Example:
12
- #
13
- # mattr_accessor :my_attr, 'Default value'
14
- #++
15
- class Module # :nodoc:
16
-
17
- def mattr_reader(*params)
18
- default = if params.last.is_a?(Symbol) then nil else params.pop end
19
-
20
-
21
- for sym in params
22
- module_eval <<-"end_eval", __FILE__, __LINE__
23
-
24
- if not defined?(@@#{sym.id2name})
25
- @@#{sym.id2name} = #{default.inspect}
26
- end
27
-
28
- def self.#{sym.id2name}
29
- @@#{sym}
30
- end
31
-
32
- def #{sym.id2name}
33
- @@#{sym}
34
- end
35
-
36
- def call_#{sym.id2name}
37
- case @@#{sym.id2name}
38
- when Symbol then send(@@#{sym})
39
- when Proc then @@#{sym}.call(self)
40
- when String then @@#{sym}
41
- else nil
42
- end
43
- end
44
-
45
- end_eval
46
- end
47
- end
48
- alias_method :cattr_reader, :mattr_reader
49
-
50
- def mattr_writer(*params)
51
- default = if params.last.is_a?(Symbol) then nil else params.pop end
52
-
53
- for sym in params
54
- module_eval <<-"end_eval", __FILE__, __LINE__
55
-
56
- if not defined?(@@#{sym.id2name})
57
- @@#{sym.id2name} = #{default.inspect.inspect}
58
- end
59
-
60
- def self.#{sym.id2name}=(obj)
61
- @@#{sym.id2name} = obj
62
- end
63
-
64
- def self.set_#{sym.id2name}(obj)
65
- @@#{sym.id2name} = obj
66
- end
67
-
68
- def #{sym.id2name}=(obj)
69
- @@#{sym} = obj
70
- end
71
-
72
- end_eval
73
- end
74
- end
75
- alias_method :cattr_writer, :cattr_writer
76
-
77
- def mattr_accessor(*syms)
78
- mattr_reader(*syms)
79
- mattr_writer(*syms)
80
- end
81
- alias_method :cattr_accessor, :mattr_accessor
82
-
83
- end
data/lib/glue/cache.rb DELETED
@@ -1,138 +0,0 @@
1
- # * George Moschovitis <gm@navel.gr>
2
- # * Anastasios Koutoumanos <ak@navel.gr>
3
- # (c) 2004-2005 Navel, all rights reserved.
4
- # $Id: cache.rb 249 2005-02-04 14:03:00Z gmosx $
5
-
6
- module N
7
-
8
- # A cache utilizing a simple LRU (Least Recently Used) policy.
9
- # The items managed by this cache must respond to the #key method.
10
- # Attempts to optimize reads rather than inserts!
11
- #
12
- # LRU semantics are enforced by inserting the items in a queue.
13
- # The lru item is always at the tail. Two special sentinels
14
- # (head, tail) are used to simplify (?) the code.
15
-
16
- class LRUCache < Hash
17
-
18
- # Mix this in your class to make LRU-managable.
19
-
20
- module Item
21
- attr_accessor :lru_key, :lru_prev, :lru_next
22
- end
23
-
24
- # head-tail sentinels
25
-
26
- class Sentinel; include Item; end
27
-
28
- # the maximum number of items in the cache.
29
-
30
- attr_accessor :max_items
31
-
32
- # the head sentinel
33
-
34
- attr :head
35
-
36
- # the tail sentinel, tail.prev points to the lru item.
37
-
38
- attr :tail
39
-
40
- def initialize(max_items)
41
- @max_items = max_items
42
- lru_clear()
43
- end
44
-
45
- # Lookup an item in the cache.
46
-
47
- def [](key)
48
- if item = super
49
- return lru_touch(item)
50
- end
51
- end
52
-
53
- # The inserted item is considered mru!
54
-
55
- def []=(key, item)
56
- item = super
57
- item.lru_key = key
58
- lru_insert(item)
59
- end
60
-
61
- # Delete an item from the cache.
62
-
63
- def delete(key)
64
- if item = super
65
- lru_delete(item)
66
- end
67
- end
68
-
69
- # Clear the cache.
70
-
71
- def clear
72
- super
73
- lru_clear()
74
- end
75
-
76
- # The first (mru) element in the cache.
77
-
78
- def first
79
- @head.lru_next
80
- end
81
-
82
- # The last (lru) element in the cache.
83
-
84
- def last
85
- @tail.lru_prev
86
- end
87
- alias_method :lru, :last
88
-
89
- private
90
-
91
- # Delete an item from the lru list.
92
-
93
- def lru_delete(item)
94
- lru_join(item.lru_prev, item.lru_next)
95
- return item
96
- end
97
-
98
- # Join two items in the lru list.
99
- # Return y to allow for chaining.
100
-
101
- def lru_join(x, y)
102
- x.lru_next = y
103
- y.lru_prev = x
104
- return y
105
- end
106
-
107
- # Append a child item to a parent item in the lru list
108
- # (Re)inserts the child in the list.
109
-
110
- def lru_append(parent, child)
111
- lru_join(child, parent.lru_next)
112
- lru_join(parent, child)
113
- end
114
-
115
- # Insert an item
116
-
117
- def lru_insert(item)
118
- delete(last.lru_key) if size() > @max_items
119
- lru_append(@head, item)
120
- end
121
-
122
- # Touch an item, make mru!
123
- # Returns the item.
124
-
125
- def lru_touch(item)
126
- lru_append(@head, lru_delete(item))
127
- end
128
-
129
- # Clear the lru.
130
-
131
- def lru_clear
132
- @head = Sentinel.new
133
- @tail = Sentinel.new
134
- lru_join(@head, @tail)
135
- end
136
- end
137
-
138
- end
data/lib/glue/flexob.rb DELETED
@@ -1,12 +0,0 @@
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
data/lib/glue/hash.rb DELETED
@@ -1,122 +0,0 @@
1
- # * George Moschovitis <gm@navel.gr>
2
- # (c) 2004-2005 Navel, all rights reserved.
3
- # $Id: hash.rb 263 2005-02-23 13:45:08Z gmosx $
4
-
5
- require 'sync'
6
-
7
- module N
8
-
9
- # A thread-safe hash. We use a sync object instead of a mutex,
10
- # because it is re-entrant. An exclusive lock is needed when
11
- # writing, a shared lock IS NEEDED when reading
12
- # uses the delegator pattern to allow for multiple
13
- # implementations!
14
-
15
- class SafeHash < Hash
16
- attr :sync
17
-
18
- # gmosx: delegator is not used.
19
- #
20
- def initialize(delegator = nil)
21
- @sync = ::Sync.new
22
- end
23
-
24
- def [](key)
25
- @sync.synchronize(::Sync::SH) { super }
26
- end
27
-
28
- def []=(key, value)
29
- @sync.synchronize(::Sync::EX) { super }
30
- end
31
-
32
- def delete(key)
33
- @sync.synchronize(::Sync::EX) { super }
34
- end
35
-
36
- def clear
37
- @sync.synchronize(::Sync::EX) { super }
38
- end
39
-
40
- def size
41
- @sync.synchronize(::Sync::SH) { super }
42
- end
43
-
44
- def values
45
- @sync.synchronize(::Sync::SH) { super }
46
- end
47
-
48
- def keys
49
- @sync.synchronize(::Sync::SH) { super }
50
- end
51
-
52
- end
53
-
54
- # A thread-safe hash. We use a sync object instead of a mutex,
55
- # because it is re-entrant. An exclusive lock is needed when
56
- # writing, a shared lock IS NEEDED when reading.
57
- #
58
- # === Design
59
- #
60
- # This class uses the delegator pattern. However we dont use rubys
61
- # delegation facilities, they are more general and powerfull than we
62
- # need here (and slower). Instead a custom (but simple) solution is
63
- # used.
64
- #
65
- # === Example
66
- #
67
- # hash = SafeHashDelegator.new(Hash.new)
68
- # hash = SafeHashDelegator.new(Hash.new)
69
-
70
- class SafeHashDelegator < Hash
71
- attr :delegate, :sync
72
-
73
- def initialize(delegate)
74
- @delegate = delegate
75
- @sync = ::Sync.new
76
- end
77
-
78
- def [](key)
79
- @sync.synchronize(::Sync::SH) {
80
- @delegate[key]
81
- }
82
- end
83
-
84
- def []=(key, value)
85
- @sync.synchronize(::Sync::EX) {
86
- @delegate[key] = value
87
- }
88
- end
89
-
90
- def delete(key)
91
- @sync.synchronize(::Sync::EX) {
92
- @delegate.delete(key)
93
- }
94
- end
95
-
96
- def clear
97
- @sync.synchronize(::Sync::EX) {
98
- @delegate.clear
99
- }
100
- end
101
-
102
- def size
103
- @sync.synchronize(::Sync::SH) {
104
- @delegate.size()
105
- }
106
- end
107
-
108
- def values
109
- @sync.synchronize(::Sync::SH) {
110
- @delegate.values()
111
- }
112
- end
113
-
114
- def keys
115
- @sync.synchronize(::Sync::SH) {
116
- @delegate.keys()
117
- }
118
- end
119
-
120
- end
121
-
122
- end