merb-core 0.9.3 → 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README +3 -3
- data/Rakefile +144 -33
- data/bin/merb +0 -0
- data/bin/merb-specs +0 -0
- data/docs/bootloading.dox +1 -0
- data/docs/merb-core-call-stack-diagram.mmap +0 -0
- data/docs/merb-core-call-stack-diagram.pdf +0 -0
- data/docs/merb-core-call-stack-diagram.png +0 -0
- data/lib/merb-core.rb +159 -37
- data/lib/merb-core/autoload.rb +1 -0
- data/lib/merb-core/bootloader.rb +208 -92
- data/lib/merb-core/config.rb +20 -6
- data/lib/merb-core/controller/abstract_controller.rb +113 -61
- data/lib/merb-core/controller/exceptions.rb +28 -13
- data/lib/merb-core/controller/merb_controller.rb +73 -44
- data/lib/merb-core/controller/mime.rb +25 -7
- data/lib/merb-core/controller/mixins/authentication.rb +1 -1
- data/lib/merb-core/controller/mixins/controller.rb +44 -8
- data/lib/merb-core/controller/mixins/render.rb +191 -128
- data/lib/merb-core/controller/mixins/responder.rb +65 -63
- data/lib/merb-core/controller/template.rb +103 -54
- data/lib/merb-core/core_ext.rb +7 -12
- data/lib/merb-core/core_ext/kernel.rb +128 -136
- data/lib/merb-core/dispatch/cookies.rb +26 -4
- data/lib/merb-core/dispatch/default_exception/default_exception.rb +93 -0
- data/lib/merb-core/dispatch/default_exception/views/_css.html.erb +198 -0
- data/lib/merb-core/dispatch/default_exception/views/_javascript.html.erb +73 -0
- data/lib/merb-core/dispatch/default_exception/views/index.html.erb +92 -0
- data/lib/merb-core/dispatch/dispatcher.rb +156 -224
- data/lib/merb-core/dispatch/request.rb +126 -25
- data/lib/merb-core/dispatch/router.rb +61 -6
- data/lib/merb-core/dispatch/router/behavior.rb +122 -41
- data/lib/merb-core/dispatch/router/route.rb +147 -22
- data/lib/merb-core/dispatch/session.rb +52 -2
- data/lib/merb-core/dispatch/session/cookie.rb +4 -2
- data/lib/merb-core/dispatch/session/memcached.rb +38 -27
- data/lib/merb-core/dispatch/session/memory.rb +18 -11
- data/lib/merb-core/dispatch/worker.rb +28 -0
- data/lib/merb-core/gem_ext/erubis.rb +58 -0
- data/lib/merb-core/logger.rb +3 -31
- data/lib/merb-core/plugins.rb +25 -3
- data/lib/merb-core/rack.rb +18 -12
- data/lib/merb-core/rack/adapter.rb +10 -8
- data/lib/merb-core/rack/adapter/ebb.rb +2 -2
- data/lib/merb-core/rack/adapter/irb.rb +31 -21
- data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +26 -0
- data/lib/merb-core/rack/adapter/thin.rb +19 -9
- data/lib/merb-core/rack/adapter/thin_turbo.rb +24 -0
- data/lib/merb-core/rack/application.rb +9 -84
- data/lib/merb-core/rack/middleware.rb +26 -0
- data/lib/merb-core/rack/middleware/path_prefix.rb +31 -0
- data/lib/merb-core/rack/middleware/profiler.rb +19 -0
- data/lib/merb-core/rack/middleware/static.rb +45 -0
- data/lib/merb-core/server.rb +27 -9
- data/lib/merb-core/tasks/audit.rake +68 -0
- data/lib/merb-core/tasks/merb.rb +1 -0
- data/lib/merb-core/tasks/merb_rake_helper.rb +12 -0
- data/lib/merb-core/tasks/stats.rake +71 -0
- data/lib/merb-core/test.rb +2 -1
- data/lib/merb-core/test/helpers/multipart_request_helper.rb +3 -3
- data/lib/merb-core/test/helpers/request_helper.rb +66 -24
- data/lib/merb-core/test/matchers/controller_matchers.rb +36 -4
- data/lib/merb-core/test/matchers/route_matchers.rb +12 -3
- data/lib/merb-core/test/matchers/view_matchers.rb +3 -3
- data/lib/merb-core/test/run_specs.rb +1 -0
- data/lib/merb-core/test/tasks/spectasks.rb +13 -5
- data/lib/merb-core/test/test_ext/string.rb +14 -0
- data/lib/merb-core/vendor/facets/dictionary.rb +3 -3
- data/lib/merb-core/vendor/facets/inflect.rb +82 -37
- data/lib/merb-core/version.rb +2 -2
- data/spec/private/config/config_spec.rb +39 -4
- data/spec/private/core_ext/kernel_spec.rb +3 -14
- data/spec/private/dispatch/bootloader_spec.rb +1 -1
- data/spec/private/dispatch/cookies_spec.rb +181 -69
- data/spec/private/dispatch/fixture/app/controllers/exceptions.rb +0 -2
- data/spec/private/dispatch/fixture/app/controllers/foo.rb +0 -2
- data/spec/private/dispatch/fixture/config/rack.rb +10 -0
- data/spec/private/dispatch/fixture/log/merb_test.log +7054 -1802
- data/spec/private/dispatch/route_params_spec.rb +2 -3
- data/spec/private/dispatch/session_mixin_spec.rb +47 -0
- data/spec/private/plugins/plugin_spec.rb +73 -59
- data/spec/private/router/behavior_spec.rb +60 -0
- data/spec/private/router/fixture/log/merb_test.log +1693 -0
- data/spec/private/router/route_spec.rb +414 -0
- data/spec/private/router/router_spec.rb +175 -0
- data/spec/private/vendor/facets/plural_spec.rb +564 -0
- data/spec/private/vendor/facets/singular_spec.rb +489 -0
- data/spec/public/abstract_controller/controllers/cousins.rb +41 -0
- data/spec/public/abstract_controller/controllers/helpers.rb +12 -2
- data/spec/public/abstract_controller/controllers/partial.rb +17 -2
- data/spec/public/abstract_controller/controllers/render.rb +16 -1
- data/spec/public/abstract_controller/controllers/views/helpers/capture_eq/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/helpers/capture_with_args/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/merb/test/fixtures/abstract/render_two_throw_contents/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/_collection.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/partial_with_collections_and_counter/index.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/_partial.erb +1 -0
- data/spec/public/abstract_controller/controllers/views/partial/with_absolute_partial/index.erb +1 -0
- data/spec/public/abstract_controller/filter_spec.rb +20 -1
- data/spec/public/abstract_controller/helper_spec.rb +10 -2
- data/spec/public/abstract_controller/partial_spec.rb +8 -0
- data/spec/public/abstract_controller/render_spec.rb +8 -0
- data/spec/public/abstract_controller/spec_helper.rb +7 -3
- data/spec/public/boot_loader/boot_loader_spec.rb +2 -2
- data/spec/public/controller/base_spec.rb +10 -2
- data/spec/public/controller/config/init.rb +6 -0
- data/spec/public/controller/controllers/authentication.rb +9 -11
- data/spec/public/controller/controllers/base.rb +2 -8
- data/spec/public/controller/controllers/cookies.rb +16 -0
- data/spec/public/controller/controllers/dispatcher.rb +35 -0
- data/spec/public/controller/controllers/display.rb +62 -14
- data/spec/public/controller/controllers/redirect.rb +36 -0
- data/spec/public/controller/controllers/responder.rb +37 -11
- data/spec/public/controller/controllers/views/layout/custom_arg.json.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.html.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/class_and_local_provides/index.xml.erb +1 -0
- data/spec/public/controller/controllers/views/merb/test/fixtures/controllers/display_with_template/no_layout.html.erb +1 -0
- data/spec/public/controller/cookies_spec.rb +23 -0
- data/spec/public/controller/dispatcher_spec.rb +411 -0
- data/spec/public/controller/display_spec.rb +43 -10
- data/spec/public/controller/redirect_spec.rb +33 -0
- data/spec/public/controller/responder_spec.rb +79 -11
- data/spec/public/controller/spec_helper.rb +3 -1
- data/spec/public/controller/url_spec.rb +10 -0
- data/spec/public/core/merb_core_spec.rb +11 -0
- data/spec/public/core_ext/fixtures/core_ext_dependency.rb +2 -0
- data/spec/public/core_ext/kernel_spec.rb +9 -0
- data/spec/public/core_ext/spec_helper.rb +1 -0
- data/spec/public/directory_structure/directory/log/merb_test.log +3729 -272
- data/spec/public/directory_structure/directory_spec.rb +3 -4
- data/spec/public/logger/logger_spec.rb +4 -4
- data/spec/public/reloading/directory/log/merb_test.log +288066 -15
- data/spec/public/reloading/reload_spec.rb +49 -27
- data/spec/public/request/multipart_spec.rb +26 -0
- data/spec/public/request/request_spec.rb +21 -2
- data/spec/public/router/fixation_spec.rb +27 -0
- data/spec/public/router/fixture/log/merb_test.log +30050 -0
- data/spec/public/router/nested_matches_spec.rb +97 -0
- data/spec/public/router/resource_spec.rb +1 -9
- data/spec/public/router/resources_spec.rb +0 -20
- data/spec/public/router/spec_helper.rb +27 -9
- data/spec/public/router/special_spec.rb +21 -8
- data/spec/public/template/template_spec.rb +17 -5
- data/spec/public/test/controller_matchers_spec.rb +10 -0
- data/spec/public/test/request_helper_spec.rb +29 -0
- data/spec/public/test/route_helper_spec.rb +18 -1
- data/spec/public/test/route_matchers_spec.rb +28 -1
- data/spec/public/test/view_matchers_spec.rb +3 -3
- data/spec/spec_helper.rb +56 -12
- metadata +89 -47
- data/lib/merb-core/core_ext/class.rb +0 -299
- data/lib/merb-core/core_ext/hash.rb +0 -426
- data/lib/merb-core/core_ext/mash.rb +0 -154
- data/lib/merb-core/core_ext/object.rb +0 -147
- data/lib/merb-core/core_ext/object_space.rb +0 -14
- data/lib/merb-core/core_ext/rubygems.rb +0 -28
- data/lib/merb-core/core_ext/set.rb +0 -46
- data/lib/merb-core/core_ext/string.rb +0 -89
- data/lib/merb-core/core_ext/time.rb +0 -13
- data/lib/merb-core/dispatch/exceptions.html.erb +0 -297
- data/spec/private/core_ext/class_spec.rb +0 -22
- data/spec/private/core_ext/hash_spec.rb +0 -522
- data/spec/private/core_ext/object_spec.rb +0 -121
- data/spec/private/core_ext/set_spec.rb +0 -26
- data/spec/private/core_ext/string_spec.rb +0 -167
- data/spec/private/core_ext/time_spec.rb +0 -16
- data/spec/private/dispatch/dispatch_spec.rb +0 -26
- data/spec/private/dispatch/fixture/log/development.log +0 -1
- data/spec/private/dispatch/fixture/log/merb.4000.pid +0 -1
- data/spec/private/dispatch/fixture/log/production.log +0 -1
- data/spec/private/dispatch/fixture/merb.4000.pid +0 -1
- data/spec/private/rack/application_spec.rb +0 -43
- data/spec/public/controller/log/merb.4000.pid +0 -1
- data/spec/public/directory_structure/directory/log/merb.4000.pid +0 -1
- data/spec/public/directory_structure/directory/merb.4000.pid +0 -1
- data/spec/public/reloading/directory/log/merb.4000.pid +0 -1
- data/spec/public/reloading/directory/merb.4000.pid +0 -1
@@ -1,7 +1,19 @@
|
|
1
1
|
module Merb
|
2
2
|
|
3
3
|
module SessionMixin
|
4
|
+
# Sets the session id cookie, along with the correct
|
5
|
+
# expiry and domain -- used for new or reset sessions
|
6
|
+
def set_session_id_cookie(key)
|
7
|
+
options = {}
|
8
|
+
options[:value] = key
|
9
|
+
options[:expires] = Time.now + _session_expiry if _session_expiry > 0
|
10
|
+
options[:domain] = _session_cookie_domain if _session_cookie_domain
|
11
|
+
cookies[_session_id_key] = options
|
12
|
+
end
|
4
13
|
|
14
|
+
@_finalize_session_exception_callbacks = []
|
15
|
+
@_persist_exception_callbacks = []
|
16
|
+
|
5
17
|
# ==== Returns
|
6
18
|
# String:: A random 32 character string for use as a unique session ID.
|
7
19
|
def rand_uuid
|
@@ -21,8 +33,46 @@ module Merb
|
|
21
33
|
def needs_new_cookie!
|
22
34
|
@_new_cookie = true
|
23
35
|
end
|
36
|
+
|
37
|
+
# Adds a callback to the list of callbacks run when
|
38
|
+
# exception is raised on session finalization, so
|
39
|
+
# you can recover.
|
40
|
+
#
|
41
|
+
# See session mixins documentation for details on
|
42
|
+
# session finalization.
|
43
|
+
#
|
44
|
+
# ==== Params
|
45
|
+
# &block::
|
46
|
+
# A block to be added to the callbacks that will be executed
|
47
|
+
# if there's exception on session finalization.
|
48
|
+
def finalize_session_exception_callbacks(&block)
|
49
|
+
if block_given?
|
50
|
+
@_finalize_session_exception_callbacks << block
|
51
|
+
else
|
52
|
+
@_finalize_session_exception_callbacks
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Adds a callback to the list of callbacks run when
|
57
|
+
# exception is raised on session persisting, so
|
58
|
+
# you can recover.
|
59
|
+
#
|
60
|
+
# See session mixins documentation for details on
|
61
|
+
# session persisting.
|
62
|
+
#
|
63
|
+
# ==== Params
|
64
|
+
# &block::
|
65
|
+
# A block to be added to the callbacks that will be executed
|
66
|
+
# if there's exception on session persisting.
|
67
|
+
def persist_exception_callbacks(&block)
|
68
|
+
if block_given?
|
69
|
+
@_persist_exception_callbacks << block
|
70
|
+
else
|
71
|
+
@_persist_exception_callbacks
|
72
|
+
end
|
73
|
+
end
|
24
74
|
|
25
|
-
module_function :rand_uuid, :needs_new_cookie
|
75
|
+
module_function :rand_uuid, :needs_new_cookie!, :finalize_session_exception_callbacks, :persist_exception_callbacks
|
26
76
|
end
|
27
77
|
|
28
|
-
end
|
78
|
+
end
|
@@ -3,7 +3,7 @@ require 'openssl' # to generate the HMAC message digest
|
|
3
3
|
# Most of this code is taken from bitsweat's implementation in rails
|
4
4
|
module Merb
|
5
5
|
|
6
|
-
module SessionMixin
|
6
|
+
module SessionMixin
|
7
7
|
|
8
8
|
# Adds a before and after dispatch hook for setting up the cookie session
|
9
9
|
# store.
|
@@ -20,7 +20,9 @@ module Merb
|
|
20
20
|
def finalize_session
|
21
21
|
new_session = request.session.read_cookie
|
22
22
|
if @original_session != new_session
|
23
|
-
|
23
|
+
options = {:expires => (Time.now + _session_expiry)}
|
24
|
+
options[:domain] = _session_cookie_domain if _session_cookie_domain
|
25
|
+
cookies.set_cookie(_session_id_key, new_session, options)
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Merb
|
2
2
|
|
3
|
-
module SessionMixin
|
3
|
+
module SessionMixin
|
4
4
|
|
5
5
|
# Adds a before and after dispatch hook for setting up the memcached
|
6
6
|
# session store.
|
@@ -8,23 +8,29 @@ module Merb
|
|
8
8
|
# ==== Parameters
|
9
9
|
# base<Class>:: The class to which the SessionMixin is mixed into.
|
10
10
|
def setup_session
|
11
|
-
|
12
|
-
|
11
|
+
orig_key = cookies[_session_id_key]
|
12
|
+
session, key = Merb::MemCacheSession.persist(orig_key)
|
13
|
+
request.session = session
|
13
14
|
@_fingerprint = Marshal.dump(request.session.data).hash
|
14
|
-
|
15
|
+
if key != orig_key
|
16
|
+
set_session_id_cookie(key)
|
17
|
+
end
|
15
18
|
end
|
16
19
|
|
17
20
|
# Finalizes the session by storing the session ID in a cookie, if the
|
18
21
|
# session has changed.
|
19
|
-
def finalize_session
|
22
|
+
def finalize_session
|
20
23
|
if @_fingerprint != Marshal.dump(request.session.data).hash
|
21
24
|
begin
|
22
25
|
CACHE.set("session:#{request.session.session_id}", request.session.data)
|
23
26
|
rescue => err
|
24
27
|
Merb.logger.debug("MemCache Error: #{err.message}")
|
28
|
+
Merb::SessionMixin::finalize_session_exception_callbacks.each {|x| x.call(err) }
|
25
29
|
end
|
26
30
|
end
|
27
|
-
|
31
|
+
if request.session.needs_new_cookie or @_new_cookie
|
32
|
+
set_session_id_cookie(request.session.session_id)
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
# ==== Returns
|
@@ -82,12 +88,17 @@ module Merb
|
|
82
88
|
# Array::
|
83
89
|
# A pair consisting of a MemCacheSession and the session's ID. If no
|
84
90
|
# sessions matched session_id, a new MemCacheSession will be generated.
|
91
|
+
#
|
92
|
+
# ==== Notes
|
93
|
+
# If there are persiste exceptions callbacks to execute, they all get executed
|
94
|
+
# when Memcache library raises an exception.
|
85
95
|
def persist(session_id)
|
86
96
|
unless session_id.blank?
|
87
97
|
begin
|
88
98
|
session = CACHE.get("session:#{session_id}")
|
89
99
|
rescue => err
|
90
|
-
Merb.logger.
|
100
|
+
Merb.logger.warn!("Could not persist session to MemCache: #{err.message}")
|
101
|
+
Merb::SessionMixin::persist_exception_callbacks.each {|x| x.call(err) }
|
91
102
|
end
|
92
103
|
if session.nil?
|
93
104
|
# Not in memcached, but assume that cookie exists
|
@@ -108,27 +119,27 @@ module Merb
|
|
108
119
|
end
|
109
120
|
|
110
121
|
# Don't try to reload in dev mode.
|
111
|
-
def reloadable?
|
122
|
+
def reloadable?
|
112
123
|
false
|
113
124
|
end
|
114
125
|
|
115
126
|
end
|
116
127
|
|
117
128
|
# Regenerate the session ID.
|
118
|
-
def regenerate
|
119
|
-
@session_id = Merb::SessionMixin::rand_uuid
|
120
|
-
self.needs_new_cookie=true
|
121
|
-
end
|
122
|
-
|
129
|
+
def regenerate
|
130
|
+
@session_id = Merb::SessionMixin::rand_uuid
|
131
|
+
self.needs_new_cookie=true
|
132
|
+
end
|
133
|
+
|
123
134
|
# Recreates the cookie with the default expiration time. Useful during log
|
124
135
|
# in for pushing back the expiration date.
|
125
|
-
def refresh_expiration
|
126
|
-
self.needs_new_cookie=true
|
127
|
-
end
|
128
|
-
|
136
|
+
def refresh_expiration
|
137
|
+
self.needs_new_cookie=true
|
138
|
+
end
|
139
|
+
|
129
140
|
# Deletes the session by emptying stored data.
|
130
|
-
def delete
|
131
|
-
@data = {}
|
141
|
+
def delete
|
142
|
+
@data = {}
|
132
143
|
end
|
133
144
|
|
134
145
|
# ==== Returns
|
@@ -136,11 +147,11 @@ module Merb
|
|
136
147
|
def loaded?
|
137
148
|
!! @data
|
138
149
|
end
|
139
|
-
|
150
|
+
|
140
151
|
# ==== Parameters
|
141
152
|
# k<~to_s>:: The key of the session parameter to set.
|
142
153
|
# v<~to_s>:: The value of the session parameter to set.
|
143
|
-
def []=(k, v)
|
154
|
+
def []=(k, v)
|
144
155
|
@data[k] = v
|
145
156
|
end
|
146
157
|
|
@@ -149,18 +160,18 @@ module Merb
|
|
149
160
|
#
|
150
161
|
# ==== Returns
|
151
162
|
# String:: The value of the session parameter.
|
152
|
-
def [](k)
|
153
|
-
@data[k]
|
163
|
+
def [](k)
|
164
|
+
@data[k]
|
154
165
|
end
|
155
166
|
|
156
167
|
# Yields the session data to an each block.
|
157
168
|
#
|
158
169
|
# ==== Parameter
|
159
170
|
# &b:: The block to pass to each.
|
160
|
-
def each(&b)
|
161
|
-
@data.each(&b)
|
171
|
+
def each(&b)
|
172
|
+
@data.each(&b)
|
162
173
|
end
|
163
|
-
|
174
|
+
|
164
175
|
private
|
165
176
|
|
166
177
|
# Attempts to redirect any messages to the data object.
|
@@ -170,4 +181,4 @@ module Merb
|
|
170
181
|
|
171
182
|
end
|
172
183
|
|
173
|
-
end
|
184
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Merb
|
2
2
|
|
3
|
-
module SessionMixin
|
3
|
+
module SessionMixin
|
4
4
|
|
5
5
|
# Adds a before and after dispatch hook for setting up the memory session
|
6
6
|
# store.
|
@@ -8,15 +8,20 @@ module Merb
|
|
8
8
|
# ==== Parameters
|
9
9
|
# base<Class>:: The class to which the SessionMixin is mixed into.
|
10
10
|
def setup_session
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
orig_key = cookies[_session_id_key]
|
12
|
+
session, key = Merb::MemorySession.persist(orig_key)
|
13
|
+
request.session = session
|
14
|
+
if key != orig_key
|
15
|
+
set_session_id_cookie(key)
|
16
|
+
end
|
14
17
|
end
|
15
18
|
|
16
19
|
# Finalizes the session by storing the session ID in a cookie, if the
|
17
20
|
# session has changed.
|
18
21
|
def finalize_session
|
19
|
-
|
22
|
+
if request.session.needs_new_cookie or @_new_cookie
|
23
|
+
set_session_id_cookie(request.session.session_id)
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
# ==== Returns
|
@@ -29,10 +34,12 @@ module Merb
|
|
29
34
|
##
|
30
35
|
# Sessions stored in memory.
|
31
36
|
#
|
32
|
-
#
|
37
|
+
# Set it up by adding the following to your init file:
|
33
38
|
#
|
34
|
-
#
|
35
|
-
#
|
39
|
+
# Merb::Config.use do |c|
|
40
|
+
# c[:session_store] = :memory
|
41
|
+
# c[:memory_session_ttl] = 3600 # in seconds, one hour
|
42
|
+
# end
|
36
43
|
#
|
37
44
|
# Sessions will remain in memory until the server is stopped or the time
|
38
45
|
# as set in :memory_session_ttl expires.
|
@@ -94,10 +101,10 @@ module Merb
|
|
94
101
|
def refresh_expiration
|
95
102
|
self.needs_new_cookie=true
|
96
103
|
end
|
97
|
-
|
104
|
+
|
98
105
|
# Deletes the session by emptying stored data.
|
99
106
|
def delete
|
100
|
-
@data = {}
|
107
|
+
@data = {}
|
101
108
|
end
|
102
109
|
|
103
110
|
# ==== Returns
|
@@ -231,4 +238,4 @@ module Merb
|
|
231
238
|
end # end MemorySessionContainer
|
232
239
|
end
|
233
240
|
|
234
|
-
Merb::MemorySessionContainer.setup(Merb::Config[:memory_session_ttl])
|
241
|
+
Merb::MemorySessionContainer.setup(Merb::Config[:memory_session_ttl])
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Merb
|
2
|
+
class Worker
|
3
|
+
|
4
|
+
attr_accessor :thread
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@thread = Thread.new { loop { process_queue } }
|
8
|
+
end
|
9
|
+
|
10
|
+
def process_queue
|
11
|
+
begin
|
12
|
+
while blk = Merb::Dispatcher.work_queue.pop
|
13
|
+
# we've been blocking on the queue waiting for an item sleeping.
|
14
|
+
# when someone pushes an item it wakes up this thread so we
|
15
|
+
# immediately pass execution to the scheduler so we don't
|
16
|
+
# accidentally run this block before the action finishes
|
17
|
+
# it's own processing
|
18
|
+
Thread.pass
|
19
|
+
blk.call
|
20
|
+
end
|
21
|
+
rescue Exception => e
|
22
|
+
Merb.logger.warn! %Q!Worker Thread Crashed with Exception:\n#{Merb.exception(e)}\nRestarting Worker Thread!
|
23
|
+
retry
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -1,5 +1,63 @@
|
|
1
1
|
require 'erubis'
|
2
2
|
module Erubis
|
3
|
+
module Basic::Converter
|
4
|
+
def convert_input(src, input)
|
5
|
+
pat = @pattern
|
6
|
+
regexp = pat.nil? || pat == '<% %>' ? DEFAULT_REGEXP : pattern_regexp(pat)
|
7
|
+
pos = 0
|
8
|
+
is_bol = true # is beginning of line
|
9
|
+
input.scan(regexp) do |indicator, code, tailch, rspace|
|
10
|
+
match = Regexp.last_match()
|
11
|
+
len = match.begin(0) - pos
|
12
|
+
text = input[pos, len]
|
13
|
+
pos = match.end(0)
|
14
|
+
ch = indicator ? indicator[0] : nil
|
15
|
+
lspace = ch == ?= ? nil : detect_spaces_at_bol(text, is_bol)
|
16
|
+
is_bol = rspace ? true : false
|
17
|
+
add_text(src, text) if text && !text.empty?
|
18
|
+
## * when '<%= %>', do nothing
|
19
|
+
## * when '<% %>' or '<%# %>', delete spaces iff only spaces are around '<% %>'
|
20
|
+
if ch == ?= # <%= %>
|
21
|
+
rspace = nil if tailch && !tailch.empty?
|
22
|
+
add_text(src, lspace) if lspace
|
23
|
+
add_expr(src, code, indicator)
|
24
|
+
add_text(src, rspace) if rspace
|
25
|
+
elsif ch == ?\# # <%# %>
|
26
|
+
n = code.count("\n") + (rspace ? 1 : 0)
|
27
|
+
if @trim && lspace && rspace
|
28
|
+
add_stmt(src, "\n" * n)
|
29
|
+
else
|
30
|
+
add_text(src, lspace) if lspace
|
31
|
+
add_stmt(src, "\n" * n)
|
32
|
+
add_text(src, rspace) if rspace
|
33
|
+
end
|
34
|
+
elsif ch == ?% # <%% %>
|
35
|
+
s = "#{lspace}#{@prefix||='<%'}#{code}#{tailch}#{@postfix||='%>'}#{rspace}"
|
36
|
+
add_text(src, s)
|
37
|
+
else # <% %>
|
38
|
+
if @trim && lspace && rspace
|
39
|
+
if respond_to?(:add_stmt2)
|
40
|
+
add_stmt2(src, "#{lspace}#{code}#{rspace}", tailch)
|
41
|
+
else
|
42
|
+
add_stmt(src, "#{lspace}#{code}#{rspace}")
|
43
|
+
end
|
44
|
+
else
|
45
|
+
add_text(src, lspace) if lspace
|
46
|
+
if respond_to?(:add_stmt2)
|
47
|
+
add_stmt2(src, code, tailch)
|
48
|
+
else
|
49
|
+
add_stmt(src, code)
|
50
|
+
end
|
51
|
+
add_text(src, rspace) if rspace
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
#rest = $' || input # ruby1.8
|
56
|
+
rest = pos == 0 ? input : input[pos..-1] # ruby1.9
|
57
|
+
add_text(src, rest)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
3
61
|
|
4
62
|
class MEruby < Erubis::Eruby
|
5
63
|
include PercentLineEnhancer
|
data/lib/merb-core/logger.rb
CHANGED
@@ -33,13 +33,12 @@ require "time" # httpdate
|
|
33
33
|
# Merb::Logger.new(log{String, IO},level{Symbol, String})
|
34
34
|
module Merb
|
35
35
|
|
36
|
-
class << self
|
36
|
+
class << self
|
37
37
|
attr_accessor :logger
|
38
38
|
end
|
39
39
|
|
40
40
|
class Logger
|
41
41
|
|
42
|
-
attr_accessor :aio
|
43
42
|
attr_accessor :level
|
44
43
|
attr_accessor :delimiter
|
45
44
|
attr_accessor :auto_flush
|
@@ -61,36 +60,10 @@ module Merb
|
|
61
60
|
:warn => 4,
|
62
61
|
:info => 3,
|
63
62
|
:debug => 0
|
64
|
-
}
|
63
|
+
} unless const_defined?(:Levels)
|
65
64
|
|
66
65
|
private
|
67
66
|
|
68
|
-
# Define the write method based on if asynchronous IO an be used.
|
69
|
-
#
|
70
|
-
# ==== Notes
|
71
|
-
# The idea here is that instead of performing an 'if' conditional check on
|
72
|
-
# each logging we do it once when the log object is setup.
|
73
|
-
def set_write_method
|
74
|
-
@log.instance_eval do
|
75
|
-
|
76
|
-
# ==== Returns
|
77
|
-
# Boolean:: True if asynchronous IO can be used.
|
78
|
-
def aio?
|
79
|
-
@aio = !Merb.environment.to_s.match(/development|test/) &&
|
80
|
-
!RUBY_PLATFORM.match(/java|mswin/) &&
|
81
|
-
!(@log == STDOUT) &&
|
82
|
-
@log.respond_to?(:write_nonblock)
|
83
|
-
end
|
84
|
-
|
85
|
-
undef write_method if defined? write_method #:nodoc:
|
86
|
-
if aio?
|
87
|
-
alias :write_method :write_nonblock
|
88
|
-
else
|
89
|
-
alias :write_method :write
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
67
|
# Readies a log for writing.
|
95
68
|
#
|
96
69
|
# ==== Parameters
|
@@ -109,7 +82,6 @@ module Merb
|
|
109
82
|
@log.sync = true
|
110
83
|
@log.write("#{Time.now.httpdate} #{delimiter} info #{delimiter} Logfile created\n")
|
111
84
|
end
|
112
|
-
set_write_method
|
113
85
|
end
|
114
86
|
|
115
87
|
public
|
@@ -155,7 +127,7 @@ module Merb
|
|
155
127
|
# Flush the entire buffer to the log object.
|
156
128
|
def flush
|
157
129
|
return unless @buffer.size > 0
|
158
|
-
@log.
|
130
|
+
@log.write(@buffer.slice!(0..-1).to_s)
|
159
131
|
end
|
160
132
|
|
161
133
|
# Close and remove the current log object.
|