browsernizer 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@
4
4
  .bundle
5
5
  Gemfile.lock
6
6
  pkg/*
7
+ /bin
data/CHANGELOG CHANGED
@@ -1,2 +1,6 @@
1
+ = Version 0.2.1
2
+ * Code cleanup by @Bertg
3
+ * Getting rid of warnings by @prowler
4
+
1
5
  = Version 0.2.0
2
6
  * ditched useragent, now using browser gem (backward compatibility might be broken)
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Browsernizer
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/browsernizer.png)](http://badge.fury.io/rb/browsernizer)
4
+
3
5
  Want friendly "please upgrade your browser" page? This gem is for you.
4
6
 
5
7
  You can redirect your visitors to any page you like (static or dynamic).
@@ -13,7 +13,7 @@ module Browsernizer
13
13
  end
14
14
 
15
15
  def <=>(other)
16
- ([0]*6).zip(to_a, other.to_a).each do |dump, a, b|
16
+ ([0]*6).zip(to_a, [*other]).each do |dump, a, b|
17
17
  r = (a||0) <=> (b||0)
18
18
  return r unless r.zero?
19
19
  end
@@ -10,37 +10,26 @@ module Browsernizer
10
10
  end
11
11
 
12
12
  def call(env)
13
- @env = env
14
- @env["browsernizer"] = {
15
- "supported" => true,
13
+ raw_browser, browser = get_browsers(env)
14
+ env["browsernizer"] = {
15
+ "supported" => supported?(raw_browser, browser),
16
16
  "browser" => browser.name.to_s,
17
17
  "version" => browser.version.to_s
18
18
  }
19
- handle_request
19
+ redirect_request(env) || @app.call(env)
20
20
  end
21
21
 
22
22
  private
23
- def handle_request
24
- @env["browsernizer"]["supported"] = false if unsupported?
25
23
 
26
- catch(:response) do
27
- if !path_excluded?
28
- if unsupported?
29
- if !on_redirection_path? && @config.get_location
30
- throw :response, redirect_to_specified
31
- end
32
- elsif on_redirection_path?
33
- throw :response, redirect_to_root
34
- end
35
- end
36
- propagate_request
24
+ def redirect_request(env)
25
+ return if path_excluded?(env)
26
+ if !env["browsernizer"]["supported"]
27
+ return redirect_to_specified if @config.get_location && !on_redirection_path?(env)
28
+ elsif on_redirection_path?(env)
29
+ return redirect_to_root
37
30
  end
38
31
  end
39
32
 
40
- def propagate_request
41
- @app.call(@env)
42
- end
43
-
44
33
  def redirect_to_specified
45
34
  [307, {"Content-Type" => "text/plain", "Location" => @config.get_location}, []]
46
35
  end
@@ -49,25 +38,23 @@ module Browsernizer
49
38
  [303, {"Content-Type" => "text/plain", "Location" => "/"}, []]
50
39
  end
51
40
 
52
- def path_excluded?
53
- @config.excluded? @env["PATH_INFO"]
54
- end
55
-
56
- def on_redirection_path?
57
- @config.get_location && @config.get_location == @env["PATH_INFO"]
41
+ def path_excluded?(env)
42
+ @config.excluded? env["PATH_INFO"]
58
43
  end
59
44
 
60
- def raw_browser
61
- ::Browser.new :ua => @env["HTTP_USER_AGENT"]
45
+ def on_redirection_path?(env)
46
+ @config.get_location && @config.get_location == env["PATH_INFO"]
62
47
  end
63
48
 
64
- def browser
65
- Browser.new raw_browser.name.to_s, raw_browser.full_version.to_s
49
+ def get_browsers(env)
50
+ raw_browser = ::Browser.new :ua => env["HTTP_USER_AGENT"]
51
+ browser = Browsernizer::Browser.new raw_browser.name.to_s, raw_browser.full_version.to_s
52
+ [raw_browser, browser]
66
53
  end
67
54
 
68
55
  # supported by default
69
- def unsupported?
70
- @config.get_supported.any? do |requirement|
56
+ def supported?(raw_browser, browser)
57
+ !@config.get_supported.any? do |requirement|
71
58
  supported = if requirement.respond_to?(:call)
72
59
  requirement.call(raw_browser)
73
60
  else
@@ -1,3 +1,3 @@
1
1
  module Browsernizer
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browsernizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-03 00:00:00.000000000 Z
12
+ date: 2013-04-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
16
- requirement: &70211448089400 !ruby/object:Gem::Requirement
16
+ requirement: &70152071474760 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70211448089400
24
+ version_requirements: *70152071474760
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70211448116560 !ruby/object:Gem::Requirement
27
+ requirement: &70152071473880 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70211448116560
35
+ version_requirements: *70152071473880
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: browser
38
- requirement: &70211448115820 !ruby/object:Gem::Requirement
38
+ requirement: &70152071472940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: 0.1.4
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70211448115820
46
+ version_requirements: *70152071472940
47
47
  description: Rack middleware for redirecting unsupported user agents to "please upgrade"
48
48
  page
49
49
  email: