sewing_kit 0.95.1 → 0.95.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
  SHA256:
3
- metadata.gz: 41ebcd8335cbea9ad813df8116ee2d9eb628ae279a01ad072d167980a534e932
4
- data.tar.gz: cc99f63e71559984cf6616b5594f2dcba064916bfa452bdd623fc9152ee7b04e
3
+ metadata.gz: 759d3abb34bbf6410d9c9169709715d7945d49381402482bdeeb509261051ad5
4
+ data.tar.gz: 056e13651007ff24eaf011c94b4c957fe614830342a3640f7f53df21e6598d17
5
5
  SHA512:
6
- metadata.gz: f525e31bf2ac93cd30c426cc89c0db275d8126d99a370cc883b913dc70868e4bfea26b674365984bedfe9cc08d2afd97d1fec7544db9758d461e404babe6b614
7
- data.tar.gz: 5aa0cc16500aa6a98404da3ac96402d04ea0f85b453581f83a3b996914955467587d120f4ddca4d2d89a3598f51e1bb09eb41713c152b6f5e25b8ae9d03ecf08
6
+ metadata.gz: c0010f8cf7cca5ebd41b6df31168c26f646919b861669e48c288ea649d2f442ca4408da3d76791e558cf81d556f516ecf0f949d04f22b1acf49e8422d83ab49d
7
+ data.tar.gz: 97caa8ba30633c96ee91b1931c412623a0187dc92f94821dd8cef9f52b33213963d5d222e6dda07bb51ab30953696f7079a3ad47426f19c997cd76ef071c9a84
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+
5
+ # 🐵 patches eager-loading and cacheing of the default user_agent patterns
6
+ # PR to add the functionality for reals: https://github.com/ua-parser/uap-ruby/pull/56
7
+ module UserAgentParser
8
+ class Parser
9
+ class Patterns
10
+ def initialize
11
+ @cache = {}
12
+ get # warm the cache for the default patterns
13
+ end
14
+
15
+ def get(path = nil)
16
+ path = UserAgentParser::DefaultPatternsPath if path.nil?
17
+ @cache[path] ||= load_and_parse(path)
18
+ end
19
+
20
+ private
21
+
22
+ def load_and_parse(path)
23
+ yml = YAML.load_file(path)
24
+
25
+ # Parse all the regexs
26
+ yml.each_pair do |_type, patterns|
27
+ patterns.each do |pattern|
28
+ pattern[:regex] = Regexp.new(pattern['regex'], pattern['regex_flag'] == 'i')
29
+ end
30
+ end
31
+
32
+ [yml['user_agent_parsers'], yml['os_parsers'], yml['device_parsers']]
33
+ end
34
+ end
35
+
36
+ # rubocop:disable Style/ClassVars
37
+ @@patterns = Patterns.new
38
+
39
+ def self.load_patterns(path)
40
+ @@patterns.get(path)
41
+ end
42
+
43
+ def initialize(options = {})
44
+ @patterns_path = options[:patterns_path]
45
+ @ua_patterns, @os_patterns, @device_patterns = Parser.load_patterns(@patterns_path)
46
+ end
47
+ end
48
+ end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module SewingKit
3
- VERSION = "0.95.1"
3
+ VERSION = "0.95.2"
4
4
  end
data/lib/sewing_kit.rb CHANGED
@@ -5,3 +5,4 @@ end
5
5
  require "sewing_kit/version"
6
6
  require "sewing_kit/configuration"
7
7
  require "sewing_kit/rails"
8
+ require "hacks/user_agent_parser"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sewing_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.95.1
4
+ version: 0.95.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Sauve
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-12 00:00:00.000000000 Z
11
+ date: 2019-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
@@ -102,6 +102,7 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - README.md
105
+ - lib/hacks/user_agent_parser.rb
105
106
  - lib/sewing_kit.rb
106
107
  - lib/sewing_kit/configuration.rb
107
108
  - lib/sewing_kit/rails.rb