browser 3.0.2 → 3.0.3

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
  SHA256:
3
- metadata.gz: d8cf4326bc2b2d9ef069fdedd8c6be7a58ca40b7d3cb33ca0264db7df79504bc
4
- data.tar.gz: bd6e16613c80c97b9aa0895baf7991088aa19946f3daeef27db2f5fadcfd171d
3
+ metadata.gz: 35cb9e029740dd22fac2f08ea933fb541b914ddc3d437f49e2402f68be7aecb3
4
+ data.tar.gz: 534a21b9b6892178c02976d19fe8ef81e9746783ac87469239efb9e8033bfaeb
5
5
  SHA512:
6
- metadata.gz: 809f13b58435f1e26b7dcf188aa9b4bbe3bad566b8139c82399060794cbfb2a99747893de20c07687a85db5ec38463561d45f6f61b2020b36155c4be794a7182
7
- data.tar.gz: 9fb22873f199a46dbfd709b75f7bf5cea2a8ef515ba4beaffdf10f2bbf9e395b18e77888deaaeace0ce7e5e201429bc7ebbdf138bf0690e6fec93a296aa2d61a
6
+ metadata.gz: fe9062f778c871766bddce4738c63ad005e0fc6310c46b0505f78da1c304e5d2f0359d8c2685727203876f8b83bf7ee06fc7dfa6b2f5fb6da719cf60bd5f80a7
7
+ data.tar.gz: ecce9f6468c7e5cfb11e47aeeaa68c44d8be5ad6b4e6e34cc9f64721dbaf0adae1514cb8b57097ec679481da7286713468fa4ac88de397190179bbf13ef42331
@@ -1,10 +1,10 @@
1
1
  ---
2
2
  language: ruby
3
- sudo: false
4
3
  cache: bundler
5
4
  rvm:
6
- - 2.6.0
7
- - 2.5.0
5
+ - 2.7
6
+ - 2.6
7
+ - 2.5
8
8
  gemfile:
9
9
  - Gemfile
10
10
  - gemfiles/rails5.gemfile
@@ -4,6 +4,10 @@
4
4
 
5
5
  - Nothing yet.
6
6
 
7
+ # 3.0.3
8
+
9
+ - Deprecate `Browser.modern_rules` and `Browser::Base#modern?`. Theses methods will be removed on the next major released, or by June 1st 2020.
10
+
7
11
  ## 3.0.2
8
12
 
9
13
  - Remove .bundle directory from package.
data/README.md CHANGED
@@ -34,7 +34,6 @@ browser.ie?(6) # detect specific IE version
34
34
  browser.ie?([">8", "<10"]) # detect specific IE (IE9).
35
35
  browser.known? # has the browser been successfully detected?
36
36
  browser.meta # an array with several attributes
37
- browser.modern? # Webkit, Firefox 17+, IE 9+ and Opera 12+
38
37
  browser.name # readable browser name
39
38
  browser.nokia?
40
39
  browser.opera?
