sewing_kit 0.95.1 → 0.95.2
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.
- checksums.yaml +4 -4
- data/lib/hacks/user_agent_parser.rb +48 -0
- data/lib/sewing_kit/version.rb +1 -1
- data/lib/sewing_kit.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 759d3abb34bbf6410d9c9169709715d7945d49381402482bdeeb509261051ad5
|
4
|
+
data.tar.gz: 056e13651007ff24eaf011c94b4c957fe614830342a3640f7f53df21e6598d17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/sewing_kit/version.rb
CHANGED
data/lib/sewing_kit.rb
CHANGED
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.
|
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-
|
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
|