browser 2.0.0.rc1 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE.md +30 -0
  3. data/.rubocop.yml +3 -0
  4. data/.travis.yml +1 -1
  5. data/CHANGELOG.md +6 -1
  6. data/README.md +33 -3
  7. data/Rakefile +4 -4
  8. data/lib/browser.rb +1 -0
  9. data/lib/browser/accept_language.rb +1 -0
  10. data/lib/browser/action_controller.rb +3 -2
  11. data/lib/browser/base.rb +1 -0
  12. data/lib/browser/blackberry.rb +1 -0
  13. data/lib/browser/bot.rb +2 -1
  14. data/lib/browser/chrome.rb +1 -0
  15. data/lib/browser/detect_version.rb +1 -0
  16. data/lib/browser/device.rb +6 -7
  17. data/lib/browser/device/base.rb +1 -0
  18. data/lib/browser/device/blackberry_playbook.rb +1 -0
  19. data/lib/browser/device/ipad.rb +1 -0
  20. data/lib/browser/device/iphone.rb +1 -0
  21. data/lib/browser/device/ipod_touch.rb +1 -0
  22. data/lib/browser/device/kindle.rb +1 -0
  23. data/lib/browser/device/kindle_fire.rb +1 -0
  24. data/lib/browser/device/playstation3.rb +1 -0
  25. data/lib/browser/device/playstation4.rb +1 -0
  26. data/lib/browser/device/psp.rb +1 -0
  27. data/lib/browser/device/psvita.rb +1 -0
  28. data/lib/browser/device/surface.rb +2 -1
  29. data/lib/browser/device/tv.rb +1 -0
  30. data/lib/browser/device/unknown.rb +1 -0
  31. data/lib/browser/device/wii.rb +1 -0
  32. data/lib/browser/device/wiiu.rb +1 -0
  33. data/lib/browser/device/xbox_360.rb +1 -0
  34. data/lib/browser/device/xbox_one.rb +1 -0
  35. data/lib/browser/edge.rb +1 -0
  36. data/lib/browser/firefox.rb +1 -0
  37. data/lib/browser/generic.rb +1 -0
  38. data/lib/browser/internet_explorer.rb +1 -0
  39. data/lib/browser/meta/base.rb +1 -0
  40. data/lib/browser/meta/device.rb +1 -0
  41. data/lib/browser/meta/generic_browser.rb +1 -0
  42. data/lib/browser/meta/id.rb +1 -0
  43. data/lib/browser/meta/ie.rb +3 -2
  44. data/lib/browser/meta/ios.rb +1 -0
  45. data/lib/browser/meta/mobile.rb +1 -0
  46. data/lib/browser/meta/modern.rb +1 -0
  47. data/lib/browser/meta/platform.rb +1 -0
  48. data/lib/browser/meta/proxy.rb +1 -0
  49. data/lib/browser/meta/safari.rb +1 -0
  50. data/lib/browser/meta/tablet.rb +1 -0
  51. data/lib/browser/meta/webkit.rb +1 -0
  52. data/lib/browser/middleware.rb +1 -0
  53. data/lib/browser/middleware/context.rb +1 -0
  54. data/lib/browser/middleware/context/additions.rb +1 -0
  55. data/lib/browser/middleware/context/url_methods.rb +1 -0
  56. data/lib/browser/nokia.rb +1 -0
  57. data/lib/browser/opera.rb +1 -0
  58. data/lib/browser/phantom_js.rb +1 -0
  59. data/lib/browser/platform.rb +11 -10
  60. data/lib/browser/platform/adobe_air.rb +1 -0
  61. data/lib/browser/platform/android.rb +1 -0
  62. data/lib/browser/platform/base.rb +1 -0
  63. data/lib/browser/platform/blackberry.rb +1 -0
  64. data/lib/browser/platform/chrome_os.rb +1 -0
  65. data/lib/browser/platform/firefox_os.rb +1 -0
  66. data/lib/browser/platform/ios.rb +1 -0
  67. data/lib/browser/platform/linux.rb +1 -0
  68. data/lib/browser/platform/mac.rb +1 -0
  69. data/lib/browser/platform/other.rb +1 -0
  70. data/lib/browser/platform/windows.rb +1 -0
  71. data/lib/browser/platform/windows_mobile.rb +1 -0
  72. data/lib/browser/platform/windows_phone.rb +1 -0
  73. data/lib/browser/rails.rb +1 -0
  74. data/lib/browser/safari.rb +2 -1
  75. data/lib/browser/testing.rb +1 -0
  76. data/lib/browser/uc_browser.rb +1 -0
  77. data/lib/browser/version.rb +2 -1
  78. data/test/browser_test.rb +1 -0
  79. data/test/middleware_test.rb +1 -0
  80. data/test/rails_test.rb +21 -0
  81. data/test/sample_app.rb +9 -0
  82. data/test/test_helper.rb +1 -0
  83. data/test/ua.yml +1 -0
  84. data/test/unit/accept_language_test.rb +1 -0
  85. data/test/unit/adobe_air_test.rb +1 -0
  86. data/test/unit/android_test.rb +1 -0
  87. data/test/unit/blackberry_test.rb +1 -0
  88. data/test/unit/bots_test.rb +1 -0
  89. data/test/unit/chrome_test.rb +1 -0
  90. data/test/unit/console_test.rb +1 -0
  91. data/test/unit/device_test.rb +1 -0
  92. data/test/unit/firefox_test.rb +1 -0
  93. data/test/unit/ie_test.rb +1 -0
  94. data/test/unit/ios_app_test.rb +1 -0
  95. data/test/unit/ios_test.rb +1 -0
  96. data/test/unit/kindle_test.rb +1 -0
  97. data/test/unit/nokia_test.rb +1 -0
  98. data/test/unit/opera_test.rb +6 -0
  99. data/test/unit/platform_test.rb +1 -0
  100. data/test/unit/proxy_test.rb +1 -0
  101. data/test/unit/safari_test.rb +1 -0
  102. data/test/unit/uc_browser_test.rb +1 -0
  103. data/test/unit/windows_phone_test.rb +1 -0
  104. data/test/unit/windows_test.rb +1 -0
  105. metadata +7 -5
  106. data/CONTRIBUTING.md +0 -44
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f578d8090bda26ced6964ce2894e545b7a10e5a6
4
- data.tar.gz: e8b3f2a1f6b5f0052af82f531284a6f9bfa25042
3
+ metadata.gz: fb23db30128545d1362d657be31139c5c0d79ab1
4
+ data.tar.gz: dd8e2126bd5de416a2d29beb3ceff26c9ed28494
5
5
  SHA512:
6
- metadata.gz: 5ac0365b335f80c2e460c80990523b928ee88e413ad47f9b52f47d5778e3ef12fe001b0f6f357d45c574ae6bb5503b248062273aa7b261da14638ee1dbff032e
7
- data.tar.gz: 0269de18d4aeffa748e7752279579b505e2d1025a70c149421496caa227196e7b97fb8b1629cacbe597667a3aaa4ecc8ddc42127b21476f227727b37d82d53ce
6
+ metadata.gz: 6138595faa14527bc208ac1cdb8adb173ea3c0946988107d35846f67ad7c501e684e3f8eb28c84e71d6397156ac1259fc553bb64f78a87878fa8fd91e0586008
7
+ data.tar.gz: a750b44ed0eabdcaedf98755363a772772e0c58efc83fdad00ccc74f8ad5a1bc0a8c28648f31ad422934a54f3ea6f8f5595ce94b79c7999ac46a42c548e78a26
@@ -0,0 +1,30 @@
1
+ ## Description
2
+
3
+ [Add feature/bug description here]
4
+
5
+ ## How to reproduce
6
+
7
+ [Add steps on how to reproduce this issue]
8
+
9
+ ## What do you expect
10
+
11
+ [Describe what do you expect to happen]
12
+
13
+ ## What happened instead
14
+
15
+ [Describe the actual results]
16
+
17
+ ## Software:
18
+
19
+ - Rails version: [Add rails version here]
20
+ - Browser gem version: [Add browser gem version here]
21
+
22
+ ## Full backtrace
23
+
24
+ ```text
25
+ [Paste full backtrace here]
26
+ ```
27
+
28
+ ## Report
29
+
30
+ [Visit <http://user-agent.herokuapp.com> and paste the URL here]
data/.rubocop.yml CHANGED
@@ -1,3 +1,6 @@
1
+ Style/FrozenStringLiteralComment:
2
+ EnforcedStyle: always
3
+
1
4
  Style/ClassCheck:
2
5
  EnforcedStyle: kind_of?
3
6
 
data/.travis.yml CHANGED
@@ -8,6 +8,6 @@ rvm:
8
8
  gemfile:
9
9
  - Gemfile
10
10
  - gemfiles/rails3.gemfile
11
- script: "bundle exec rake spec"
11
+ script: "bundle exec rake"
12
12
  notifications:
13
13
  email: false
data/CHANGELOG.md CHANGED
@@ -1,10 +1,15 @@
1
1
  # Changelog
2
2
 
3
- ## v2.0.0 [unreleased]
3
+ ## v2.0.1
4
+
5
+ - Fix Rails integration.
6
+
7
+ ## v2.0.0
4
8
 
5
9
  - `Browser#platform` now returns instance of `Browser::Platform`, instead of a `String`. It contains information about the platform (software).
6
10
  - `Browser#device` was added. It returns information about the device (hardware).
7
11
  - `Browser#accept_language` now returns a list of `Browser::AcceptLanguage` objects.
8
12
  - `Browser#bot` now returns a `Browser::Bot` instance.
9
13
  - Safari running as web app mode is not recognized as Safari anymore.
14
+ - ruby-2.3+ will always activate frozen strings.
10
15
  - [List of all commits since last release](https://github.com/fnando/browser/compare/v1.1.0...v2.0.0)
data/README.md CHANGED
@@ -273,9 +273,33 @@ Rails.configuration.middleware.use Browser::Middleware do
273
273
  end
274
274
  ```
275
275
 
276
+ ### Migrating to v2
277
+
278
+ #### Troubleshooting
279
+
280
+ ##### `TypeError: no implicit conversion of Hash into String`
281
+
282
+ The class constructor now has a different signature. Change the instantiation from `Browser.new(options)` to `Browser.new(ua, options)`, where:
283
+
284
+ - `ua`: must be a string representing the user agent.
285
+ - `options`: must be a hash (for now it only accepts the `accept_language` option).
286
+
276
287
  ## Development
277
288
 
278
- If you want to contribute to this project, just follow the tips below.
289
+ ### Writing code
290
+
291
+ Once you've made your great commits (include tests, please):
292
+
293
+ 1. [Fork](http://help.github.com/forking/) browser
294
+ 2. Create a topic branch - `git checkout -b my_branch`
295
+ 3. Push to your branch - `git push origin my_branch`
296
+ 4. Create a pull request
297
+ 5. That's it!
298
+
299
+ Please respect the indentation rules and code style.
300
+ And use 2 spaces, not tabs. And don't touch the version thing.
301
+
302
+ ## Configuring environment
279
303
 
280
304
  To configure your environment, you must have Ruby and bundler installed. Then run `bundle install` to install all dependencies.
281
305
 
@@ -285,12 +309,16 @@ To run tests, execute `./bin/rake`.
285
309
 
286
310
  Before using your time to code a new feature, open a ticket asking if it makes sense and if it's on this project's scope.
287
311
 
312
+ Don't forget to add a new entry to `CHANGELOG.md`.
313
+
288
314
  #### Adding a new bot
289
315
 
290
316
  1. Add the user agent to `test/ua_bots.yml`.
291
317
  2. Add the readable name to `bots.yml`. The key must be something that matches the user agent, in lowercased text.
292
318
  3. Run tests.
293
319
 
320
+ Don't forget to add a new entry to `CHANGELOG.md`.
321
+
294
322
  #### Adding a new search engine
295
323
 
296
324
  1. Add the user agent to `test/ua_search_engines.yml`.
@@ -298,9 +326,11 @@ Before using your time to code a new feature, open a ticket asking if it makes s
298
326
  3. Add the readable name to `search_engines.yml`. The key must be something that matches the user agent, in lowercased text.
299
327
  4. Run tests.
300
328
 
301
- #### Wrong browser detection
329
+ Don't forget to add a new entry to `CHANGELOG.md`.
330
+
331
+ #### Wrong browser/platform/device detection
302
332
 
303
- Follow the instructions of [CONTRIBUTING.md](https://github.com/fnando/browser/blob/master/CONTRIBUTING.md).
333
+ If you know how to fix it, follow the "Writing code" above. Open an issue otherwise; make sure you fill in the issue template with all the required information.
304
334
 
305
335
  ## Maintainer
306
336
 
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require "bundler/setup"
3
3
  Bundler::GemHelper.install_tasks
4
4
 
5
5
  require "rake/testtask"
6
- Rake::TestTask.new(:spec) do |t|
6
+ Rake::TestTask.new(:test) do |t|
7
7
  t.libs << "lib"
8
8
  t.libs << "test"
9
9
  t.test_files = FileList["test/**/*_test.rb"]
@@ -12,14 +12,14 @@ Rake::TestTask.new(:spec) do |t|
12
12
  end
13
13
 
14
14
  desc "Run specs against all gemfiles"
15
- task "spec:all" do
15
+ task "test:all" do
16
16
  %w[
17
17
  Gemfile
18
18
  gemfiles/rails3.gemfile
19
19
  ].each do |gemfile|
20
20
  puts "=> Running with Gemfile: #{gemfile}"
21
- system "BUNDLE_GEMFILE=#{gemfile} rake spec"
21
+ system "BUNDLE_GEMFILE=#{gemfile} rake test"
22
22
  end
23
23
  end
24
24
 
25
- task default: "spec"
25
+ task default: "test"
data/lib/browser.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "set"
2
3
  require "yaml"
3
4
  require "pathname"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class AcceptLanguage
3
4
  def self.languages
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "action_controller/railtie"
2
3
 
3
4
  module Browser
@@ -12,8 +13,8 @@ module Browser
12
13
 
13
14
  def browser
14
15
  @browser ||= Browser.new(
15
- accept_language: request.headers["Accept-Language"],
16
- ua: request.headers["User-Agent"]
16
+ request.headers["User-Agent"],
17
+ accept_language: request.headers["Accept-Language"]
17
18
  )
18
19
  end
19
20
  end
data/lib/browser/base.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Base
3
4
  include DetectVersion
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class BlackBerry < Base
3
4
  def id
data/lib/browser/bot.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Bot
3
4
  def self.detect_empty_ua!
@@ -5,7 +6,7 @@ module Browser
5
6
  end
6
7
 
7
8
  def self.detect_empty_ua?
8
- !!@detect_empty_ua
9
+ @detect_empty_ua
9
10
  end
10
11
 
11
12
  def self.bots
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Chrome < Base
3
4
  def id
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module DetectVersion
3
4
  private
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  attr_reader :ua
@@ -39,10 +40,10 @@ module Browser
39
40
  # Detect if browser is tablet (currently iPad, Android, Surface or
40
41
  # Playbook).
41
42
  def tablet?
42
- !!(
43
- ipad? ||
44
- (platform.android? && !detect_mobile?) || surface? || playbook?
45
- )
43
+ ipad? ||
44
+ (platform.android? && !detect_mobile?) ||
45
+ surface? ||
46
+ playbook?
46
47
  end
47
48
 
48
49
  # Detect if browser is mobile.
@@ -159,12 +160,10 @@ module Browser
159
160
  # Regex taken from http://detectmobilebrowsers.com
160
161
  # rubocop:disable Metrics/LineLength
161
162
  def detect_mobile?
162
- !!(
163
- psp? ||
163
+ psp? ||
164
164
  /zunewp7/i.match(ua) ||
165
165
  /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.match(ua) ||
166
166
  /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.match(ua[0..3])
167
- )
168
167
  end
169
168
  # rubocop:enable Metrics/LineLength
170
169
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class BlackBerryPlaybook < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class Ipad < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class Iphone < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class IpodTouch < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class Kindle < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class KindleFire < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class PlayStation3 < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class PlayStation4 < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class PSP < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class PSVita < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class Surface < Base
@@ -10,7 +11,7 @@ module Browser
10
11
  end
11
12
 
12
13
  def match?
13
- platform.windows_rt? && !!(ua =~ /Touch/)
14
+ platform.windows_rt? && ua =~ /Touch/
14
15
  end
15
16
 
16
17
  private
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class TV < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class Unknown < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class Wii < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class WiiU < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class Xbox360 < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Device
3
4
  class XboxOne < Base
data/lib/browser/edge.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Edge < InternetExplorer
3
4
  def id
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Firefox < Base
3
4
  def id
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Generic < Base
3
4
  NAMES = {
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class InternetExplorer < Base
3
4
  # https://msdn.microsoft.com/en-us/library/ms537503(v=vs.85).aspx#TriToken
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class Device < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class GenericBrowser < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class Id < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class IE < Base
@@ -8,10 +9,10 @@ module Browser
8
9
  def meta
9
10
  return unless browser.ie?
10
11
 
11
- meta = ""
12
+ meta = []
12
13
  meta << "oldie lt-ie8 lt-ie9" if version < 8
13
14
  meta << "lt-ie9" if version == 8
14
- meta
15
+ meta.join(" ")
15
16
  end
16
17
  end
17
18
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class IOS < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class Mobile < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class Modern < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class Platform < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class Proxy < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class Safari < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class Tablet < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  module Meta
3
4
  class Webkit < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "uri"
2
3
 
3
4
  module Browser
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Middleware
3
4
  class Context
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "browser/middleware/context/url_methods"
2
3
 
3
4
  module Browser
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Middleware
3
4
  class Context
data/lib/browser/nokia.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Nokia < Base
3
4
  def id
data/lib/browser/opera.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Opera < Base
3
4
  def id
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class PhantomJS < Base
3
4
  def id
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  include DetectVersion
@@ -105,40 +106,40 @@ module Browser
105
106
 
106
107
  # http://msdn.microsoft.com/fr-FR/library/ms537503.aspx#PltToken
107
108
  def windows_xp?
108
- windows? && !!(ua =~ /Windows NT 5\.[12]/)
109
+ windows? && ua =~ /Windows NT 5\.[12]/
109
110
  end
110
111
 
111
112
  def windows_vista?
112
- windows? && !!(ua =~ /Windows NT 6\.0/)
113
+ windows? && ua =~ /Windows NT 6\.0/
113
114
  end
114
115
 
115
116
  def windows7?
116
- windows? && !!(ua =~ /Windows NT 6\.1/)
117
+ windows? && ua =~ /Windows NT 6\.1/
117
118
  end
118
119
 
119
120
  def windows8?
120
- windows? && !!(ua =~ /Windows NT 6\.[2-3]/)
121
+ windows? && ua =~ /Windows NT 6\.[2-3]/
121
122
  end
122
123
 
123
124
  def windows8_1?
124
- windows? && !!(ua =~ /Windows NT 6\.3/)
125
+ windows? && ua =~ /Windows NT 6\.3/
125
126
  end
126
127
 
127
128
  def windows10?
128
- windows? && !!(ua =~ /Windows NT 10/)
129
+ windows? && ua =~ /Windows NT 10/
129
130
  end
130
131
 
131
132
  def windows_rt?
132
- windows8? && !!(ua =~ /ARM/)
133
+ windows8? && ua =~ /ARM/
133
134
  end
134
135
 
135
136
  # Detect if current platform is Windows in 64-bit architecture.
136
137
  def windows_x64?
137
- !!(windows? && ua =~ /(Win64|x64|Windows NT 5\.2)/)
138
+ windows? && ua =~ /(Win64|x64|Windows NT 5\.2)/
138
139
  end
139
140
 
140
141
  def windows_wow64?
141
- windows? && !!(ua =~ /WOW64/i)
142
+ windows? && ua =~ /WOW64/i
142
143
  end
143
144
 
144
145
  def windows_x64_inclusive?
@@ -146,7 +147,7 @@ module Browser
146
147
  end
147
148
 
148
149
  def windows_touchscreen_desktop?
149
- windows? && !!(ua =~ /Touch/)
150
+ windows? && ua =~ /Touch/
150
151
  end
151
152
  end
152
153
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class AdobeAir < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class Android < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class BlackBerry < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class ChromeOS < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class FirefoxOS < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class IOS < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class Linux < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class Mac < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class Other < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class Windows < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class WindowsMobile < Base
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Platform
3
4
  class WindowsPhone < Base
data/lib/browser/rails.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "rails/railtie"
2
3
  require "browser/action_controller"
3
4
  require "browser/middleware/context/additions"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class Safari < Base
3
4
  def id
@@ -16,7 +17,7 @@ module Browser
16
17
  end
17
18
 
18
19
  def match?
19
- !!(ua =~ /Safari/ && ua !~ /Chrome|CriOS|PhantomJS|FxiOS/)
20
+ ua =~ /Safari/ && ua !~ /Chrome|CriOS|PhantomJS|FxiOS/
20
21
  end
21
22
  end
22
23
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  def self.user_agents
3
4
  @user_agents ||= browser_user_agents
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
3
  class UCBrowser < Base
3
4
  def id
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Browser
2
- VERSION = "2.0.0.rc1"
3
+ VERSION = "2.0.1"
3
4
  end
data/test/browser_test.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class BrowserTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
  require "browser/rails"
3
4
  require "sample_app"
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+ require "test_helper"
3
+ require "browser/rails"
4
+ require "sample_app"
5
+
6
+ class RailsTest < Minitest::Test
7
+ include Rack::Test::Methods
8
+
9
+ def app
10
+ Rails.application
11
+ end
12
+
13
+ test "renders page" do
14
+ get "/home", {}, "HTTP_USER_AGENT" => Browser["CHROME"],
15
+ "HTTP_ACCEPT" => "text/html",
16
+ "HTTP_ACCEPT_LANGUAGE" => "en-US;q=0.8"
17
+
18
+ assert_equal 200, last_response.status
19
+ assert_equal "Chrome:en-US", last_response.body
20
+ end
21
+ end
data/test/sample_app.rb CHANGED
@@ -1,6 +1,13 @@
1
+ # frozen_string_literal: true
1
2
  require "rails"
2
3
  require "browser"
3
4
 
5
+ class PagesController < ActionController::Base
6
+ def home
7
+ render text: "#{browser.name}:#{browser.accept_language.first.full}"
8
+ end
9
+ end
10
+
4
11
  class SampleApp < Rails::Application
5
12
  config.secret_token = "99f19f08db7a37bdcb9d6701f54dca"
6
13
  config.secret_key_base = "99f19f08db7a37bdcb9d6701f54dca"
@@ -19,6 +26,8 @@ class SampleApp < Rails::Application
19
26
  get "/asset", to: proc {
20
27
  [200, {"Content-Type" => "image/png"}, []]
21
28
  }
29
+
30
+ get "/home", to: "pages#home"
22
31
  end
23
32
 
24
33
  config.middleware.use Browser::Middleware do
data/test/test_helper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", __FILE__)
2
3
  require "bundler/setup"
3
4
  require "minitest/autorun"
data/test/ua.yml CHANGED
@@ -72,6 +72,7 @@ NINTENDO_WIIU: 'Mozilla/5.0 (Nintendo WiiU) AppleWebKit/534.52 (KHTML, like Geck
72
72
  NOKIA: 'Mozilla/5.0 (Series40; NokiaX3-02/le6.32; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/2.0.2.62.10'
73
73
  NOOK: 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; NOOK BNTV250A Build/GINGERBREAD 1.4.3) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Safari/533.1'
74
74
  OPERA: 'Opera/9.80 (Macintosh; Intel Mac OS X 10.7.4; U; en) Presto/2.10.229 Version/11.64'
75
+ OPERA_ANDROID: 'Mozill/5.0 (Linux; Android 4.4.2; A1-810 Build/KOT49H) Apple/WebKit/537.36 (KHTML, like Gecko) Chrome/48.0.25 64.99 Safari/537.36 OPR/35.0.2070.100283'
75
76
  OPERA_MINI: 'Opera/9.80 (Android; Opera Mini/7.029952/28.2359;u; fr) Presto/2.8.119 Version/11.10'
76
77
  OPERA_MOBI: 'Opera/9.8 (Android 2.3.5; Linux; Opera Mobi/ADR-1205181138; U; en) Presto/2.10.254 Version/12.00'
77
78
  OPERA_NEXT: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.37 Safari/537.36 OPR/15.0.1147.44 (Edition Next)'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class AcceptLanguageTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class AdobeAirTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class AndroidTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class BlackberryTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class BotsTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class ChromeTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class ConsoleTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class DeviceTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class FirefoxTest < Minitest::Test
data/test/unit/ie_test.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class IeTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class IosAppTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class IosTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class KindleTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class NokiaTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class OperaTest < Minitest::Test
@@ -33,4 +34,9 @@ class OperaTest < Minitest::Test
33
34
  browser = Browser.new(Browser["OPERA_MOBI"])
34
35
  assert browser.opera?
35
36
  end
37
+
38
+ test "detects opera running in Android" do
39
+ browser = Browser.new(Browser["OPERA_ANDROID"])
40
+ assert browser.platform.android?
41
+ end
36
42
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class PlatformTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class ProxyTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class SafariTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class UcBrowserTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class WindowPhoneTest < Minitest::Test
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "test_helper"
2
3
 
3
4
  class WindowsTest < Minitest::Test
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: 2.0.0.rc1
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-19 00:00:00.000000000 Z
11
+ date: 2016-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,12 +130,12 @@ extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
132
  - ".bundle/config"
133
+ - ".github/ISSUE_TEMPLATE.md"
133
134
  - ".gitignore"
134
135
  - ".hound.yml"
135
136
  - ".rubocop.yml"
136
137
  - ".travis.yml"
137
138
  - CHANGELOG.md
138
- - CONTRIBUTING.md
139
139
  - Gemfile
140
140
  - README.md
141
141
  - Rakefile
@@ -219,6 +219,7 @@ files:
219
219
  - search_engines.yml
220
220
  - test/browser_test.rb
221
221
  - test/middleware_test.rb
222
+ - test/rails_test.rb
222
223
  - test/sample_app.rb
223
224
  - test/test_helper.rb
224
225
  - test/ua.yml
@@ -260,9 +261,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
260
261
  version: '2.0'
261
262
  required_rubygems_version: !ruby/object:Gem::Requirement
262
263
  requirements:
263
- - - ">"
264
+ - - ">="
264
265
  - !ruby/object:Gem::Version
265
- version: 1.3.1
266
+ version: '0'
266
267
  requirements: []
267
268
  rubyforge_project:
268
269
  rubygems_version: 2.5.1
@@ -272,6 +273,7 @@ summary: Do some browser detection with Ruby.
272
273
  test_files:
273
274
  - test/browser_test.rb
274
275
  - test/middleware_test.rb
276
+ - test/rails_test.rb
275
277
  - test/sample_app.rb
276
278
  - test/test_helper.rb
277
279
  - test/ua.yml
data/CONTRIBUTING.md DELETED
@@ -1,44 +0,0 @@
1
- # Contributing
2
-
3
- ## Issues
4
-
5
- If you want to request a feature or report a bug, please use the following template.
6
-
7
- ```markdown
8
- ## Description
9
-
10
- [Add feature/bug description here]
11
-
12
- ## How to reproduce
13
-
14
- [Add steps on how to reproduce this issue]
15
-
16
- ## What do you expect
17
-
18
- [Describe what do you expect to happen]
19
-
20
- ## What happened instead
21
-
22
- [Describe the actual results]
23
-
24
- ## Gem version:
25
-
26
- Browser version: [Add browser gem version here]
27
-
28
- ## Report
29
-
30
- Visit <http://user-agent.herokuapp.com> and paste the URL here.
31
- ```
32
-
33
- ## Writing code
34
-
35
- Once you've made your great commits (include tests, please):
36
-
37
- 1. [Fork](http://help.github.com/forking/) browser
38
- 2. Create a topic branch - `git checkout -b my_branch`
39
- 3. Push to your branch - `git push origin my_branch`
40
- 4. [Create an Issue](http://github.com/fnando/browser/issues) with a link to your branch
41
- 5. That's it!
42
-
43
- Please respect the indentation rules and code style.
44
- And use 2 spaces, not tabs. And don't touch the versioning thing.