scorched 0.12 → 0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 83445d0e97b4717ff0d830c7e72f09bf0c8f8fa1
4
- data.tar.gz: eb90cc0893a4b53d180d7dca083f04340026b964
3
+ metadata.gz: 097dc690273075ecec2044e7ef6cc9ef285e4c03
4
+ data.tar.gz: ceac380dfda10425b551488c953e34efc4d681a6
5
5
  SHA512:
6
- metadata.gz: d90ea66b9a3a280fa2746d0a9cf12a0697c6169e035fdcba9753612bf3297bd01c87b4ca7fa286740c24441e6ec539105cb4621c99a4b28facacdfe2deedeade
7
- data.tar.gz: db597065e5a9d1dd93be4a738f998bea0cc85be0b057cd8b107eaad98f5932cc4ebf51aefc03a7b11c5ee412672f2c695e687e755cab5ed69c5f1c93f200d522
6
+ metadata.gz: 8b67fe3315887ef8cc9863c1353a803ff27e82d9f5c6ecb6b3d1b611077c1ec2ffad754e175e8adecaba2fb50f1ad7d96f3f3e5ce27f83c4005a5b5c44df8745
7
+ data.tar.gz: 4d68ca06da03b5cf45d25191b6786008591066f85e2bceb246e82e6ffccbef6d21a357e2534ee5114855e81015712cf3de584cb2ba93145fa213dc80c926b779
data/CHANGES.md CHANGED
@@ -1,6 +1,10 @@
1
1
  Changelog
2
2
  =========
3
3
 
4
+ ### v0.13
5
+ * Added `content_type` condition, corresponding to the `Content-Type` request header.
6
+ * Reverted rogue commit containing experimental debugging logging that I didn't plan to merge. Fixes issue #12.
7
+
4
8
  ### v0.12
5
9
  * Halt can now take an optional response body (typically a string).
6
10
  * Controller now returns a valid rack array, rather than a Scorched::Response.
@@ -69,6 +69,7 @@ Conditions are essentially just pre-requisites that must be met before a mapping
69
69
 
70
70
  * `:charset` - Character sets accepted by the client.
71
71
  * `:config` - Takes a hash, each element of which must match the value of the corresponding config option.
72
+ * `:content_type` - The content-type of the body of the request. E.g. "multipart/form-data", "application/json"
72
73
  * `:encoding` - Encodings accepted by the client.
73
74
  * `:failed_condition` - If one or more mappings are matched, but they're conditions do not pass, the first failed condition of the first matched mapping is considered the `failed_condition` for the request.
74
75
  * `:host` - The host name (i.e. domain name) used in the request.
@@ -39,13 +39,16 @@ module Scorched
39
39
 
