merb-core 0.9.13 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,6 +1,6 @@
|
|
1
1
|
module Merb
|
2
2
|
class Router
|
3
|
-
|
3
|
+
|
4
4
|
module Resources
|
5
5
|
# Behavior#+resources+ is a route helper for defining a collection of
|
6
6
|
# RESTful resources. It yields to a block for child routes.
|
@@ -66,7 +66,7 @@ module Merb
|
|
66
66
|
# posts.resources :comments
|
67
67
|
# end
|
68
68
|
#
|
69
|
-
#
|
69
|
+
# :api: public
|
70
70
|
def resources(name, *args, &block)
|
71
71
|
name = name.to_s
|
72
72
|
options = extract_options_from_args!(args) || {}
|
@@ -223,7 +223,7 @@ module Merb
|
|
223
223
|
# account.resources :preferences, :controller => "settings"
|
224
224
|
# end
|
225
225
|
#
|
226
|
-
#
|
226
|
+
# :api: public
|
227
227
|
def resource(name, *args, &block)
|
228
228
|
name = name.to_s
|
229
229
|
options = extract_options_from_args!(args) || {}
|
@@ -271,7 +271,7 @@ module Merb
|
|
271
271
|
|
272
272
|
protected
|
273
273
|
|
274
|
-
#api private
|
274
|
+
# :api: private
|
275
275
|
def register_resource(*key)
|
276
276
|
options = extract_options_from_args!(key) || {}
|
277
277
|
key = [ @options[:resource_prefix], key ].flatten.compact
|
@@ -281,7 +281,7 @@ module Merb
|
|
281
281
|
self
|
282
282
|
end
|
283
283
|
|
284
|
-
#api private
|
284
|
+
# :api: private
|
285
285
|
def resource_block(builders, &block)
|
286
286
|
behavior = ResourceBehavior.new(builders, @proxy, @conditions, @params, @defaults, @identifiers, @options, @blocks)
|
287
287
|
with_behavior_context(behavior, &block)
|
@@ -301,14 +301,14 @@ module Merb
|
|
301
301
|
# Adding the collection and member methods to behavior
|
302
302
|
class ResourceBehavior < Behavior #:nodoc:
|
303
303
|
|
304
|
-
#api private
|
304
|
+
# :api: private
|
305
305
|
def initialize(builders, *args)
|
306
306
|
super(*args)
|
307
307
|
@collection = builders[:collection]
|
308
308
|
@member = builders[:member]
|
309
309
|
end
|
310
310
|
|
311
|
-
#api private
|
311
|
+
# :api: private
|
312
312
|
def collection(action, options = {})
|
313
313
|
action = action.to_s
|
314
314
|
method = options[:method]
|
@@ -316,7 +316,7 @@ module Merb
|
|
316
316
|
@collection[action, to, method]
|
317
317
|
end
|
318
318
|
|
319
|
-
#
|
319
|
+
# :api: private
|
320
320
|
def member(action, options = {})
|
321
321
|
action = action.to_s
|
322
322
|
method = options[:method]
|
@@ -326,4 +326,4 @@ module Merb
|
|
326
326
|
|
327
327
|
end
|
328
328
|
end
|
329
|
-
end
|
329
|
+
end
|
@@ -10,10 +10,14 @@ module Merb
|
|
10
10
|
JUST_BRACKETS = /\[(\d+)\]/
|
11
11
|
SEGMENT_CHARACTERS = "[^\/.,;?]".freeze
|
12
12
|
|
13
|
+
# :api: private
|
13
14
|
attr_reader :conditions, :params, :segments
|
15
|
+
# :api: private
|
14
16
|
attr_reader :index, :variables, :name
|
17
|
+
# :api: private
|
15
18
|
attr_accessor :fixation, :resource_identifiers
|
16
19
|
|
20
|
+
# :api: private
|
17
21
|
def initialize(conditions, params, deferred_procs, options = {})
|
18
22
|
@conditions, @params = conditions, params
|
19
23
|
|
@@ -35,18 +39,22 @@ module Merb
|
|
35
39
|
compile
|
36
40
|
end
|
37
41
|
|
42
|
+
# :api: private
|
38
43
|
def regexp?
|
39
44
|
@regexp
|
40
45
|
end
|
41
|
-
|
46
|
+
|
47
|
+
# :api: private
|
42
48
|
def generatable?
|
43
49
|
@generatable && !regexp?
|
44
50
|
end
|
45
51
|
|
52
|
+
# :api: private
|
46
53
|
def allow_fixation?
|
47
54
|
@fixation
|
48
55
|
end
|
49
56
|
|
57
|
+
# :api: private
|
50
58
|
def to_s
|
51
59
|
regexp? ?
|
52
60
|
"/#{conditions[:path].source}/" :
|
@@ -56,6 +64,8 @@ module Merb
|
|
56
64
|
alias_method :inspect, :to_s
|
57
65
|
|
58
66
|
# Appends self to Merb::Router.routes
|
67
|
+
|
68
|
+
# :api: private
|
59
69
|
def register
|
60
70
|
@index = Merb::Router.routes.size
|
61
71
|
Merb::Router.routes << self
|
@@ -63,6 +73,7 @@ module Merb
|
|
63
73
|
end
|
64
74
|
|
65
75
|
# Inserts self to Merb::Router.routes at the specified index.
|
76
|
+
# :api: private
|
66
77
|
def register_at(index)
|
67
78
|
@index = index
|
68
79
|
Merb::Router.routes.insert(index, self)
|
@@ -71,11 +82,13 @@ module Merb
|
|
71
82
|
|
72
83
|
# Sets the route as a resource route with the given key as the
|
73
84
|
# lookup key.
|
85
|
+
# :api: private
|
74
86
|
def resource=(key)
|
75
87
|
Router.resource_routes[key] = self
|
76
88
|
key
|
77
89
|
end
|
78
90
|
|
91
|
+
# :api: private
|
79
92
|
def name=(name)
|
80
93
|
@name = name.to_sym
|
81
94
|
Router.named_routes[@name] = self
|
@@ -102,6 +115,8 @@ module Merb
|
|
102
115
|
#
|
103
116
|
# ==== Returns
|
104
117
|
# String:: The generated URL.
|
118
|
+
#
|
119
|
+
# :api: private
|
105
120
|
def generate(args = [], defaults = {}, resource = false)
|
106
121
|
unless generatable?
|
107
122
|
raise GenerationError, "Cannot generate regexp Routes" if regexp?
|
@@ -144,6 +159,8 @@ module Merb
|
|
144
159
|
#
|
145
160
|
# param_keys that end in _id are treated slightly differently in order
|
146
161
|
# to get nested resources to work correctly.
|
162
|
+
#
|
163
|
+
# :api: private
|
147
164
|
def identify(obj, param_key = nil)
|
148
165
|
identifier = identifier_for(obj)
|
149
166
|
if identifier.is_a?(Array)
|
@@ -161,6 +178,8 @@ module Merb
|
|
161
178
|
# Returns the identifier for the passed object. Built in core ruby classes are
|
162
179
|
# always identified with to_s. The method will return nil in that case (since
|
163
180
|
# to_s is the default for objects that do not have identifiers.)
|
181
|
+
#
|
182
|
+
# :api: private
|
164
183
|
def identifier_for(obj)
|
165
184
|
return if obj.is_a?(String) || obj.is_a?(Symbol) || obj.is_a?(Numeric) ||
|
166
185
|
obj.is_a?(TrueClass) || obj.is_a?(FalseClass) || obj.is_a?(NilClass) ||
|
@@ -175,6 +194,8 @@ module Merb
|
|
175
194
|
|
176
195
|
# Returns the if statement and return value for for the main
|
177
196
|
# Router.match compiled method.
|
197
|
+
#
|
198
|
+
# :api: private
|
178
199
|
def compiled_statement(first)
|
179
200
|
els_if = first ? ' if ' : ' elsif '
|
180
201
|
|
@@ -197,6 +218,7 @@ module Merb
|
|
197
218
|
|
198
219
|
# === Compilation ===
|
199
220
|
|
221
|
+
# :api: private
|
200
222
|
def compile
|
201
223
|
compile_conditions
|
202
224
|
compile_params
|
@@ -206,7 +228,8 @@ module Merb
|
|
206
228
|
# The Generator class handles compiling the route down to a lambda that
|
207
229
|
# can generate the URL from a params hash and a default params hash.
|
208
230
|
class Generator #:nodoc:
|
209
|
-
|
231
|
+
|
232
|
+
# :api: private
|
210
233
|
def initialize(segments, symbol_conditions, identifiers)
|
211
234
|
@segments = segments
|
212
235
|
@symbol_conditions = symbol_conditions
|
@@ -216,6 +239,8 @@ module Merb
|
|
216
239
|
@opt_segment_stack = [[]]
|
217
240
|
end
|
218
241
|
|
242
|
+
#
|
243
|
+
# :api: private
|
219
244
|
def compiled
|
220
245
|
ruby = ""
|
221
246
|
ruby << "lambda do |params, defaults|\n"
|
@@ -242,6 +267,8 @@ module Merb
|
|
242
267
|
|
243
268
|
# Cleans up methods a bunch. We don't need to pass the current segment
|
244
269
|
# level around everywhere anymore. It's kept track for us in the stack.
|
270
|
+
#
|
271
|
+
# :api: private
|
245
272
|
def with(segments, &block)
|
246
273
|
@stack.push(segments)
|
247
274
|
retval = yield
|
@@ -249,22 +276,27 @@ module Merb
|
|
249
276
|
retval
|
250
277
|
end
|
251
278
|
|
279
|
+
# :api: private
|
252
280
|
def segments
|
253
281
|
@stack.last || []
|
254
282
|
end
|
255
|
-
|
283
|
+
|
284
|
+
# :api: private
|
256
285
|
def symbol_segments
|
257
286
|
segments.flatten.select { |s| s.is_a?(Symbol) }
|
258
287
|
end
|
259
|
-
|
288
|
+
|
289
|
+
# :api: private
|
260
290
|
def current_segments
|
261
291
|
segments.select { |s| s.is_a?(Symbol) }
|
262
292
|
end
|
263
|
-
|
293
|
+
|
294
|
+
# :api: private
|
264
295
|
def nested_segments
|
265
296
|
segments.select { |s| s.is_a?(Array) }.flatten.select { |s| s.is_a?(Symbol) }
|
266
297
|
end
|
267
|
-
|
298
|
+
|
299
|
+
# :api: private
|
268
300
|
def block_for_level
|
269
301
|
ruby = ""
|
270
302
|
ruby << "if #{segment_level_matches_conditions}\n"
|
@@ -273,7 +305,8 @@ module Merb
|
|
273
305
|
ruby << %{ "#{combine_required_and_optional_segments}"\n}
|
274
306
|
ruby << "end"
|
275
307
|
end
|
276
|
-
|
308
|
+
|
309
|
+
# :api: private
|
277
310
|
def check_if_defaults_should_be_included
|
278
311
|
ruby = ""
|
279
312
|
ruby << "include_defaults = "
|
@@ -282,6 +315,7 @@ module Merb
|
|
282
315
|
end
|
283
316
|
|
284
317
|
# --- Not so pretty ---
|
318
|
+
# :api: private
|
285
319
|
def segment_level_matches_conditions
|
286
320
|
conditions = current_segments.map do |segment|
|
287
321
|
condition = "(cached_#{segment} = params[#{segment.inspect}] || include_defaults && defaults[#{segment.inspect}])"
|
@@ -299,10 +333,12 @@ module Merb
|
|
299
333
|
conditions.join(" && ")
|
300
334
|
end
|
301
335
|
|
336
|
+
# :api: private
|
302
337
|
def remove_used_segments_in_query_path
|
303
338
|
"#{current_segments.inspect}.each { |s| query_params.delete(s) }"
|
304
339
|
end
|
305
340
|
|
341
|
+
# :api: private
|
306
342
|
def generate_optional_segments
|
307
343
|
optionals = []
|
308
344
|
|
@@ -321,6 +357,7 @@ module Merb
|
|
321
357
|
optionals.join("\n")
|
322
358
|
end
|
323
359
|
|
360
|
+
# :api: private
|
324
361
|
def combine_required_and_optional_segments
|
325
362
|
bits = ""
|
326
363
|
|
@@ -340,6 +377,7 @@ module Merb
|
|
340
377
|
|
341
378
|
# === Conditions ===
|
342
379
|
|
380
|
+
# :api: private
|
343
381
|
def compile_conditions
|
344
382
|
@original_conditions = conditions.dup
|
345
383
|
|
@@ -360,6 +398,8 @@ module Merb
|
|
360
398
|
# to concat all the parts together, then parse the path and extract the
|
361
399
|
# variables. However, if any of the parts are a regular expression, then
|
362
400
|
# we abort the parsing and just convert it to a regexp.
|
401
|
+
#
|
402
|
+
# :api: private
|
363
403
|
def compile_path(path)
|
364
404
|
@segments = []
|
365
405
|
compiled = ""
|
@@ -397,6 +437,8 @@ module Merb
|
|
397
437
|
end
|
398
438
|
|
399
439
|
# Simple nested parenthesis parser
|
440
|
+
#
|
441
|
+
# :api: private
|
400
442
|
def segments_with_optionals_from_string(path, nest_level = 0)
|
401
443
|
segments = []
|
402
444
|
|
@@ -425,6 +467,7 @@ module Merb
|
|
425
467
|
segments
|
426
468
|
end
|
427
469
|
|
470
|
+
# :api: private
|
428
471
|
def segments_from_string(path)
|
429
472
|
segments = []
|
430
473
|
|
@@ -441,6 +484,7 @@ module Merb
|
|
441
484
|
end
|
442
485
|
|
443
486
|
# --- Yeah, this could probably be refactored
|
487
|
+
# :api: private
|
444
488
|
def compile_path_segments(compiled, segments)
|
445
489
|
segments.each do |segment|
|
446
490
|
case segment
|
@@ -463,6 +507,7 @@ module Merb
|
|
463
507
|
end
|
464
508
|
|
465
509
|
# Handles anchors in Regexp conditions
|
510
|
+
# :api: private
|
466
511
|
def compile_segment_condition(condition)
|
467
512
|
return "(#{SEGMENT_CHARACTERS}+)" unless condition
|
468
513
|
return "(#{condition})" unless condition.is_a?(Regexp)
|
@@ -484,6 +529,7 @@ module Merb
|
|
484
529
|
"(#{condition})"
|
485
530
|
end
|
486
531
|
|
532
|
+
# :api: private
|
487
533
|
def compile_params
|
488
534
|
# Loop through each param and compile it
|
489
535
|
@defaults.merge(@params).each do |key, value|
|
@@ -498,6 +544,7 @@ module Merb
|
|
498
544
|
end
|
499
545
|
|
500
546
|
# This was pretty much a copy / paste from the old router
|
547
|
+
# :api: private
|
501
548
|
def compile_param(value)
|
502
549
|
result = []
|
503
550
|
match = true
|
@@ -531,6 +578,7 @@ module Merb
|
|
531
578
|
result.join(' + ').gsub("\\_", "_")
|
532
579
|
end
|
533
580
|
|
581
|
+
# :api: private
|
534
582
|
def condition_statements
|
535
583
|
statements = []
|
536
584
|
|
@@ -576,6 +624,7 @@ module Merb
|
|
576
624
|
end
|
577
625
|
|
578
626
|
# (request.matched? || ((block_result = process(proc.call))))
|
627
|
+
# :api: private
|
579
628
|
def deferred_condition_statement(deferred)
|
580
629
|
if current = deferred.first
|
581
630
|
html = " && (request.matched? || ("
|
@@ -589,6 +638,7 @@ module Merb
|
|
589
638
|
end
|
590
639
|
end
|
591
640
|
|
641
|
+
# :api: private
|
592
642
|
def params_as_string
|
593
643
|
elements = params.keys.map do |k|
|
594
644
|
"#{k.inspect} => #{params[k]}"
|
@@ -598,6 +648,7 @@ module Merb
|
|
598
648
|
|
599
649
|
# ---------- Utilities ----------
|
600
650
|
|
651
|
+
# :api: private
|
601
652
|
def arrays_to_regexps(condition)
|
602
653
|
return condition unless condition.is_a?(Array)
|
603
654
|
|
@@ -613,6 +664,7 @@ module Merb
|
|
613
664
|
Regexp.compile(source.join('|'))
|
614
665
|
end
|
615
666
|
|
667
|
+
# :api: private
|
616
668
|
def segment_level_to_s(segments)
|
617
669
|
(segments || []).inject('') do |str, seg|
|
618
670
|
str << case seg
|
@@ -623,6 +675,7 @@ module Merb
|
|
623
675
|
end
|
624
676
|
end
|
625
677
|
|
678
|
+
# :api: private
|
626
679
|
def capturing_parentheses_count(regexp)
|
627
680
|
regexp = regexp.source if regexp.is_a?(Regexp)
|
628
681
|
regexp.scan(/(?!\\)[(](?!\?[#=:!>-imx])/).length
|
@@ -7,7 +7,7 @@ module Merb
|
|
7
7
|
# configured session stores (:session_stores config option)
|
8
8
|
# or default one (:session_store config option).
|
9
9
|
#
|
10
|
-
#
|
10
|
+
# :api: private
|
11
11
|
def self.session_stores
|
12
12
|
@session_stores ||= begin
|
13
13
|
config_stores = Array(
|
@@ -49,7 +49,7 @@ module Merb
|
|
49
49
|
# Raised when storing more data than the available space reserved.
|
50
50
|
class SessionOverflow < StandardError; end
|
51
51
|
|
52
|
-
#
|
52
|
+
# :api: private
|
53
53
|
def self.included(base)
|
54
54
|
# Register a callback to finalize sessions - needs to run before the cookie
|
55
55
|
# callback extracts Set-Cookie headers from request.cookies.
|
@@ -61,6 +61,8 @@ module Merb
|
|
61
61
|
#
|
62
62
|
# ==== Returns
|
63
63
|
# SessionContainer:: The session that was extracted from the request object.
|
64
|
+
#
|
65
|
+
# :api: public
|
64
66
|
def session(session_store = nil)
|
65
67
|
request.session(session_store)
|
66
68
|
end
|
@@ -69,6 +71,8 @@ module Merb
|
|
69
71
|
|
70
72
|
# ==== Returns
|
71
73
|
# String:: A random 32 character string for use as a unique session ID.
|
74
|
+
#
|
75
|
+
# :api: private
|
72
76
|
def rand_uuid
|
73
77
|
values = [
|
74
78
|
rand(0x0010000),
|
@@ -84,7 +88,7 @@ module Merb
|
|
84
88
|
|
85
89
|
# Marks this session as needing a new cookie.
|
86
90
|
#
|
87
|
-
#
|
91
|
+
# :api: private
|
88
92
|
def needs_new_cookie!
|
89
93
|
@_new_cookie = true
|
90
94
|
end
|
@@ -94,7 +98,7 @@ module Merb
|
|
94
98
|
# ==== Returns
|
95
99
|
# Boolean:: true if a new cookie is needed, false otherwise.
|
96
100
|
#
|
97
|
-
#
|
101
|
+
# :api: private
|
98
102
|
def needs_new_cookie?
|
99
103
|
@_new_cookie
|
100
104
|
end
|
@@ -106,6 +110,8 @@ module Merb
|
|
106
110
|
# Adds class methods to Merb::Request object.
|
107
111
|
# Sets up repository of session store types.
|
108
112
|
# Sets the session ID key and expiry values.
|
113
|
+
#
|
114
|
+
# :api: private
|
109
115
|
def self.included(base)
|
110
116
|
base.extend ClassMethods
|
111
117
|
|
@@ -129,7 +135,7 @@ module Merb
|
|
129
135
|
# === Notres
|
130
136
|
# This is automatically called when Merb::SessionContainer is subclassed.
|
131
137
|
#
|
132
|
-
#
|
138
|
+
# :api: private
|
133
139
|
def register_session_type(name, class_name)
|
134
140
|
self.registered_session_types[name.to_sym] = class_name
|
135
141
|
end
|
@@ -138,7 +144,7 @@ module Merb
|
|
138
144
|
|
139
145
|
# The default session store type.
|
140
146
|
#
|
141
|
-
#
|
147
|
+
# :api: private
|
142
148
|
def default_session_store
|
143
149
|
Merb::Config[:session_store] && Merb::Config[:session_store].to_sym
|
144
150
|
end
|
@@ -146,7 +152,7 @@ module Merb
|
|
146
152
|
# ==== Returns
|
147
153
|
# Hash:: All active session stores by type.
|
148
154
|
#
|
149
|
-
#
|
155
|
+
# :api: private
|
150
156
|
def session_stores
|
151
157
|
@session_stores ||= {}
|
152
158
|
end
|
@@ -166,7 +172,7 @@ module Merb
|
|
166
172
|
# SessionContainer::
|
167
173
|
# an instance of a session store extending Merb::SessionContainer.
|
168
174
|
#
|
169
|
-
#
|
175
|
+
# :api: public
|
170
176
|
def session(session_store = nil)
|
171
177
|
session_store ||= default_session_store
|
172
178
|
if class_name = self.class.registered_session_types[session_store]
|
@@ -188,7 +194,7 @@ module Merb
|
|
188
194
|
# === Notes
|
189
195
|
# The session is assigned internally by its session_store_type key.
|
190
196
|
#
|
191
|
-
#
|
197
|
+
# :api: private
|
192
198
|
def session=(new_session)
|
193
199
|
if self.session?(new_session.class.session_store_type)
|
194
200
|
original_session_id = self.session(new_session.class.session_store_type).session_id
|
@@ -204,7 +210,7 @@ module Merb
|
|
204
210
|
# ==== Returns
|
205
211
|
# Boolean:: true if the session is part of the session stores configured.
|
206
212
|
#
|
207
|
-
#
|
213
|
+
# :api: private
|
208
214
|
def session?(session_store = nil)
|
209
215
|
(session_store ? [session_store] : session_stores).any? do |type, store|
|
210
216
|
store.is_a?(Merb::SessionContainer)
|
@@ -213,7 +219,7 @@ module Merb
|
|
213
219
|
|
214
220
|
# Teardown and/or persist the current sessions.
|
215
221
|
#
|
216
|
-
#
|
222
|
+
# :api: private
|
217
223
|
def finalize_session
|
218
224
|
session_stores.each { |name, store| store.finalize(self) }
|
219
225
|
end
|
@@ -221,7 +227,7 @@ module Merb
|
|
221
227
|
|
222
228
|
# Assign default cookie values
|
223
229
|
#
|
224
|
-
#
|
230
|
+
# :api: private
|
225
231
|
def default_cookies
|
226
232
|
defaults = {}
|
227
233
|
if route && route.allow_fixation? && params.key?(_session_id_key)
|
@@ -237,7 +243,7 @@ module Merb
|
|
237
243
|
# value<String>:: The value of the session cookie; either the session id or the actual encoded data.
|
238
244
|
# options<Hash>:: Cookie options like domain, path and expired.
|
239
245
|
#
|
240
|
-
#
|
246
|
+
# :api: private
|
241
247
|
def set_session_cookie_value(value, options = {})
|
242
248
|
defaults = {}
|
243
249
|
defaults[:expires] = Time.now + _session_expiry if _session_expiry > 0
|
@@ -248,7 +254,7 @@ module Merb
|
|
248
254
|
# ==== Returns
|
249
255
|
# String:: The value of the session cookie; either the session id or the actual encoded data.
|
250
256
|
#
|
251
|
-
#
|
257
|
+
# :api: private
|
252
258
|
def session_cookie_value
|
253
259
|
cookies[_session_id_key]
|
254
260
|
end
|
@@ -256,7 +262,7 @@ module Merb
|
|
256
262
|
|
257
263
|
# Destroy the session cookie.
|
258
264
|
#
|
259
|
-
#
|
265
|
+
# :api: private
|
260
266
|
def destroy_session_cookie
|
261
267
|
cookies.delete(_session_id_key)
|
262
268
|
end
|