ramaze 0.1.0 → 0.1.1

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 (195) hide show
  1. data/Rakefile +4 -12
  2. data/bin/ramaze +95 -171
  3. data/doc/CHANGELOG +387 -4
  4. data/doc/README +81 -13
  5. data/doc/meta/announcement.txt +51 -8
  6. data/doc/meta/configuration.txt +17 -34
  7. data/doc/meta/internals.txt +34 -4
  8. data/doc/migrate/1110_to_1111.txt +131 -0
  9. data/doc/readme_chunks/features.txt +81 -12
  10. data/doc/readme_chunks/installing.txt +0 -1
  11. data/doc/tutorial/todolist.html +293 -65
  12. data/doc/tutorial/{todolist.txt → todolist.mkd} +251 -51
  13. data/examples/blog/main.rb +1 -1
  14. data/examples/blog/src/model.rb +0 -1
  15. data/examples/hello.rb +2 -5
  16. data/examples/templates/template/external.haml +5 -5
  17. data/examples/templates/template/external.liquid +1 -1
  18. data/examples/templates/template/external.mab +8 -8
  19. data/examples/templates/template/external.rem +30 -0
  20. data/examples/templates/template/external.rhtml +6 -7
  21. data/examples/templates/template/external.zmr +13 -9
  22. data/examples/templates/template_amrita2.rb +8 -8
  23. data/examples/templates/template_erubis.rb +11 -11
  24. data/examples/templates/template_ezamar.rb +9 -11
  25. data/examples/templates/template_haml.rb +13 -13
  26. data/examples/templates/template_liquid.rb +10 -10
  27. data/examples/templates/template_markaby.rb +13 -10
  28. data/examples/templates/template_remarkably.rb +59 -0
  29. data/examples/todolist/main.rb +1 -7
  30. data/examples/todolist/src/controller/main.rb +26 -13
  31. data/examples/todolist/src/element/page.rb +5 -0
  32. data/examples/whywiki/main.rb +1 -1
  33. data/lib/proto/main.rb +0 -8
  34. data/lib/proto/public/css/ramaze_error.css +12 -4
  35. data/lib/proto/public/error.zmr +6 -25
  36. data/lib/ramaze.rb +35 -245
  37. data/lib/ramaze/action.rb +21 -0
  38. data/lib/ramaze/adapter.rb +94 -29
  39. data/lib/ramaze/adapter/base.rb +57 -0
  40. data/lib/ramaze/adapter/mongrel.rb +12 -19
  41. data/lib/ramaze/adapter/webrick.rb +21 -20
  42. data/lib/ramaze/cache.rb +47 -3
  43. data/lib/ramaze/cache/memcached.rb +22 -0
  44. data/lib/ramaze/cache/yaml_store.rb +19 -0
  45. data/lib/ramaze/controller.rb +47 -271
  46. data/lib/ramaze/controller/error.rb +43 -0
  47. data/lib/ramaze/controller/render.rb +90 -0
  48. data/lib/ramaze/controller/resolve.rb +147 -0
  49. data/lib/ramaze/dispatcher.rb +41 -9
  50. data/lib/ramaze/dispatcher/file.rb +1 -1
  51. data/lib/ramaze/global.rb +73 -158
  52. data/lib/ramaze/global/dsl.rb +29 -0
  53. data/lib/ramaze/global/globalstruct.rb +90 -0
  54. data/lib/ramaze/helper.rb +1 -1
  55. data/lib/ramaze/helper/aspect.rb +39 -179
  56. data/lib/ramaze/helper/cache.rb +8 -9
  57. data/lib/ramaze/helper/cgi.rb +23 -0
  58. data/lib/ramaze/helper/file.rb +3 -0
  59. data/lib/ramaze/helper/inform.rb +3 -0
  60. data/lib/ramaze/helper/link.rb +56 -63
  61. data/lib/ramaze/helper/nitroform.rb +4 -0
  62. data/lib/ramaze/helper/redirect.rb +1 -1
  63. data/lib/ramaze/inform.rb +6 -2
  64. data/lib/ramaze/inform/analogger.rb +5 -1
  65. data/lib/ramaze/inform/hub.rb +1 -1
  66. data/lib/ramaze/inform/informing.rb +7 -0
  67. data/lib/ramaze/snippets/kernel/aquire.rb +2 -0
  68. data/lib/ramaze/snippets/kernel/constant.rb +2 -0
  69. data/lib/ramaze/snippets/kernel/pretty_inspect.rb +2 -0
  70. data/lib/ramaze/snippets/object/traits.rb +4 -0
  71. data/lib/ramaze/snippets/openstruct/temp.rb +3 -0
  72. data/lib/ramaze/snippets/string/DIVIDE.rb +2 -0
  73. data/lib/ramaze/snippets/string/camel_case.rb +2 -0
  74. data/lib/ramaze/snippets/string/color.rb +2 -0
  75. data/lib/ramaze/snippets/string/each.rb +2 -0
  76. data/lib/ramaze/snippets/string/snake_case.rb +3 -0
  77. data/lib/ramaze/snippets/struct/fill.rb +8 -2
  78. data/lib/ramaze/snippets/struct/values_at.rb +16 -0
  79. data/lib/ramaze/snippets/symbol/to_proc.rb +3 -0
  80. data/lib/ramaze/sourcereload.rb +89 -0
  81. data/lib/ramaze/template.rb +21 -12
  82. data/lib/ramaze/template/amrita2.rb +6 -6
  83. data/lib/ramaze/template/erubis.rb +4 -9
  84. data/lib/ramaze/template/ezamar.rb +13 -57
  85. data/lib/ramaze/template/ezamar/element.rb +10 -12
  86. data/lib/ramaze/template/ezamar/engine.rb +40 -101
  87. data/lib/ramaze/template/ezamar/morpher.rb +3 -3
  88. data/lib/ramaze/template/haml.rb +3 -6
  89. data/lib/ramaze/template/liquid.rb +4 -9
  90. data/lib/ramaze/template/markaby.rb +16 -22
  91. data/lib/ramaze/template/remarkably.rb +28 -0
  92. data/lib/ramaze/tool/mime.rb +2 -0
  93. data/lib/ramaze/tool/record.rb +6 -0
  94. data/lib/ramaze/trinity/request.rb +44 -54
  95. data/lib/ramaze/trinity/response.rb +1 -1
  96. data/lib/ramaze/trinity/session.rb +15 -37
  97. data/lib/ramaze/version.rb +1 -1
  98. data/rake_tasks/gem.rake +2 -2
  99. data/rake_tasks/maintaince.rake +42 -1
  100. data/rake_tasks/spec.rake +45 -0
  101. data/spec/examples/caching.rb +1 -1
  102. data/spec/examples/simple.rb +1 -1
  103. data/spec/examples/templates/template_amrita2.rb +1 -0
  104. data/spec/examples/templates/template_erubis.rb +2 -1
  105. data/spec/examples/templates/template_ezamar.rb +1 -1
  106. data/spec/examples/templates/template_haml.rb +2 -1
  107. data/spec/examples/templates/template_liquid.rb +2 -1
  108. data/spec/examples/templates/template_markaby.rb +2 -1
  109. data/spec/examples/templates/template_remarkably.rb +22 -0
  110. data/spec/examples/todolist.rb +125 -0
  111. data/spec/helper.rb +2 -23
  112. data/spec/helper/minimal.rb +20 -0
  113. data/spec/helper/mock_http.rb +24 -30
  114. data/spec/helper/simple_http.rb +2 -2
  115. data/spec/helper/wrap.rb +6 -9
  116. data/spec/ramaze/adapter.rb +1 -1
  117. data/spec/ramaze/adapter/record.rb +31 -0
  118. data/spec/ramaze/cache.rb +41 -54
  119. data/spec/ramaze/controller.rb +121 -137
  120. data/spec/ramaze/controller/template/list.xhtml +1 -0
  121. data/spec/ramaze/controller/template/other/greet/other.xhtml +1 -0
  122. data/spec/ramaze/controller/template_resolving.rb +27 -3
  123. data/spec/ramaze/element.rb +11 -7
  124. data/spec/ramaze/error.rb +1 -1
  125. data/spec/ramaze/gestalt.rb +2 -0
  126. data/spec/ramaze/helper/aspect.rb +30 -21
  127. data/spec/ramaze/helper/auth.rb +1 -1
  128. data/spec/ramaze/helper/cache.rb +2 -1
  129. data/spec/ramaze/helper/form.rb +14 -11
  130. data/spec/ramaze/helper/link.rb +18 -41
  131. data/spec/ramaze/localize.rb +29 -2
  132. data/spec/ramaze/morpher.rb +23 -12
  133. data/spec/ramaze/params.rb +46 -24
  134. data/spec/ramaze/request.rb +6 -2
  135. data/spec/ramaze/store/yaml.rb +5 -0
  136. data/spec/ramaze/template.rb +22 -27
  137. data/spec/ramaze/template/amrita2.rb +1 -2
  138. data/spec/ramaze/template/erubis.rb +1 -1
  139. data/spec/ramaze/template/ezamar.rb +1 -2
  140. data/spec/ramaze/template/haml.rb +2 -2
  141. data/spec/ramaze/template/haml/with_vars.haml +1 -1
  142. data/spec/ramaze/template/liquid.rb +1 -1
  143. data/spec/ramaze/template/markaby.rb +1 -1
  144. data/spec/ramaze/template/remarkably.rb +56 -0
  145. data/spec/ramaze/template/remarkably/external.rem +8 -0
  146. data/spec/ramaze/template/remarkably/sum.rem +1 -0
  147. metadata +38 -63
  148. data/doc/README.html +0 -637
  149. data/doc/allison/LICENSE +0 -184
  150. data/doc/allison/README +0 -37
  151. data/doc/allison/allison.css +0 -299
  152. data/doc/allison/allison.gif +0 -0
  153. data/doc/allison/allison.js +0 -307
  154. data/doc/allison/allison.rb +0 -287
  155. data/doc/allison/cache/BODY +0 -588
  156. data/doc/allison/cache/CLASS_INDEX +0 -4
  157. data/doc/allison/cache/CLASS_PAGE +0 -1
  158. data/doc/allison/cache/FILE_INDEX +0 -4
  159. data/doc/allison/cache/FILE_PAGE +0 -1
  160. data/doc/allison/cache/FONTS +0 -1
  161. data/doc/allison/cache/FR_INDEX_BODY +0 -1
  162. data/doc/allison/cache/IMGPATH +0 -1
  163. data/doc/allison/cache/INDEX +0 -1
  164. data/doc/allison/cache/JAVASCRIPT +0 -307
  165. data/doc/allison/cache/METHOD_INDEX +0 -4
  166. data/doc/allison/cache/METHOD_LIST +0 -1
  167. data/doc/allison/cache/SRC_PAGE +0 -1
  168. data/doc/allison/cache/STYLE +0 -321
  169. data/doc/allison/cache/URL +0 -1
  170. data/doc/changes.txt +0 -3375
  171. data/doc/changes.xml +0 -3378
  172. data/examples/todolist/conf/benchmark.yaml +0 -35
  173. data/examples/todolist/conf/debug.yaml +0 -34
  174. data/examples/todolist/conf/live.yaml +0 -33
  175. data/examples/todolist/conf/silent.yaml +0 -31
  176. data/examples/todolist/conf/stage.yaml +0 -33
  177. data/examples/todolist/public/css/coderay.css +0 -105
  178. data/examples/todolist/public/css/ramaze_error.css +0 -42
  179. data/lib/proto/conf/benchmark.yaml +0 -21
  180. data/lib/proto/conf/debug.yaml +0 -21
  181. data/lib/proto/conf/live.yaml +0 -21
  182. data/lib/proto/conf/silent.yaml +0 -21
  183. data/lib/proto/conf/stage.yaml +0 -21
  184. data/lib/proto/public/css/coderay.css +0 -105
  185. data/lib/ramaze/http_status.rb +0 -66
  186. data/lib/ramaze/snippets/hash/keys_to_sym.rb +0 -19
  187. data/lib/ramaze/snippets/kernel/method.rb +0 -26
  188. data/lib/ramaze/snippets/method/name.rb +0 -22
  189. data/lib/ramaze/snippets/ramaze/autoreload.rb +0 -135
  190. data/lib/ramaze/snippets/rdoc/usage_no_exit.rb +0 -65
  191. data/spec/all.rb +0 -32
  192. data/spec/ramaze/conf/locale_de.yaml +0 -6
  193. data/spec/ramaze/conf/locale_en.yaml +0 -6
  194. data/spec/ramaze/dependencies.rb +0 -16
  195. data/spec/ramaze/global.rb +0 -44
