ramaze 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +4 -12
- data/bin/ramaze +95 -171
- data/doc/CHANGELOG +387 -4
- data/doc/README +81 -13
- data/doc/meta/announcement.txt +51 -8
- data/doc/meta/configuration.txt +17 -34
- data/doc/meta/internals.txt +34 -4
- data/doc/migrate/1110_to_1111.txt +131 -0
- data/doc/readme_chunks/features.txt +81 -12
- data/doc/readme_chunks/installing.txt +0 -1
- data/doc/tutorial/todolist.html +293 -65
- data/doc/tutorial/{todolist.txt → todolist.mkd} +251 -51
- data/examples/blog/main.rb +1 -1
- data/examples/blog/src/model.rb +0 -1
- data/examples/hello.rb +2 -5
- data/examples/templates/template/external.haml +5 -5
- data/examples/templates/template/external.liquid +1 -1
- data/examples/templates/template/external.mab +8 -8
- data/examples/templates/template/external.rem +30 -0
- data/examples/templates/template/external.rhtml +6 -7
- data/examples/templates/template/external.zmr +13 -9
- data/examples/templates/template_amrita2.rb +8 -8
- data/examples/templates/template_erubis.rb +11 -11
- data/examples/templates/template_ezamar.rb +9 -11
- data/examples/templates/template_haml.rb +13 -13
- data/examples/templates/template_liquid.rb +10 -10
- data/examples/templates/template_markaby.rb +13 -10
- data/examples/templates/template_remarkably.rb +59 -0
- data/examples/todolist/main.rb +1 -7
- data/examples/todolist/src/controller/main.rb +26 -13
- data/examples/todolist/src/element/page.rb +5 -0
- data/examples/whywiki/main.rb +1 -1
- data/lib/proto/main.rb +0 -8
- data/lib/proto/public/css/ramaze_error.css +12 -4
- data/lib/proto/public/error.zmr +6 -25
- data/lib/ramaze.rb +35 -245
- data/lib/ramaze/action.rb +21 -0
- data/lib/ramaze/adapter.rb +94 -29
- data/lib/ramaze/adapter/base.rb +57 -0
- data/lib/ramaze/adapter/mongrel.rb +12 -19
- data/lib/ramaze/adapter/webrick.rb +21 -20
- data/lib/ramaze/cache.rb +47 -3
- data/lib/ramaze/cache/memcached.rb +22 -0
- data/lib/ramaze/cache/yaml_store.rb +19 -0
- data/lib/ramaze/controller.rb +47 -271
- data/lib/ramaze/controller/error.rb +43 -0
- data/lib/ramaze/controller/render.rb +90 -0
- data/lib/ramaze/controller/resolve.rb +147 -0
- data/lib/ramaze/dispatcher.rb +41 -9
- data/lib/ramaze/dispatcher/file.rb +1 -1
- data/lib/ramaze/global.rb +73 -158
- data/lib/ramaze/global/dsl.rb +29 -0
- data/lib/ramaze/global/globalstruct.rb +90 -0
- data/lib/ramaze/helper.rb +1 -1
- data/lib/ramaze/helper/aspect.rb +39 -179
- data/lib/ramaze/helper/cache.rb +8 -9
- data/lib/ramaze/helper/cgi.rb +23 -0
- data/lib/ramaze/helper/file.rb +3 -0
- data/lib/ramaze/helper/inform.rb +3 -0
- data/lib/ramaze/helper/link.rb +56 -63
- data/lib/ramaze/helper/nitroform.rb +4 -0
- data/lib/ramaze/helper/redirect.rb +1 -1
- data/lib/ramaze/inform.rb +6 -2
- data/lib/ramaze/inform/analogger.rb +5 -1
- data/lib/ramaze/inform/hub.rb +1 -1
- data/lib/ramaze/inform/informing.rb +7 -0
- data/lib/ramaze/snippets/kernel/aquire.rb +2 -0
- data/lib/ramaze/snippets/kernel/constant.rb +2 -0
- data/lib/ramaze/snippets/kernel/pretty_inspect.rb +2 -0
- data/lib/ramaze/snippets/object/traits.rb +4 -0
- data/lib/ramaze/snippets/openstruct/temp.rb +3 -0
- data/lib/ramaze/snippets/string/DIVIDE.rb +2 -0
- data/lib/ramaze/snippets/string/camel_case.rb +2 -0
- data/lib/ramaze/snippets/string/color.rb +2 -0
- data/lib/ramaze/snippets/string/each.rb +2 -0
- data/lib/ramaze/snippets/string/snake_case.rb +3 -0
- data/lib/ramaze/snippets/struct/fill.rb +8 -2
- data/lib/ramaze/snippets/struct/values_at.rb +16 -0
- data/lib/ramaze/snippets/symbol/to_proc.rb +3 -0
- data/lib/ramaze/sourcereload.rb +89 -0
- data/lib/ramaze/template.rb +21 -12
- data/lib/ramaze/template/amrita2.rb +6 -6
- data/lib/ramaze/template/erubis.rb +4 -9
- data/lib/ramaze/template/ezamar.rb +13 -57
- data/lib/ramaze/template/ezamar/element.rb +10 -12
- data/lib/ramaze/template/ezamar/engine.rb +40 -101
- data/lib/ramaze/template/ezamar/morpher.rb +3 -3
- data/lib/ramaze/template/haml.rb +3 -6
- data/lib/ramaze/template/liquid.rb +4 -9
- data/lib/ramaze/template/markaby.rb +16 -22
- data/lib/ramaze/template/remarkably.rb +28 -0
- data/lib/ramaze/tool/mime.rb +2 -0
- data/lib/ramaze/tool/record.rb +6 -0
- data/lib/ramaze/trinity/request.rb +44 -54
- data/lib/ramaze/trinity/response.rb +1 -1
- data/lib/ramaze/trinity/session.rb +15 -37
- data/lib/ramaze/version.rb +1 -1
- data/rake_tasks/gem.rake +2 -2
- data/rake_tasks/maintaince.rake +42 -1
- data/rake_tasks/spec.rake +45 -0
- data/spec/examples/caching.rb +1 -1
- data/spec/examples/simple.rb +1 -1
- data/spec/examples/templates/template_amrita2.rb +1 -0
- data/spec/examples/templates/template_erubis.rb +2 -1
- data/spec/examples/templates/template_ezamar.rb +1 -1
- data/spec/examples/templates/template_haml.rb +2 -1
- data/spec/examples/templates/template_liquid.rb +2 -1
- data/spec/examples/templates/template_markaby.rb +2 -1
- data/spec/examples/templates/template_remarkably.rb +22 -0
- data/spec/examples/todolist.rb +125 -0
- data/spec/helper.rb +2 -23
- data/spec/helper/minimal.rb +20 -0
- data/spec/helper/mock_http.rb +24 -30
- data/spec/helper/simple_http.rb +2 -2
- data/spec/helper/wrap.rb +6 -9
- data/spec/ramaze/adapter.rb +1 -1
- data/spec/ramaze/adapter/record.rb +31 -0
- data/spec/ramaze/cache.rb +41 -54
- data/spec/ramaze/controller.rb +121 -137
- data/spec/ramaze/controller/template/list.xhtml +1 -0
- data/spec/ramaze/controller/template/other/greet/other.xhtml +1 -0
- data/spec/ramaze/controller/template_resolving.rb +27 -3
- data/spec/ramaze/element.rb +11 -7
- data/spec/ramaze/error.rb +1 -1
- data/spec/ramaze/gestalt.rb +2 -0
- data/spec/ramaze/helper/aspect.rb +30 -21
- data/spec/ramaze/helper/auth.rb +1 -1
- data/spec/ramaze/helper/cache.rb +2 -1
- data/spec/ramaze/helper/form.rb +14 -11
- data/spec/ramaze/helper/link.rb +18 -41
- data/spec/ramaze/localize.rb +29 -2
- data/spec/ramaze/morpher.rb +23 -12
- data/spec/ramaze/params.rb +46 -24
- data/spec/ramaze/request.rb +6 -2
- data/spec/ramaze/store/yaml.rb +5 -0
- data/spec/ramaze/template.rb +22 -27
- data/spec/ramaze/template/amrita2.rb +1 -2
- data/spec/ramaze/template/erubis.rb +1 -1
- data/spec/ramaze/template/ezamar.rb +1 -2
- data/spec/ramaze/template/haml.rb +2 -2
- data/spec/ramaze/template/haml/with_vars.haml +1 -1
- data/spec/ramaze/template/liquid.rb +1 -1
- data/spec/ramaze/template/markaby.rb +1 -1
- data/spec/ramaze/template/remarkably.rb +56 -0
- data/spec/ramaze/template/remarkably/external.rem +8 -0
- data/spec/ramaze/template/remarkably/sum.rem +1 -0
- metadata +38 -63
- data/doc/README.html +0 -637
- data/doc/allison/LICENSE +0 -184
- data/doc/allison/README +0 -37
- data/doc/allison/allison.css +0 -299
- data/doc/allison/allison.gif +0 -0
- data/doc/allison/allison.js +0 -307
- data/doc/allison/allison.rb +0 -287
- data/doc/allison/cache/BODY +0 -588
- data/doc/allison/cache/CLASS_INDEX +0 -4
- data/doc/allison/cache/CLASS_PAGE +0 -1
- data/doc/allison/cache/FILE_INDEX +0 -4
- data/doc/allison/cache/FILE_PAGE +0 -1
- data/doc/allison/cache/FONTS +0 -1
- data/doc/allison/cache/FR_INDEX_BODY +0 -1
- data/doc/allison/cache/IMGPATH +0 -1
- data/doc/allison/cache/INDEX +0 -1
- data/doc/allison/cache/JAVASCRIPT +0 -307
- data/doc/allison/cache/METHOD_INDEX +0 -4
- data/doc/allison/cache/METHOD_LIST +0 -1
- data/doc/allison/cache/SRC_PAGE +0 -1
- data/doc/allison/cache/STYLE +0 -321
- data/doc/allison/cache/URL +0 -1
- data/doc/changes.txt +0 -3375
- data/doc/changes.xml +0 -3378
- data/examples/todolist/conf/benchmark.yaml +0 -35
- data/examples/todolist/conf/debug.yaml +0 -34
- data/examples/todolist/conf/live.yaml +0 -33
- data/examples/todolist/conf/silent.yaml +0 -31
- data/examples/todolist/conf/stage.yaml +0 -33
- data/examples/todolist/public/css/coderay.css +0 -105
- data/examples/todolist/public/css/ramaze_error.css +0 -42
- data/lib/proto/conf/benchmark.yaml +0 -21
- data/lib/proto/conf/debug.yaml +0 -21
- data/lib/proto/conf/live.yaml +0 -21
- data/lib/proto/conf/silent.yaml +0 -21
- data/lib/proto/conf/stage.yaml +0 -21
- data/lib/proto/public/css/coderay.css +0 -105
- data/lib/ramaze/http_status.rb +0 -66
- data/lib/ramaze/snippets/hash/keys_to_sym.rb +0 -19
- data/lib/ramaze/snippets/kernel/method.rb +0 -26
- data/lib/ramaze/snippets/method/name.rb +0 -22
- data/lib/ramaze/snippets/ramaze/autoreload.rb +0 -135
- data/lib/ramaze/snippets/rdoc/usage_no_exit.rb +0 -65
- data/spec/all.rb +0 -32
- data/spec/ramaze/conf/locale_de.yaml +0 -6
- data/spec/ramaze/conf/locale_en.yaml +0 -6
- data/spec/ramaze/dependencies.rb +0 -16
- 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
|
data/lib/ramaze/adapter.rb
CHANGED
@@ -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 '
|
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
|
-
|
13
|
-
include Ramaze::Request
|
14
|
-
end
|
18
|
+
module Ramaze
|
15
19
|
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
21
|
-
|
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
|
-
|
24
|
-
|
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
|
-
|
28
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
41
|
-
|
92
|
+
# check the given host and ports via test_connection.
|
93
|
+
# Shuts down if no connection is possible.
|
42
94
|
|
43
|
-
|
44
|
-
|
95
|
+
def test_connections host, ports
|
96
|
+
return unless Global.test_connections
|
45
97
|
|
46
|
-
|
47
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
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
|
9
|
-
|
10
|
-
class
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
18
|
-
|
19
|
-
class
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
36
|
-
|
37
|
-
|
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
|
data/lib/ramaze/cache.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
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)
|