rack-domain-filter 1.0.1 → 1.0.2

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: ecad2be7765f37121b0adcce79f408ee0eefc089
4
- data.tar.gz: 6c46aa80f6a4af20434246db6fbab7e874bcfb42
3
+ metadata.gz: 534cb5c1b06beb433412c50f11fbb308a52ff39b
4
+ data.tar.gz: 5bff87a87f6e6739180aed8f5d330a616b2eea2b
5
5
  SHA512:
6
- metadata.gz: 915dd5d8a5299c746ce40afe428fe229bc336167330223f3ad71910f5e18041710d1cfde6139900b26cc94d90604e24e52f2d82c2a65704060eeba3f1141f842
7
- data.tar.gz: e4ab369e3f4c931e6d38c30960def317d19b8853880d151f145bbe920ec06a764a9908aa06aa014306428d4d074f70af142feb2824fba6e9036d8f2ffc35b1b0
6
+ metadata.gz: 77421c55c38572f1809b6f69ffcd0dd28fe031f7501f09775e1a2fa4105957a6b102309dbade273c30000484697df8cfdcaacbebc38e84e37e572a9a9b30ffc9
7
+ data.tar.gz: 7f6b0da2eeff62db29f2129c85bd90902981e16d1c83ea4452b17d8c2d64f6540ab727b391d938dff50497da517b49f25e75368a28a71b4a7558730589d407af
@@ -19,6 +19,10 @@ module Rack
19
19
 
20
20
  @no_match = block
21
21
  end
22
+
23
+ def skip_path_for(pattern)
24
+ @skip_path_patterns << pattern
25
+ end
22
26
  end
23
27
 
24
28
  # private
@@ -27,12 +31,14 @@ module Rack
27
31
  attr_accessor :uri_mapping
28
32
  attr_accessor :after_requests_list
29
33
  attr_accessor :exception_catcher_mapping
34
+ attr_accessor :skip_path_patterns
30
35
 
31
36
  def initialize
32
37
  @uri_mapping = {}
33
38
  @after_requests_list = []
34
39
  @exception_catcher_mapping = {}
35
40
  @no_match = nil
41
+ @skip_path_patterns = []
36
42
  end
37
43
 
38
44
  include ConfigurationDSL
@@ -45,6 +45,31 @@ module Rack
45
45
 
46
46
  true
47
47
  end
48
+
49
+ def can_skip_path?(env)
50
+ req = Rack::Request.new(env)
51
+ skip_current_request = false
52
+ config.skip_path_patterns.each do |pattern|
53
+ break if skip_current_request
54
+ if pattern.is_a?(String)
55
+ skip_current_request ||= skip_string?(pattern, req)
56
+ elsif pattern.is_a?(Regexp)
57
+ skip_current_request ||= skip_regex?(pattern, req)
58
+ else
59
+ raise "Unknown pattern: #{pattern}. It must be a regex or a string!"
60
+ end
61
+ end
62
+ skip_current_request
63
+ end
64
+
65
+ def skip_regex?(regex, req)
66
+ !req.fullpath.match(regex).nil?
67
+ end
68
+
69
+ def skip_string?(string, req)
70
+ string == req.fullpath
71
+ end
72
+
48
73
  end
49
74
  end
50
75
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class DomainFilter
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
@@ -10,20 +10,26 @@ module Rack
10
10
  @match_found = false
11
11
  end
12
12
 
13
+ def wrap_call
14
+ result = yield
15
+
16
+ run_after_request
17
+
18
+ result
19
+ end
20
+
13
21
  def call(env)
22
+ if can_skip_path?(env)
23
+ return wrap_call { @app.call(env) }
24
+ end
25
+
14
26
  match_uri(env)
15
27
 
16
28
  if !@match_found && can_respond_no_match?
17
- result = trigger_no_match(env)
18
- run_after_request
19
- return result
29
+ return wrap_call { trigger_no_match(env) }
20
30
  end
21
31
 
22
- result = @app.call(env)
23
-
24
- run_after_request
25
-
26
- result
32
+ wrap_call { @app.call(env) }
27
33
  rescue => e
28
34
  result = catch_exception(e)
29
35
  run_after_request
@@ -15,6 +15,9 @@ Gem::Specification.new do |spec|
15
15
  spec.summary = spec.description
16
16
  spec.version = Rack::DomainFilter::VERSION
17
17
 
18
+ # Test v2.6 after release
19
+ spec.required_ruby_version = ['>= 2.1', '< 2.6']
20
+
18
21
  spec.add_dependency 'rack'
19
22
 
20
23
  # Test and build tools
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-domain-filter
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Muhammad Mufid Afif
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-26 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -217,7 +217,10 @@ required_ruby_version: !ruby/object:Gem::Requirement
217
217
  requirements:
218
218
  - - ">="
219
219
  - !ruby/object:Gem::Version
220
- version: '0'
220
+ version: '2.1'
221
+ - - "<"
222
+ - !ruby/object:Gem::Version
223
+ version: '2.6'
221
224
  required_rubygems_version: !ruby/object:Gem::Requirement
222
225
  requirements:
223
226
  - - ">="
@@ -225,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
228
  version: '0'
226
229
  requirements: []
227
230
  rubyforge_project:
228
- rubygems_version: 2.6.13
231
+ rubygems_version: 2.6.14.1
229
232
  signing_key:
230
233
  specification_version: 4
231
234
  summary: Per-domain filter for Rack.