@@ -0,0 +1,21 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ module Ramaze
5
+
6
+ unless defined?(Action) # prevent problems for SourceReload
7
+
8
+ # The Action holds information that is essential to render the action for a
9
+ # request.
10
+
11
+ class Action < Struct.new('Action', :controller, :method, :params, :template, :binding)
12
+ def to_s
13
+ %{#<Action method=#{method.inspect}, params=#{params.inspect} template=#{template.inspect}>}
14
+ end
15
+
16
+ def params=(*par)
17
+ self[:params] = par.flatten.map{|pa| CGI.unescape(pa)}
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,54 +1,119 @@
1
1
  # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
- require 'rack'
4
+ require 'socket'
5
+ require 'timeout'
5
6
  require 'benchmark'
6
7
 
8
+ require 'rack'
9
+ require 'rack/utils'
10
+
7
11
  require 'ramaze/trinity'
12
+ require 'ramaze/tool/record'
13
+ require 'ramaze/adapter/base'
8
14
 
9
15
  # for OSX compatibility
10
16
  Socket.do_not_reverse_lookup = true
11
17
 
12
- class Rack::Request
13
- include Ramaze::Request
14
- end
18
+ module Ramaze
15
19
 
16
- class Rack::Response
17
- include Ramaze::Response
18
- end
20
+ # Shortcut to the HTTP_STATUS_CODES of Rack::Utils
21
+ # inverted for easier access
22
+
23
+ STATUS_CODE = Rack::Utils::HTTP_STATUS_CODES.invert
19
24
 
20
- module Ramaze::Adapter
21
- class Base
25
+ # This module holds all classes and methods related to the adapters like
26
+ # webrick or mongrel.
27
+ # It's responsible to start and stop them.
28
+
29
+ module Adapter
22
30
  class << self
23
- def stop
24
- Inform.debug("Stopping #{self.class}")
31
+
32
+ # Is called by Ramaze.startup and will first call start_adapter and wait
33
+ # up to 3 seconds for an adapter to appear.
34
+ # It will then wait for the adapters to finish If Global.run_loose is
35
+ # set or otherwise pass you on control which is useful for testing or IRB
36
+ # sessions.
37
+
38
+ def startup options = {}
39
+ start_adapter
40
+
41
+ Timeout.timeout(3) do
42
+ sleep 0.01 until Global.adapters.list.any?
43
+ end
44
+
45
+ Global.adapters.list.each{|a| a.join} unless Global.run_loose
46
+
47
+ rescue SystemExit
48
+ Ramaze.shutdown
49
+ rescue Object => ex
50
+ Inform.error(ex)
51
+ Ramaze.shutdown
25
52
  end
26
53
 
27
- def call(env)
28
- new.call(env)
54
+ # Takes Global.adapter and starts if test_connections is positive that
55
+ # connections can be made to the specified host and ports.
56
+ # If you set Global.adapter to false it won't start any but deploy a
57
+ # dummy which is useful for testing purposes where you just send fake
58
+ # requests to Dispatcher.
59
+
60
+ def start_adapter
61
+ if adapter = Global.adapter
62
+ host, ports = Global.host, Global.ports
63
+
64
+ Inform.info("Adapter: #{adapter}, testing connection to #{host}:#{ports}")
65
+ test_connections(host, ports)
66
+
67
+ Inform.info("and we're running: #{host}:#{ports}")
68
+ adapter.start(host, ports)
69
+ else # run dummy
70
+ Global.adapters.add Thread.new{ sleep }
71
+ Inform.warn("Seems like Global.adapter is turned off", "Continue without adapter.")
72
+ end
73
+ rescue LoadError => ex
74
+ Inform.warn(ex, "Continue without adapter.")
29
75
  end
30
- end
31
76
 
32
- def call(env)
33
- if Ramaze::Global.benchmarking
34
- time = Benchmark.measure{ respond env }
35
- Inform.debug("request took #{time.real}s")
36
- else
37
- respond env
77
+ # Calls ::shutdown on all running adapters and waits up to 1 second for
78
+ # them to finish, then goes on to kill them and exit still.
79
+
80
+ def shutdown
81
+ Timeout.timeout(1) do
82
+ Global.adapters.list.each do |adapter|
83
+ a = adapter[:adapter]
84
+ a.shutdown if a.respond_to?(:shutdown)
85
+ end
86
+ end
87
+ rescue Timeout::Error
88
+ Global.adapters.list.each{|a| a.kill!}
89
+ exit!
38
90
  end
39
91
 
40
- finish
41
- end
92
+ # check the given host and ports via test_connection.
93
+ # Shuts down if no connection is possible.
42
94
 
43
- def finish
44
- response = Thread.current[:response]
95
+ def test_connections host, ports
96
+ return unless Global.test_connections
45
97
 
46
- response.finish
47
- end
98
+ ports.each do |port|
99
+ unless test_connection(host, port)
100
+ Inform.error("Cannot open connection on #{host}:#{port}")
101
+ Ramaze.shutdown
102
+ end
103
+ end
104
+ end
48
105
 
49
- def respond env
50
- request, response = Rack::Request.new(env), Rack::Response.new
51
- Ramaze::Dispatcher.handle(request, response)
106
+ # Opens a TCPServer temporarily and returns true if a connection is
107
+ # possible and false if none can be made
108
+
109
+ def test_connection host, port
110
+ Timeout.timeout(1) do
111
+ TCPServer.open(host, port){ true }
112
+ end
113
+ rescue => ex
114
+ Inform.error(ex)
115
+ false
116
+ end
52
117
  end
53
118
  end
54
119
  end
@@ -0,0 +1,57 @@
1
+ # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
+ # All files in this distribution are subject to the terms of the Ruby license.
3
+
4
+ module Ramaze
5
+ module Adapter
6
+
7
+ # This class is holding common behaviour for its subclasses.
8
+
9
+ class Base
10
+ class << self
11
+
12
+ # For the specified host and for all given ports call run_server and
13
+ # add the returned thread to the Global.adapters ThreadGroup.
14
+ # Afterwards adds a trap for the value of Global.shutdown_trap which
15
+ # calls Ramaze.shutdown when triggered (usually by SIGINT).
16
+
17
+ def start host, ports
18
+ ports.each do |port|
19
+ Global.adapters.add(run_server(host, port))
20
+ trap(Global.shutdown_trap){ Ramaze.shutdown }
21
+ end
22
+ end
23
+
24
+ # Does nothing
25
+
26
+ def stop
27
+ Inform.debug("Stopping #{self.class}")
28
+ end
29
+
30
+ def call(env)
31
+ if Ramaze::Global.benchmarking
32
+ time = Benchmark.measure{ respond env }
33
+ Inform.debug("request took #{time.real}s")
34
+ else
35
+ respond env
36
+ end
37
+
38
+ finish
39
+ end
40
+
41
+ def finish
42
+ response = Thread.current[:response]
43
+
44
+ response.finish
45
+ end
46
+
47
+ def respond env
48
+ request, response = Request.new(env), Response.new
49
+ if filter = Global.record
50
+ Record << request if filter[request]
51
+ end
52
+ Dispatcher.handle(request, response)
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -2,27 +2,20 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  require 'ramaze/adapter'
5
-
6
5
  require 'mongrel'
6
+ require 'rack/handler/mongrel'
7
7
 
8
- module Ramaze::Adapter
9
- class Mongrel < Base
10
- class << self
11
- def start host, ports
12
- ports.map{|port| run_server(host, port) }.first
13
- end
14
-
15
- def run_server host, port
16
- server = ::Mongrel::HttpServer.new(host, port)
17
- server.register('/', ::Rack::Handler::Mongrel.new(self))
18
- server.run
19
- end
20
-
21
- def stop
22
- end
23
-
24
- def call(env)
25
- new.call(env)
8
+ module Ramaze
9
+ module Adapter
10
+ class Mongrel < Base
11
+ class << self
12
+ def run_server host, port
13
+ server = ::Mongrel::HttpServer.new(host, port)
14
+ server.register('/', ::Rack::Handler::Mongrel.new(self))
15
+ thread = server.run
16
+ thread[:adapter] = server
17
+ thread
18
+ end
26
19
  end
27
20
  end
28
21
  end
@@ -2,7 +2,7 @@
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
4
  require 'ramaze/adapter'
5
-
5
+ require 'webrick'
6
6
  require 'rack/handler/webrick'
7
7
 
8
8
  module WEBrick
@@ -14,27 +14,28 @@ module WEBrick
14
14
  end
15
15
  end
16
16
 
17
- module Ramaze::Adapter
18
- class Webrick < Base
19
- class << self
20
- def start host, ports
21
- ports.map{|port| run_server(host, port) }.first
22
- end
17
+ module Ramaze
18
+ module Adapter
19
+ class WEBrick < Base
20
+ class << self
21
+ def run_server host, port, options = {}
22
+ options = {
23
+ :Port => port,
24
+ :BindAddress => host,
25
+ :Logger => Inform,
26
+ :AccessLog => [
27
+ [Inform, ::WEBrick::AccessLog::COMMON_LOG_FORMAT],
28
+ [Inform, ::WEBrick::AccessLog::REFERER_LOG_FORMAT]
29
+ ]
30
+ }.merge(options)
23
31
 
24
- def run_server host, port, options = {}
25
- options = {
26
- :Port => port,
27
- :BindAddress => host,
28
- :Logger => Ramaze::Inform,
29
- :AccessLog => [
30
- [Ramaze::Inform, WEBrick::AccessLog::COMMON_LOG_FORMAT],
31
- [Ramaze::Inform, WEBrick::AccessLog::REFERER_LOG_FORMAT]
32
- ]
33
- }.merge(options)
34
32
 
35
- Thread.new do
36
- Thread.current[:adapter] =
37
- Rack::Handler::WEBrick.run(self, options)
33
+ server = ::WEBrick::HTTPServer.new(options)
34
+ server.mount("/", ::Rack::Handler::WEBrick, self)
35
+ thread = Thread.new(server) do |adapter|
36
+ Thread.current[:adapter] = adapter
37
+ adapter.start
38
+ end
38
39
  end
39
40
  end
40
41
  end
@@ -1,11 +1,55 @@
1
1
  # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
+ require 'ramaze/cache/memory'
5
+
4
6
  module Ramaze
5
- autoload :MemoryCache, "ramaze/cache/memory.rb"
6
7
  autoload :YAMLStoreCache, "ramaze/cache/yaml_store.rb"
7
8
  autoload :MemcachedCache, "ramaze/cache/memcached.rb"
8
9
 
9
- Cache = nil
10
- SessionCache = nil
10
+ # This is the wrapper of all caches, providing mechanism
11
+ # for switching caching from one adapter to another.
12
+
13
+ class Cache
14
+ include Enumerable
15
+ CACHES = {}
16
+
17
+ # This will define a method to access a new cache directly over
18
+ # sinleton-methods on Cache
19
+
20
+ def self.add *keys
21
+ keys.each do |key|
22
+ CACHES[key] = new
23
+ self.class.class_eval do
24
+ define_method(key){ CACHES[key] }
25
+ end
26
+ end
27
+ end
28
+
29
+ def initialize(cache = Global.cache)
30
+ @cache = cache.new
31
+ end
32
+
33
+ def [](key)
34
+ @cache[key.to_s]
35
+ end
36
+
37
+ def []=(key, value)
38
+ @cache[key.to_s] = value
39
+ end
40
+
41
+ def delete(*args)
42
+ args.each do |arg|
43
+ @cache.delete(arg.to_s)
44
+ end
45
+ end
46
+
47
+ def method_missing(meth, *args, &block)
48
+ if @cache.respond_to?(meth)
49
+ @cache.send(meth, *args, &block)
50
+ else
51
+ super
52
+ end
53
+ end
54
+ end
11
55
  end
@@ -59,3 +59,25 @@ module Ramaze
59
59
  end
60
60
  end
61
61
  end
62
+
63
+ # add the MemCache#clear method
64
+
65
+ class MemCache
66
+ def clear
67
+ raise MemCacheError, "Update of readonly cache" if @readonly
68
+
69
+ @servers.each do |server|
70
+ server.flush_all
71
+ end
72
+ end
73
+
74
+ class Server
75
+ def flush_all
76
+ @mutex.lock if @multithread
77
+
78
+ socket.write "flush_all\r\n"
79
+ ensure
80
+ @mutex.unlock if @multithread
81
+ end
82
+ end
83
+ end
@@ -5,10 +5,13 @@ require 'yaml/store'
5
5
  module Ramaze
6
6
  class YAMLStoreCache
7
7
 
8
+ attr_accessor :file
9
+
8
10
  # create a new YAML::Store with the given file (which will be created if it
9
11
  # is not already there).
10
12
 
11
13
  def initialize(file = 'cache.yaml')
14
+ @file = file
12
15
  @cache = YAML::Store.new(file)
13
16
  end
14
17
 
@@ -20,6 +23,22 @@ module Ramaze
20
23
  end
21
24
  end
22
25
 
26
+ def underlying_yaml
27
+ YAML.load_file(@file)
28
+ end
29
+
30
+ def clear
31
+ transaction do |y|
32
+ File.open(@file, 'w+'){|f| f.puts({}.to_yaml)}
33
+ end
34
+ end
35
+
36
+ def delete(key)
37
+ transaction do |y|
38
+ y.delete(key)
39
+ end
40
+ end
41
+
23
42
  # just a helper to use transactions.
24
43
 
25
44
  def transaction(&block)