40
40
  conditions << {
41
41
  charset: proc { |charsets|
42
- [*charsets].any? { |charset| request.env['rack-accept.request'].charset? charset }
42
+ [*charsets].any? { |charset| env['rack-accept.request'].charset? charset }
43
43
  },
44
44
  config: proc { |map|
45
45
  map.all? { |k,v| config[k] == v }
46
46
  },
47
+ content_type: proc { |content_types|
48
+ [*content_types].include? env['CONTENT_TYPE']
49
+ },
47
50
  encoding: proc { |encodings|
48
- [*encodings].any? { |encoding| request.env['rack-accept.request'].encoding? encoding }
51
+ [*encodings].any? { |encoding| env['rack-accept.request'].encoding? encoding }
49
52
  },
50
53
  failed_condition: proc { |conditions|
51
54
  if !matches.empty? && matches.all? { |m| m.failed_condition }
@@ -56,10 +59,10 @@ module Scorched
56
59
  (Regexp === host) ? host =~ request.host : host == request.host
57
60
  },
58
61
  language: proc { |languages|
59
- [*languages].any? { |language| request.env['rack-accept.request'].language? language }
62
+ [*languages].any? { |language| env['rack-accept.request'].language? language }
60
63
  },
61
64
  media_type: proc { |types|
62
- [*types].any? { |type| request.env['rack-accept.request'].media_type? type }
65
+ [*types].any? { |type| env['rack-accept.request'].media_type? type }
63
66
  },
64
67
  method: proc { |methods|
65
68
  [*methods].include?(request.request_method)
@@ -236,8 +239,6 @@ module Scorched
236
239
  end
237
240
  env['scorched.request'] ||= Request.new(env)
238
241
  env['scorched.response'] ||= Response.new
239
- @_log_prefix = ' ' * (4 * request.breadcrumb.length)
240
- log :debug, "#{log_object(self)} instantiated"
241
242
  end
242
243
 
243
244
  def action
@@ -256,7 +257,6 @@ module Scorched
256
257
  redirect(request.path.chomp('/'))
257
258
  end
258
259
 
259
- log :debug, :matches
260
260
  if matches.all? { |m| m.failed_condition }
261
261
  pass if config[:auto_pass]
262
262
  response.status = matches.empty? ? 404 : 403
@@ -267,19 +267,17 @@ module Scorched
267
267
  @_matched = true == matches.each { |match|
268
268
  next if match.failed_condition
269
269
  request.breadcrumb << match
270
- target = match.mapping[:target]
271
270
  break if catch(:pass) {
272
- log :debug, "Invoking target: #{log_object(target)}"
271
+ target = match.mapping[:target]
273
272
  response.merge! (Proc === target) ? instance_exec(env, &target) : target.call(env)
274
273
  }
275
274
  request.breadcrumb.pop
276
- log :debug, "#{log_object(target)} passed the request"
277
275
  }
278
276
  rescue => inner_error
279
277
  rescue_block.call(inner_error)
280
278
  end
281
279
  run_filters(:after)
282
- end || log(:debug, "Request halted")
280
+ end
283
281
  rescue => outer_error
284
282
  outer_error == inner_error ? raise : rescue_block.call(outer_error)
285
283
  end
@@ -520,52 +518,18 @@ module Scorched
520
518
 
521
519
  def run_filters(type)
522
520
  tracker = env['scorched.executed_filters'] ||= {before: Set.new, after: Set.new}
523
- eligable = filters[type].reject{ |f| tracker[type].include? f || check_for_failed_condition(f[:conditions])}
524
- log :debug, "Running #{eligable.length} eligable #{type} filters:"
525
- eligable.each do |f|
526
- log :debug, " #{f[:conditions]} => #{log_object f[:proc]}"
527
- tracker[type] << f
528
- instance_exec(&f[:proc])
529
- end
530
- end
531
-
532
- def log(type, message = nil, *args)
533
- if config[:logger]
534
- logger = config[:logger]
535
- type = Logger.const_get(type.to_s.upcase)
536
- logger.progname ||= 'Scorched'
537
-
538
- case message
539
- when :matches
540
- message = []
541
- eligable = matches.reject { |m| m.failed_condition }
542
- message << "#{matches.length} mappings matched #{request.unmatched_path.inspect}:"
543
- matches.each do |m|
544
- message << " #{m.mapping[:pattern].inspect} => #{log_object m.mapping[:target]}"
545
- end
546
- message << "#{eligable.length} of which are eligable:"
547
- eligable.each do |m|
548
- message << " #{m.mapping[:pattern].inspect} => #{log_object m.mapping[:target]}"
549
- end
550
- end
551
-
552
- [*message].each do |v|
553
- v.insert(0, @_log_prefix)
554
- logger.add(type, v)
521
+ filters[type].reject{ |f| tracker[type].include? f }.each do |f|
522
+ unless check_for_failed_condition(f[:conditions])
523
+ tracker[type] << f
524
+ instance_exec(&f[:proc])
555
525
  end
556
526
  end
557
- true # Makes it safe to use in conditions
558
527
  end
559
528
 
560
- def log_object(obj)
561
- case obj
562
- when Proc
563
- "<Proc @#{obj.source_location.join(':')}>"
564
- when Array
565
- obj.map { |v| log_object(v) }.inspect
566
- else
567
- obj.class.name || Controller === obj.class ? 'Anonymous controller' : 'Anonymous class'
568
- end
529
+ def log(type, message)
530
+ config[:logger].progname ||= 'Scorched'
531
+ type = Logger.const_get(type.to_s.upcase)
532
+ config[:logger].add(type, message)
569
533
  end
570
534
  end
571
535
  end
@@ -1,3 +1,3 @@
1
1
  module Scorched
2
- VERSION = '0.12'
2
+ VERSION = '0.13'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scorched
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.12'
4
+ version: '0.13'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Wardrop
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-31 00:00:00.000000000 Z
11
+ date: 2013-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack