merb-core 0.9.13 → 1.0
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.
- data/Rakefile +5 -3
- data/lib/merb-core.rb +84 -41
- data/lib/merb-core/bootloader.rb +71 -60
- data/lib/merb-core/config.rb +31 -17
- data/lib/merb-core/controller/abstract_controller.rb +35 -35
- data/lib/merb-core/controller/exceptions.rb +14 -9
- data/lib/merb-core/controller/merb_controller.rb +22 -20
- data/lib/merb-core/controller/mime.rb +5 -5
- data/lib/merb-core/controller/mixins/authentication.rb +11 -8
- data/lib/merb-core/controller/mixins/conditional_get.rb +7 -7
- data/lib/merb-core/controller/mixins/controller.rb +15 -15
- data/lib/merb-core/controller/mixins/render.rb +16 -16
- data/lib/merb-core/controller/mixins/responder.rb +23 -23
- data/lib/merb-core/controller/template.rb +17 -17
- data/lib/merb-core/core_ext/hash.rb +2 -2
- data/lib/merb-core/core_ext/kernel.rb +19 -18
- data/lib/merb-core/dispatch/cookies.rb +13 -0
- data/lib/merb-core/dispatch/default_exception/default_exception.rb +12 -1
- data/lib/merb-core/dispatch/dispatcher.rb +6 -5
- data/lib/merb-core/dispatch/request.rb +56 -52
- data/lib/merb-core/dispatch/request_parsers.rb +7 -7
- data/lib/merb-core/dispatch/router.rb +14 -14
- data/lib/merb-core/dispatch/router/behavior.rb +31 -31
- data/lib/merb-core/dispatch/router/cached_proc.rb +13 -1
- data/lib/merb-core/dispatch/router/resources.rb +9 -9
- data/lib/merb-core/dispatch/router/route.rb +60 -7
- data/lib/merb-core/dispatch/session.rb +21 -15
- data/lib/merb-core/dispatch/session/container.rb +10 -8
- data/lib/merb-core/dispatch/session/cookie.rb +12 -11
- data/lib/merb-core/dispatch/session/memcached.rb +4 -2
- data/lib/merb-core/dispatch/session/memory.rb +8 -6
- data/lib/merb-core/dispatch/session/store_container.rb +6 -5
- data/lib/merb-core/dispatch/worker.rb +28 -10
- data/lib/merb-core/gem_ext/erubis.rb +4 -2
- data/lib/merb-core/logger.rb +3 -22
- data/lib/merb-core/plugins.rb +5 -5
- data/lib/merb-core/rack.rb +1 -1
- data/lib/merb-core/rack/adapter.rb +5 -1
- data/lib/merb-core/rack/adapter/abstract.rb +15 -10
- data/lib/merb-core/rack/adapter/ebb.rb +4 -2
- data/lib/merb-core/rack/adapter/evented_mongrel.rb +2 -1
- data/lib/merb-core/rack/adapter/fcgi.rb +3 -1
- data/lib/merb-core/rack/adapter/irb.rb +10 -1
- data/lib/merb-core/rack/adapter/mongrel.rb +5 -2
- data/lib/merb-core/rack/adapter/runner.rb +3 -1
- data/lib/merb-core/rack/adapter/swiftiplied_mongrel.rb +2 -1
- data/lib/merb-core/rack/adapter/thin.rb +4 -1
- data/lib/merb-core/rack/adapter/thin_turbo.rb +1 -0
- data/lib/merb-core/rack/adapter/webrick.rb +8 -34
- data/lib/merb-core/rack/application.rb +2 -2
- data/lib/merb-core/rack/handler/mongrel.rb +7 -0
- data/lib/merb-core/rack/helpers.rb +1 -1
- data/lib/merb-core/rack/middleware.rb +7 -1
- data/lib/merb-core/rack/middleware/conditional_get.rb +3 -0
- data/lib/merb-core/rack/middleware/content_length.rb +2 -0
- data/lib/merb-core/rack/middleware/path_prefix.rb +4 -0
- data/lib/merb-core/rack/middleware/profiler.rb +3 -1
- data/lib/merb-core/rack/middleware/static.rb +7 -1
- data/lib/merb-core/rack/middleware/tracer.rb +1 -0
- data/lib/merb-core/rack/stream_wrapper.rb +35 -30
- data/lib/merb-core/server.rb +17 -16
- data/lib/merb-core/tasks/gem_management.rb +1 -1
- data/lib/merb-core/tasks/merb.rb +3 -1
- data/lib/merb-core/tasks/merb_rake_helper.rb +1 -1
- data/lib/merb-core/test.rb +8 -8
- data/lib/merb-core/test/helpers.rb +1 -1
- data/lib/merb-core/test/helpers/cookie_jar.rb +16 -2
- data/lib/merb-core/test/helpers/mock_request_helper.rb +13 -13
- data/lib/merb-core/test/helpers/request_helper.rb +1 -1
- data/lib/merb-core/test/helpers/route_helper.rb +2 -2
- data/lib/merb-core/test/matchers.rb +3 -3
- data/lib/merb-core/test/matchers/request_matchers.rb +1 -1
- data/lib/merb-core/test/run_spec.rb +1 -1
- data/lib/merb-core/test/tasks/spectasks.rb +1 -1
- data/lib/merb-core/test/test_ext/hpricot.rb +1 -1
- data/lib/merb-core/test/test_ext/rspec.rb +2 -2
- data/lib/merb-core/test/test_ext/string.rb +1 -1
- data/lib/merb-core/version.rb +1 -1
- metadata +8 -22
- data/lib/merb-core/test/matchers/view_matchers.rb +0 -231
- data/lib/merb-core/test/webrat.rb +0 -37
- data/lib/merb-core/vendor/nokogiri/css.rb +0 -6
- data/lib/merb-core/vendor/nokogiri/css/generated_parser.rb +0 -653
- data/lib/merb-core/vendor/nokogiri/css/generated_tokenizer.rb +0 -159
- data/lib/merb-core/vendor/nokogiri/css/node.rb +0 -95
- data/lib/merb-core/vendor/nokogiri/css/parser.rb +0 -24
- data/lib/merb-core/vendor/nokogiri/css/parser.y +0 -198
- data/lib/merb-core/vendor/nokogiri/css/tokenizer.rb +0 -9
- data/lib/merb-core/vendor/nokogiri/css/tokenizer.rex +0 -63
- data/lib/merb-core/vendor/nokogiri/css/xpath_visitor.rb +0 -159
data/lib/merb-core/config.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Merb
|
|
|
11
11
|
# ==== Returns
|
|
12
12
|
# Hash:: The defaults for the config.
|
|
13
13
|
#
|
|
14
|
-
#
|
|
14
|
+
# :api: private
|
|
15
15
|
def defaults
|
|
16
16
|
@defaults ||= {
|
|
17
17
|
:host => "0.0.0.0",
|
|
@@ -47,7 +47,7 @@ module Merb
|
|
|
47
47
|
# ==== Returns
|
|
48
48
|
# nil
|
|
49
49
|
#
|
|
50
|
-
#
|
|
50
|
+
# :api: public
|
|
51
51
|
def use
|
|
52
52
|
@configuration ||= {}
|
|
53
53
|
yield @configuration
|
|
@@ -62,7 +62,7 @@ module Merb
|
|
|
62
62
|
# ==== Returns
|
|
63
63
|
# Boolean:: True if the key exists in the config.
|
|
64
64
|
#
|
|
65
|
-
#
|
|
65
|
+
# :api: public
|
|
66
66
|
def key?(key)
|
|
67
67
|
@configuration.key?(key)
|
|
68
68
|
end
|
|
@@ -75,7 +75,7 @@ module Merb
|
|
|
75
75
|
# ==== Returns
|
|
76
76
|
# Object:: The value of the configuration parameter.
|
|
77
77
|
#
|
|
78
|
-
#
|
|
78
|
+
# :api: public
|
|
79
79
|
def [](key)
|
|
80
80
|
(@configuration ||= setup)[key]
|
|
81
81
|
end
|
|
@@ -85,6 +85,8 @@ module Merb
|
|
|
85
85
|
# ==== Parameters
|
|
86
86
|
# key<Object>:: The key to set the parameter for.
|
|
87
87
|
# val<Object>:: The value of the parameter.
|
|
88
|
+
#
|
|
89
|
+
# :api: public
|
|
88
90
|
def []=(key, val)
|
|
89
91
|
(@configuration ||= setup)[key] = val
|
|
90
92
|
end
|
|
@@ -97,7 +99,7 @@ module Merb
|
|
|
97
99
|
# ==== Returns
|
|
98
100
|
# Object:: The value of the removed entry.
|
|
99
101
|
#
|
|
100
|
-
#
|
|
102
|
+
# :api: public
|
|
101
103
|
def delete(key)
|
|
102
104
|
@configuration.delete(key)
|
|
103
105
|
end
|
|
@@ -111,6 +113,8 @@ module Merb
|
|
|
111
113
|
#
|
|
112
114
|
# ==== Returns
|
|
113
115
|
# Object:: The value of the configuration parameter or the default.
|
|
116
|
+
#
|
|
117
|
+
# :api: public
|
|
114
118
|
def fetch(key, default)
|
|
115
119
|
@configuration.fetch(key, default)
|
|
116
120
|
end
|
|
@@ -120,7 +124,7 @@ module Merb
|
|
|
120
124
|
# ==== Returns
|
|
121
125
|
# Hash:: The config as a hash.
|
|
122
126
|
#
|
|
123
|
-
#
|
|
127
|
+
# :api: public
|
|
124
128
|
def to_hash
|
|
125
129
|
@configuration
|
|
126
130
|
end
|
|
@@ -130,7 +134,7 @@ module Merb
|
|
|
130
134
|
# ==== Returns
|
|
131
135
|
# String:: The config as YAML.
|
|
132
136
|
#
|
|
133
|
-
#
|
|
137
|
+
# :api: public
|
|
134
138
|
def to_yaml
|
|
135
139
|
require "yaml"
|
|
136
140
|
@configuration.to_yaml
|
|
@@ -145,15 +149,24 @@ module Merb
|
|
|
145
149
|
# ==== Returns
|
|
146
150
|
# The configuration as a hash.
|
|
147
151
|
#
|
|
148
|
-
#
|
|
152
|
+
# :api: private
|
|
149
153
|
def setup(settings = {})
|
|
150
|
-
|
|
154
|
+
config = defaults.merge(settings)
|
|
151
155
|
|
|
152
|
-
unless
|
|
153
|
-
|
|
156
|
+
unless config[:reload_classes]
|
|
157
|
+
config[:fork_for_class_load] = false
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
dev_mode = config[:environment] == "development"
|
|
161
|
+
unless config.key?(:reap_workers_quickly)
|
|
162
|
+
config[:reap_workers_quickly] = dev_mode & !config[:cluster]
|
|
154
163
|
end
|
|
155
164
|
|
|
156
|
-
|
|
165
|
+
unless config.key?(:bind_fail_fatal)
|
|
166
|
+
config[:bind_fail_fatal] = dev_mode
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
@configuration = config
|
|
157
170
|
end
|
|
158
171
|
|
|
159
172
|
# Parses the command line arguments and stores them in the config.
|
|
@@ -164,7 +177,7 @@ module Merb
|
|
|
164
177
|
# ==== Returns
|
|
165
178
|
# The configuration as a hash.
|
|
166
179
|
#
|
|
167
|
-
#
|
|
180
|
+
# :api: private
|
|
168
181
|
def parse_args(argv = ARGV)
|
|
169
182
|
@configuration ||= {}
|
|
170
183
|
# Our primary configuration hash for the length of this method
|
|
@@ -391,6 +404,7 @@ module Merb
|
|
|
391
404
|
Merb::Config.setup(options)
|
|
392
405
|
end
|
|
393
406
|
|
|
407
|
+
# :api: private
|
|
394
408
|
attr_accessor :configuration
|
|
395
409
|
|
|
396
410
|
# Set configuration parameters from a code block, where each method
|
|
@@ -410,7 +424,7 @@ module Merb
|
|
|
410
424
|
# ==== Returns
|
|
411
425
|
# nil
|
|
412
426
|
#
|
|
413
|
-
#
|
|
427
|
+
# :api: public
|
|
414
428
|
def configure(&block)
|
|
415
429
|
ConfigBlock.new(self, &block) if block_given?
|
|
416
430
|
nil
|
|
@@ -426,7 +440,7 @@ module Merb
|
|
|
426
440
|
# ==== Returns
|
|
427
441
|
# The value of the entry fetched or assigned to.
|
|
428
442
|
#
|
|
429
|
-
#
|
|
443
|
+
# :api: public
|
|
430
444
|
def method_missing(method, *args)
|
|
431
445
|
if method.to_s[-1,1] == '='
|
|
432
446
|
@configuration[method.to_s.tr('=','').to_sym] = *args
|
|
@@ -450,7 +464,7 @@ module Merb
|
|
|
450
464
|
# ==== Returns
|
|
451
465
|
# nil
|
|
452
466
|
#
|
|
453
|
-
#
|
|
467
|
+
# :api: private
|
|
454
468
|
def initialize(klass, &block)
|
|
455
469
|
@klass = klass
|
|
456
470
|
instance_eval(&block)
|
|
@@ -458,7 +472,7 @@ module Merb
|
|
|
458
472
|
|
|
459
473
|
# Assign args as the value of the entry keyed by method.
|
|
460
474
|
#
|
|
461
|
-
#
|
|
475
|
+
# :api: private
|
|
462
476
|
def method_missing(method, *args)
|
|
463
477
|
@klass[method] = *args
|
|
464
478
|
end
|
|
@@ -95,20 +95,20 @@
|
|
|
95
95
|
class Merb::AbstractController
|
|
96
96
|
include Merb::RenderMixin
|
|
97
97
|
include Merb::InlineTemplates
|
|
98
|
-
|
|
98
|
+
|
|
99
99
|
class_inheritable_accessor :_layout, :_template_root, :template_roots
|
|
100
100
|
class_inheritable_accessor :_before_filters, :_after_filters
|
|
101
101
|
class_inheritable_accessor :_before_dispatch_callbacks, :_after_dispatch_callbacks
|
|
102
102
|
|
|
103
103
|
cattr_accessor :_abstract_subclasses
|
|
104
104
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
attr_accessor :
|
|
109
|
-
attr_accessor :_benchmarks, :_thrown_content
|
|
105
|
+
# :api: plugin
|
|
106
|
+
attr_accessor :body, :action_name, :_benchmarks
|
|
107
|
+
# :api: private
|
|
108
|
+
attr_accessor :_thrown_content
|
|
110
109
|
|
|
111
110
|
# Stub so content-type support in RenderMixin doesn't throw errors
|
|
111
|
+
# :api: private
|
|
112
112
|
attr_accessor :content_type
|
|
113
113
|
|
|
114
114
|
FILTER_OPTIONS = [:only, :exclude, :if, :unless, :with]
|
|
@@ -124,13 +124,13 @@ class Merb::AbstractController
|
|
|
124
124
|
|
|
125
125
|
# ==== Returns
|
|
126
126
|
# String:: The controller name in path form, e.g. "admin/items".
|
|
127
|
-
#
|
|
127
|
+
# :api: public
|
|
128
128
|
def self.controller_name() @controller_name ||= self.name.to_const_path end
|
|
129
129
|
|
|
130
130
|
# ==== Returns
|
|
131
131
|
# String:: The controller name in path form, e.g. "admin/items".
|
|
132
132
|
#
|
|
133
|
-
#
|
|
133
|
+
# :api: public
|
|
134
134
|
def controller_name() self.class.controller_name end
|
|
135
135
|
|
|
136
136
|
# This is called after the controller is instantiated to figure out where to
|
|
@@ -162,7 +162,7 @@ class Merb::AbstractController
|
|
|
162
162
|
# This would look for templates at controller.action.mime.type instead
|
|
163
163
|
# of controller/action.mime.type
|
|
164
164
|
#
|
|
165
|
-
#
|
|
165
|
+
# :api: public
|
|
166
166
|
# @overridable
|
|
167
167
|
def _template_location(context, type, controller)
|
|
168
168
|
controller ? "#{controller}/#{context}" : context
|
|
@@ -175,7 +175,7 @@ class Merb::AbstractController
|
|
|
175
175
|
# type<~to_s>::
|
|
176
176
|
# The mime-type of the template that will be rendered. Defaults to being called with nil.
|
|
177
177
|
#
|
|
178
|
-
#
|
|
178
|
+
# :api: public
|
|
179
179
|
# @overridable
|
|
180
180
|
def _absolute_template_location(template, type)
|
|
181
181
|
template
|
|
@@ -187,7 +187,7 @@ class Merb::AbstractController
|
|
|
187
187
|
# root<~to_s>::
|
|
188
188
|
# The new path to set the template root to.
|
|
189
189
|
#
|
|
190
|
-
#
|
|
190
|
+
# :api: public
|
|
191
191
|
def self._template_root=(root)
|
|
192
192
|
@_template_root = root
|
|
193
193
|
_reset_template_roots
|
|
@@ -195,7 +195,7 @@ class Merb::AbstractController
|
|
|
195
195
|
|
|
196
196
|
# Reset the template root based on the @_template_root ivar.
|
|
197
197
|
#
|
|
198
|
-
#
|
|
198
|
+
# :api: private
|
|
199
199
|
def self._reset_template_roots
|
|
200
200
|
self.template_roots = [[self._template_root, :_template_location]]
|
|
201
201
|
end
|
|
@@ -205,7 +205,7 @@ class Merb::AbstractController
|
|
|
205
205
|
# Template roots as pairs of template root path and template location
|
|
206
206
|
# method.
|
|
207
207
|
#
|
|
208
|
-
#
|
|
208
|
+
# :api: plugin
|
|
209
209
|
def self._template_roots
|
|
210
210
|
self.template_roots || _reset_template_roots
|
|
211
211
|
end
|
|
@@ -215,7 +215,7 @@ class Merb::AbstractController
|
|
|
215
215
|
# Template roots as pairs of template root path and template location
|
|
216
216
|
# method.
|
|
217
217
|
#
|
|
218
|
-
#
|
|
218
|
+
# :api: plugin
|
|
219
219
|
def self._template_roots=(roots)
|
|
220
220
|
self.template_roots = roots
|
|
221
221
|
end
|
|
@@ -226,14 +226,14 @@ class Merb::AbstractController
|
|
|
226
226
|
# ==== Returns
|
|
227
227
|
# Set:: The subclasses.
|
|
228
228
|
#
|
|
229
|
-
#
|
|
229
|
+
# :api: private
|
|
230
230
|
def self.subclasses_list() _abstract_subclasses end
|
|
231
231
|
|
|
232
232
|
# ==== Parameters
|
|
233
233
|
# klass<Merb::AbstractController>::
|
|
234
234
|
# The controller that is being inherited from Merb::AbstractController
|
|
235
235
|
#
|
|
236
|
-
#
|
|
236
|
+
# :api: private
|
|
237
237
|
def self.inherited(klass)
|
|
238
238
|
_abstract_subclasses << klass.to_s
|
|
239
239
|
helper_module_name = klass.to_s =~ /^(#|Merb::)/ ? "#{klass}Helper" : "Merb::#{klass}Helper"
|
|
@@ -248,7 +248,7 @@ class Merb::AbstractController
|
|
|
248
248
|
# ==== Parameters
|
|
249
249
|
# *args:: The args are ignored in this class, but we need this so that subclassed initializes can have parameters
|
|
250
250
|
#
|
|
251
|
-
#
|
|
251
|
+
# :api: private
|
|
252
252
|
def initialize(*args)
|
|
253
253
|
@_benchmarks = {}
|
|
254
254
|
@_caught_content = {}
|
|
@@ -269,7 +269,7 @@ class Merb::AbstractController
|
|
|
269
269
|
# ==== Raises
|
|
270
270
|
# ArgumentError:: Invalid result caught from before filters.
|
|
271
271
|
#
|
|
272
|
-
#
|
|
272
|
+
# :api: plugin
|
|
273
273
|
def _dispatch(action)
|
|
274
274
|
self.action_name = action
|
|
275
275
|
self._before_dispatch_callbacks.each { |cb| cb.call(self) }
|
|
@@ -305,7 +305,7 @@ class Merb::AbstractController
|
|
|
305
305
|
# ==== Parameters
|
|
306
306
|
# action<~to_s>:: the action method to dispatch to
|
|
307
307
|
#
|
|
308
|
-
#
|
|
308
|
+
# :api: plugin
|
|
309
309
|
# @overridable
|
|
310
310
|
def _call_action(action)
|
|
311
311
|
send(action)
|
|
@@ -329,7 +329,7 @@ class Merb::AbstractController
|
|
|
329
329
|
# Execute the +Proc+, in the context of the controller (self will be the
|
|
330
330
|
# controller)
|
|
331
331
|
#
|
|
332
|
-
#
|
|
332
|
+
# :api: private
|
|
333
333
|
def _call_filters(filter_set)
|
|
334
334
|
(filter_set || []).each do |filter, rule|
|
|
335
335
|
if _call_filter_for_action?(rule, action_name) && _filter_condition_met?(rule)
|
|
@@ -365,7 +365,7 @@ class Merb::AbstractController
|
|
|
365
365
|
# ==== Returns
|
|
366
366
|
# Boolean:: True if the action should be called.
|
|
367
367
|
#
|
|
368
|
-
#
|
|
368
|
+
# :api: private
|
|
369
369
|
def _call_filter_for_action?(rule, action_name)
|
|
370
370
|
# Both:
|
|
371
371
|
# * no :only or the current action is in the :only list
|
|
@@ -387,7 +387,7 @@ class Merb::AbstractController
|
|
|
387
387
|
# ==== Returns
|
|
388
388
|
# Boolean:: True if the conditions are met.
|
|
389
389
|
#
|
|
390
|
-
#
|
|
390
|
+
# :api: private
|
|
391
391
|
def _filter_condition_met?(rule)
|
|
392
392
|
# Both:
|
|
393
393
|
# * no :if or the if condition evaluates to true
|
|
@@ -411,7 +411,7 @@ class Merb::AbstractController
|
|
|
411
411
|
# If condition is a symbol, it will be send'ed. If it is a Proc it will be
|
|
412
412
|
# called directly with self as an argument.
|
|
413
413
|
#
|
|
414
|
-
#
|
|
414
|
+
# :api: private
|
|
415
415
|
def _evaluate_condition(condition)
|
|
416
416
|
case condition
|
|
417
417
|
when Symbol : self.send(condition)
|
|
@@ -432,7 +432,7 @@ class Merb::AbstractController
|
|
|
432
432
|
# ==== Notes
|
|
433
433
|
# If the filter already exists, its options will be replaced with opts.;
|
|
434
434
|
#
|
|
435
|
-
#
|
|
435
|
+
# :api: public
|
|
436
436
|
def self.after(filter = nil, opts = {}, &block)
|
|
437
437
|
add_filter(self._after_filters, filter || block, opts)
|
|
438
438
|
end
|
|
@@ -448,7 +448,7 @@ class Merb::AbstractController
|
|
|
448
448
|
# ==== Notes
|
|
449
449
|
# If the filter already exists, its options will be replaced with opts.
|
|
450
450
|
#
|
|
451
|
-
#
|
|
451
|
+
# :api: public
|
|
452
452
|
def self.before(filter = nil, opts = {}, &block)
|
|
453
453
|
add_filter(self._before_filters, filter || block, opts)
|
|
454
454
|
end
|
|
@@ -460,7 +460,7 @@ class Merb::AbstractController
|
|
|
460
460
|
# ==== Parameters
|
|
461
461
|
# filter<Symbol, String>:: A filter name to skip.
|
|
462
462
|
#
|
|
463
|
-
#
|
|
463
|
+
# :api: public
|
|
464
464
|
def self.skip_after(filter)
|
|
465
465
|
skip_filter(self._after_filters, filter)
|
|
466
466
|
end
|
|
@@ -472,7 +472,7 @@ class Merb::AbstractController
|
|
|
472
472
|
# ==== Parameters
|
|
473
473
|
# filter<Symbol, String>:: A filter name to skip.
|
|
474
474
|
#
|
|
475
|
-
#
|
|
475
|
+
# :api: public
|
|
476
476
|
def self.skip_before(filter)
|
|
477
477
|
skip_filter(self._before_filters , filter)
|
|
478
478
|
end
|
|
@@ -530,7 +530,7 @@ class Merb::AbstractController
|
|
|
530
530
|
#
|
|
531
531
|
# url(:articles, 2008, 10, "test_article")
|
|
532
532
|
#
|
|
533
|
-
#
|
|
533
|
+
# :api: public
|
|
534
534
|
def url(name, *args)
|
|
535
535
|
args << {}
|
|
536
536
|
Merb::Router.url(name, *args)
|
|
@@ -543,7 +543,7 @@ class Merb::AbstractController
|
|
|
543
543
|
# This uses the same arguments as the url method, with added requirements
|
|
544
544
|
# of protocol and host options.
|
|
545
545
|
#
|
|
546
|
-
#
|
|
546
|
+
# :api: public
|
|
547
547
|
def absolute_url(*args)
|
|
548
548
|
# FIXME: arrgh, why request.protocol returns http://?
|
|
549
549
|
# :// is not part of protocol name
|
|
@@ -587,7 +587,7 @@ class Merb::AbstractController
|
|
|
587
587
|
# resource(:users, :new) # => /users/new
|
|
588
588
|
# resource(:@user, :edit) # => /users/10/edit
|
|
589
589
|
#
|
|
590
|
-
#
|
|
590
|
+
# :api: public
|
|
591
591
|
def resource(*args)
|
|
592
592
|
args << {}
|
|
593
593
|
Merb::Router.resource(*args)
|
|
@@ -602,7 +602,7 @@ class Merb::AbstractController
|
|
|
602
602
|
# ==== Returns
|
|
603
603
|
# String:: The output of a template block or the return value of a non-template block converted to a string.
|
|
604
604
|
#
|
|
605
|
-
#
|
|
605
|
+
# :api: public
|
|
606
606
|
def capture(*args, &block)
|
|
607
607
|
ret = nil
|
|
608
608
|
|
|
@@ -620,7 +620,7 @@ class Merb::AbstractController
|
|
|
620
620
|
# str<String>:: The string to concatenate to the buffer.
|
|
621
621
|
# binding<Binding>:: The binding to use for the buffer.
|
|
622
622
|
#
|
|
623
|
-
#
|
|
623
|
+
# :api: public
|
|
624
624
|
def concat(str, binding)
|
|
625
625
|
send("concat_#{@_engine}", str, binding)
|
|
626
626
|
end
|
|
@@ -638,7 +638,7 @@ class Merb::AbstractController
|
|
|
638
638
|
# Both :only and :exclude, or :if and :unless given, if filter is not a
|
|
639
639
|
# Symbol, String or Proc, or if an unknown option is passed.
|
|
640
640
|
#
|
|
641
|
-
#
|
|
641
|
+
# :api: private
|
|
642
642
|
def self.add_filter(filters, filter, opts={})
|
|
643
643
|
raise(ArgumentError,
|
|
644
644
|
"You can specify either :only or :exclude but
|
|
@@ -683,7 +683,7 @@ class Merb::AbstractController
|
|
|
683
683
|
# ==== Raises
|
|
684
684
|
# ArgumentError:: filter not Symbol or String.
|
|
685
685
|
#
|
|
686
|
-
#
|
|
686
|
+
# :api: private
|
|
687
687
|
def self.skip_filter(filters, filter)
|
|
688
688
|
raise(ArgumentError, 'You can only skip filters that have a String or Symbol name.') unless
|
|
689
689
|
[Symbol, String].include? filter.class
|
|
@@ -704,7 +704,7 @@ class Merb::AbstractController
|
|
|
704
704
|
# ==== Examples
|
|
705
705
|
# normalize_filters!(:only => :new) #=> {:only => [:new]}
|
|
706
706
|
#
|
|
707
|
-
#
|
|
707
|
+
# :api: public
|
|
708
708
|
def self.normalize_filters!(opts={})
|
|
709
709
|
opts[:only] = Array(opts[:only]).map {|x| x.to_s} if opts[:only]
|
|
710
710
|
opts[:exclude] = Array(opts[:exclude]).map {|x| x.to_s} if opts[:exclude]
|
|
@@ -6,7 +6,7 @@ class Exception
|
|
|
6
6
|
# String:: The name of the action in the Exceptions controller which will get invoked
|
|
7
7
|
# when this exception is raised during a request.
|
|
8
8
|
#
|
|
9
|
-
#
|
|
9
|
+
# :api: public
|
|
10
10
|
# @overridable
|
|
11
11
|
def action_name() self.class.action_name end
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ class Exception
|
|
|
14
14
|
# ==== Returns
|
|
15
15
|
# Boolean:: Whether or not this exception is the same as another.
|
|
16
16
|
#
|
|
17
|
-
#
|
|
17
|
+
# :api: public
|
|
18
18
|
def same?(other)
|
|
19
19
|
self.class == other.class &&
|
|
20
20
|
self.message == other.message &&
|
|
@@ -28,7 +28,7 @@ class Exception
|
|
|
28
28
|
# String:: The name of the action in the Exceptions controller which will get invoked
|
|
29
29
|
# when an instance of this Exception sub/class is raised by an action.
|
|
30
30
|
#
|
|
31
|
-
#
|
|
31
|
+
# :api: public
|
|
32
32
|
# @overridable
|
|
33
33
|
def self.action_name
|
|
34
34
|
if self == Exception
|
|
@@ -46,7 +46,7 @@ class Exception
|
|
|
46
46
|
# ==== Returns
|
|
47
47
|
# Integer:: The status code to send in the response. Defaults to 500.
|
|
48
48
|
#
|
|
49
|
-
#
|
|
49
|
+
# :api: public
|
|
50
50
|
# @overridable
|
|
51
51
|
def self.status
|
|
52
52
|
500
|
|
@@ -154,6 +154,9 @@ module Merb
|
|
|
154
154
|
|
|
155
155
|
# === Returns
|
|
156
156
|
# Integer:: The status-code of the error.
|
|
157
|
+
#
|
|
158
|
+
# @overridable
|
|
159
|
+
# :api: plugin
|
|
157
160
|
def status; self.class.status; end
|
|
158
161
|
alias :to_i :status
|
|
159
162
|
|
|
@@ -167,7 +170,7 @@ module Merb
|
|
|
167
170
|
# ==== Returns
|
|
168
171
|
# Fixnum:: The status code of this exception.
|
|
169
172
|
#
|
|
170
|
-
#
|
|
173
|
+
# :api: public
|
|
171
174
|
def status
|
|
172
175
|
const_get(:STATUS) rescue 0
|
|
173
176
|
end
|
|
@@ -184,7 +187,7 @@ module Merb
|
|
|
184
187
|
# ==== Returns
|
|
185
188
|
# (Integer, nil):: The status set on this exception, or nil if a status was already set.
|
|
186
189
|
#
|
|
187
|
-
#
|
|
190
|
+
# :api: private
|
|
188
191
|
def status=(num)
|
|
189
192
|
unless self.status?
|
|
190
193
|
register_status_code(self, num)
|
|
@@ -197,7 +200,7 @@ module Merb
|
|
|
197
200
|
# ==== Returns
|
|
198
201
|
# Boolean:: Whether a status code has been set
|
|
199
202
|
#
|
|
200
|
-
#
|
|
203
|
+
# :api: private
|
|
201
204
|
def status?
|
|
202
205
|
self.const_defined?(:STATUS)
|
|
203
206
|
end
|
|
@@ -213,7 +216,7 @@ module Merb
|
|
|
213
216
|
# subclass<Merb::ControllerExceptions::Base>::
|
|
214
217
|
# The Exception class that is inheriting from Merb::ControllerExceptions::Base
|
|
215
218
|
#
|
|
216
|
-
#
|
|
219
|
+
# :api: public
|
|
217
220
|
def inherited(subclass)
|
|
218
221
|
# don't set the constant yet - any class methods will be called after self.inherited
|
|
219
222
|
# unless self.status = ... is set explicitly, the status code will be inherited
|
|
@@ -227,7 +230,7 @@ module Merb
|
|
|
227
230
|
# ==== Parameters
|
|
228
231
|
# num<~to_i>:: The status code
|
|
229
232
|
#
|
|
230
|
-
#
|
|
233
|
+
# :api: privaate
|
|
231
234
|
def register_status_code(klass, code)
|
|
232
235
|
name = self.to_s.split('::').last.snake_case
|
|
233
236
|
STATUS_CODES[name.to_sym] = code.to_i
|
|
@@ -338,6 +341,8 @@ module Merb
|
|
|
338
341
|
# Required to show exceptions in the log file
|
|
339
342
|
#
|
|
340
343
|
# e<Exception>:: The exception that a message is being generated for
|
|
344
|
+
#
|
|
345
|
+
# :api: plugin
|
|
341
346
|
def self.exception(e)
|
|
342
347
|
"#{ e.message } - (#{ e.class })\n" <<
|
|
343
348
|
"#{(e.backtrace or []).join("\n")}"
|