turnout 0.2.3 → 0.2.4

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: adf33ca2dc98cb6fa15b8e17290193dd24f16795
4
- data.tar.gz: abff4e95ca98a1dc8bc2d10e11eea6e677fb0724
3
+ metadata.gz: f239e00975d88e68f53e7a3cc03df4124c02858a
4
+ data.tar.gz: 81227d4c7b4f6b74b45215291d3863a945a9acca
5
5
  SHA512:
6
- metadata.gz: 9d3f40a2d6701f652ffbddf93cb07f7b2d7ca7ce229b29283ad0079b51b1fbf948fdb597bfd36bd5000746b3dd1d74e3ffc48687c58c0a897f3b5e113ee3e164
7
- data.tar.gz: eca42d7c3acb642cc8dc5aa68f5790838756279a74eb143268087172ec1d69c89f4e82486f3c3fdfef8afea462454be53a11d8acbf0cea198a51fadfb698c432
6
+ metadata.gz: 7a507e6ed38712a52d941bb47ae7e5760d15d47278179c71410a2282990a7d16eadabd51a7eb3e940011984ff78fed9ac3eb5bd6e5751de1da02f3c79c0f5843
7
+ data.tar.gz: d36bd8d89167dfaeb95681dfd7554a07da861dcddd057e41decee83736aff60fb43a13ba7d176428e8e6afcba46b91cc62cb1425a346daf713dec0f6bdbaa597
@@ -82,7 +82,7 @@ A [default maintenance page](https://github.com/biola/turnout/blob/master/public
82
82
  Tips
83
83
  ====
84
84
 
85
- There is no `denied_paths` feature because turnout denies everyhing by default.
85
+ There is no `denied_paths` feature because turnout denies everything by default.
86
86
  However you can achieve the same sort of functionality by using
87
87
  [negative lookaheads](http://www.regular-expressions.info/lookaround.html) with the `allowed_paths` setting, like so:
88
88
 
@@ -106,4 +106,4 @@ Example maintenance.yml File
106
106
  - ^/contact_us
107
107
  allowed_ips:
108
108
  - 127.0.0.1
109
- - 192.168.0.0/24
109
+ - 192.168.0.0/24
@@ -10,9 +10,10 @@ class Rack::Turnout
10
10
  end
11
11
 
12
12
  def call(env)
13
+ self.request = Rack::Request.new(env)
13
14
  reload_settings
14
15
 
15
- if on?(env)
16
+ if on?
16
17
  [ 503, { 'Content-Type' => 'text/html', 'Content-Length' => content_length }, [content] ]
17
18
  else
18
19
  @app.call(env)
@@ -21,27 +22,32 @@ class Rack::Turnout
21
22
 
22
23
  protected
23
24
 
24
- def on?(env)
25
- request = Rack::Request.new(env)
25
+ attr_accessor :request
26
26
 
27
- return false if path_allowed?(request.path)
28
- return false if ip_allowed?(request.ip)
29
- maintenance_file_exists?
27
+ def on?
28
+ maintenance_file_exists? && !request_allowed?
30
29
  end
31
30
 
32
- def path_allowed?(path)
33
- (settings['allowed_paths'] || []).each do |allowed_path|
34
- return true if path =~ Regexp.new(allowed_path)
31
+ def request_allowed?
32
+ path_allowed? || ip_allowed?
33
+ end
34
+
35
+ def path_allowed?
36
+ (settings['allowed_paths'] || []).any? do |allowed_path|
37
+ request.path =~ Regexp.new(allowed_path)
35
38
  end
36
- false
37
39
  end
38
40
 
39
- def ip_allowed?(ip)
40
- ip = IPAddr.new(ip) unless ip.is_a? IPAddr
41
- (settings['allowed_ips'] || []).each do |allowed_ip|
42
- return true if IPAddr.new(allowed_ip).include? ip
41
+ def ip_allowed?
42
+ begin
43
+ ip = IPAddr.new(request.ip.to_s)
44
+ rescue ArgumentError
45
+ return false
46
+ end
47
+
48
+ (settings['allowed_ips'] || []).any? do |allowed_ip|
49
+ IPAddr.new(allowed_ip).include? ip
43
50
  end
44
- false
45
51
  end
46
52
 
47
53
  def reload_settings
@@ -1,3 +1,3 @@
1
1
  module Turnout
2
- VERSION = '0.2.3'
2
+ VERSION = '0.2.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turnout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Crownoble
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-17 00:00:00.000000000 Z
11
+ date: 2013-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -102,7 +102,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
102
102
  version: '0'
103
103
  requirements: []
104
104
  rubyforge_project:
105
- rubygems_version: 2.0.0.rc.2
105
+ rubygems_version: 2.0.3
106
106
  signing_key:
107
107
  specification_version: 4
108
108
  summary: A Rack based maintenance mode plugin for Rails