@@ -145,23 +144,26 @@ browser.mobile? #=> false
145
144
  - For a list of device detections, check [lib/browser/device.rb](https://github.com/fnando/browser/blob/master/lib/browser/device.rb)
146
145
  - For a list of bot detections, check [bots.yml](https://github.com/fnando/browser/blob/master/bots.yml)
147
146
 
148
- ### What defines a modern browser?
147
+ ### Detecting modern browsers
149
148
 
150
- The current rules that define a modern browser are pretty loose.
151
-
152
- * Chrome 65+
153
- * Safari 10+
154
- * Firefox 52+
155
- * IE11+
156
- * Microsoft Edge 39+
157
- * Opera 50+
158
-
159
- You can define your own rules. A rule must be a proc/lambda or any object that implements the method === and accepts the browser object. To redefine all rules, clear the existing rules before adding your own.
149
+ To detect whether a browser can be considered as modern or not, create a method that abstracts your versioning constraints. The following example will consider any of the following browsers as a modern:
160
150
 
161
151
  ```ruby
162
- # Only Google Chrome 79+ is considered modern.
163
- Browser.modern_rules.clear
164
- Browser.modern_rules << -> b { b.chrome? && b.version.to_i >= 79 }
152
+ # Expects an Browser instance,
153
+ # like in `Browser.new(user_agent, accept_language: language)`.
154
+ def modern_browser?(browser)
155
+ [
156
+ browser.chrome? && browser.version.to_i >= 65,
157
+ browser.safari? && browser.version.to_i >= 10,
158
+ browser.firefox? && browser.version.to_i >= 52,
159
+ browser.ie? && browser.version.to_i >= 11 && !browser.compatibility_view?,
160
+ browser.edge? && browser.version.to_i >= 15,
161
+ browser.opera? && browser.version.to_i >= 50,
162
+ browser.facebook?
163
+ && browser.safari_webapp_mode?
164
+ && browser.webkit_full_version.to_i >= 602
165
+ ].any?
166
+ end
165
167
  ```
166
168
 
167
169
  ### Rails integration
@@ -240,9 +242,6 @@ browser.msie_full_version
240
242
 
241
243
  browser.compatibility_view?
242
244
  #=> true
243
-
244
- browser.modern?
245
- #=> false
246
245
  ```
247
246
 
248
247
  This behavior changed in `v1.0.0`; previously there wasn't a way of getting the real browser version.
@@ -298,7 +297,7 @@ You can use the `Browser::Middleware` to redirect user agents.
298
297
 
299
298
  ```ruby
300
299
  use Browser::Middleware do
301
- redirect_to "/upgrade" unless browser.modern?
300
+ redirect_to "/upgrade" if browser.ie?
302
301
  end
303
302
  ```
304
303
 
@@ -306,17 +305,7 @@ If you're using Rails, you can use the route helper methods. Just add something
306
305
 
307
306
  ```ruby
308
307
  Rails.configuration.middleware.use Browser::Middleware do
309
- redirect_to upgrade_path unless browser.modern?
310
- end
311
- ```
312
-
313
- Notice that you can have multiple conditionals.
314
-
315
- ```ruby
316
- Rails.configuration.middleware.use Browser::Middleware do
317
- next if browser.bot.search_engine?
318
- redirect_to upgrade_path(browser: "oldie") if browser.ie? && !browser.modern?
319
- redirect_to upgrade_path(browser: "oldfx") if browser.firefox? && !browser.modern?
308
+ redirect_to upgrade_path if browser.ie?
320
309
  end
321
310
  ```
322
311
 
@@ -324,7 +313,7 @@ If you need access to the `Rack::Request` object (e.g. to exclude a path), you c
324
313
 
325
314
  ```ruby
326
315
  Rails.configuration.middleware.use Browser::Middleware do
327
- redirect_to upgrade_path unless browser.modern? || request.env["PATH_INFO"] == "/exclude_me"
316
+ redirect_to upgrade_path if browser.ie? && request.env["PATH_INFO"] != "/exclude_me"
328
317
  end
329
318
  ```
330
319
 
@@ -52,6 +52,11 @@ module Browser
52
52
 
53
53
  # Return true if browser is modern (Webkit, Firefox 17+, IE9+, Opera 12+).
54
54
  def modern?
55
+ warn <<~TEXT
56
+ Browser::Base#modern? is now deprecated.
57
+ Check https://github.com/fnando/browser/issues/435 for details.
58
+ TEXT
59
+
55
60
  Browser.modern_rules.any? {|rule| rule === self } # rubocop:disable Style/CaseEquality
56
61
  end
57
62
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Browser
4
- VERSION = "3.0.2"
4
+ VERSION = "3.0.3"
5
5
  end
@@ -24,3 +24,11 @@ module Minitest
24
24
  end
25
25
  end
26
26
  end
27
+
28
+ # Override Browser::Base#warn, so we don't output deprecation messages.
29
+ module Browser
30
+ class Base
31
+ def warn(*)
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browser
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-09 00:00:00.000000000 Z
11
+ date: 2020-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler