device_detector_regexes 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +1 -11
- data/README.md +8 -13
- data/device_detector_regexes.gemspec +0 -2
- data/lib/device_detector_regexes.rb +39 -5
- data/lib/device_detector_regexes/device_detector.rb +14 -0
- data/lib/device_detector_regexes/version.rb +1 -1
- metadata +3 -31
- data/lib/device_detector_regexes/parser.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24497676df61d5343c44418e2f8c4c8904eed8947cb5db1212196ac542ab91e0
|
4
|
+
data.tar.gz: c9bd55656c6e3daee2a7d995d3f057b5ea87b09f4e0c423a5d90eaa0df77e1d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5fafe5b9c03bd69c37ee0240d9c4fd86210ed3e20ae55d089be998c809e3cd1e5d445077ee8d7d939ce3307ddb2c760479166d997f4d0f271808f0c3e62e738
|
7
|
+
data.tar.gz: 4e130d6639c97c4afb210477289bdde0be6bbce0f1ca15df2e24199ab51e947c94b82f11452782ea9dbc03b32bbf115f58bac4d72dc1dcb32633200dfc513940
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,23 +1,13 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
device_detector_regexes (0.1.
|
4
|
+
device_detector_regexes (0.1.4)
|
5
5
|
device_detector
|
6
|
-
dry-configurable
|
7
|
-
rake
|
8
6
|
|
9
7
|
GEM
|
10
8
|
remote: https://rubygems.org/
|
11
9
|
specs:
|
12
|
-
concurrent-ruby (1.1.6)
|
13
10
|
device_detector (1.0.3)
|
14
|
-
dry-configurable (0.11.3)
|
15
|
-
concurrent-ruby (~> 1.0)
|
16
|
-
dry-core (~> 0.4, >= 0.4.7)
|
17
|
-
dry-equalizer (~> 0.2)
|
18
|
-
dry-core (0.4.9)
|
19
|
-
concurrent-ruby (~> 1.0)
|
20
|
-
dry-equalizer (0.3.0)
|
21
11
|
rake (12.3.3)
|
22
12
|
|
23
13
|
PLATFORMS
|
data/README.md
CHANGED
@@ -21,32 +21,27 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
## Usage
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
```bash
|
27
|
-
rake map_into\["my_folder_name"\]
|
28
|
-
```
|
29
|
-
|
30
|
-
Somewhere in your code
|
24
|
+
Map device_detector [regexes folder](https://github.com/podigee/device_detector/tree/develop/regexes) into your custom folder
|
31
25
|
|
32
26
|
```ruby
|
33
|
-
|
27
|
+
DeviceDetector.configure do |config|
|
28
|
+
config.dir = "path/to/your/custom/folder"
|
29
|
+
end
|
34
30
|
```
|
35
31
|
|
36
|
-
|
32
|
+
Add new regexes to the appropriate file
|
37
33
|
|
38
34
|
```yaml
|
39
|
-
#
|
35
|
+
# your/custom/folder/regexes/client/mobile_apps.yml
|
40
36
|
|
41
37
|
# [] # leave an empty array here if the file is empty
|
42
|
-
- regex: 'Foo(?:[ /]([\d\.]+))
|
38
|
+
- regex: 'Foo(?:[ /]([\d\.]+))'
|
43
39
|
name: 'Bar'
|
44
40
|
version: '$1'
|
41
|
+
prefix: false # do not append piwik dd prefix
|
45
42
|
```
|
46
43
|
|
47
44
|
```ruby
|
48
|
-
# bin/console
|
49
|
-
|
50
45
|
client = DeviceDetector.new("Foo/2.1.2; Android: 9; Model:PAR-LX1; okhttp/3.12.8")
|
51
46
|
client.name # => "Bar"
|
52
47
|
client.full_version # => "2.1.2"
|
@@ -1,11 +1,45 @@
|
|
1
1
|
require "device_detector"
|
2
|
-
require "dry/configurable"
|
3
2
|
|
4
|
-
|
3
|
+
module DeviceDetectorRegexes; end
|
5
4
|
|
6
|
-
|
5
|
+
class DeviceDetector
|
6
|
+
class << self
|
7
|
+
class Configuration
|
8
|
+
def dir
|
9
|
+
@dir || Dir.pwd
|
10
|
+
end
|
7
11
|
|
8
|
-
|
12
|
+
def dir=(dir)
|
13
|
+
@dir = Pathname(dir)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
class DeviceDetector::Parser
|
20
|
+
def filepaths
|
21
|
+
filenames.each_with_object([]) do |filename, filenames|
|
22
|
+
|
23
|
+
# push custom files first due to higher precedence lookup than default files
|
24
|
+
custom_file_path = File.expand_path(filename, File.join(DeviceDetector.config.dir, "regexes"))
|
25
|
+
if File.exists?(custom_file_path)
|
26
|
+
filenames << [filename.to_sym, custom_file_path]
|
27
|
+
end
|
28
|
+
|
29
|
+
filenames << [filename.to_sym, File.join(ROOT, "regexes", filename)]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def parse_regexes(path, raw_regexes)
|
34
|
+
raw_regexes.map do |meta|
|
35
|
+
fail "invalid device spec: #{meta.inspect}" unless meta[:regex].is_a? String
|
36
|
+
meta[:regex] = build_regex(meta[:regex], meta[:prefix])
|
37
|
+
meta[:path] = path
|
38
|
+
meta
|
39
|
+
end
|
40
|
+
end
|
9
41
|
|
10
|
-
|
42
|
+
def build_regex(src, prefix = true)
|
43
|
+
Regexp.new (prefix ? '(?:^|[^A-Z0-9\-_]|[^A-Z0-9\-]_|sprd-)(?:' + src + ')' : src), Regexp::IGNORECASE
|
44
|
+
end
|
11
45
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# module DeviceDetectorRegexes
|
2
|
+
# def self.included(base)
|
3
|
+
# base.extend(Dry::Configurable)
|
4
|
+
# base.instance_eval do
|
5
|
+
# setting(:custom_dir, "/Users/kirill/Work/device_detector_regexes") { |dir| Pathname(dir) }
|
6
|
+
# end
|
7
|
+
# base.extend(ClassMethods)
|
8
|
+
# end
|
9
|
+
|
10
|
+
# module ClassMethods
|
11
|
+
# extend Dry::Configurable
|
12
|
+
# setting(:custom_dir, Dir.pwd) { |dir| Pathname(dir) }
|
13
|
+
# end
|
14
|
+
# end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: device_detector_regexes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Karpinovsky
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: device_detector
|
@@ -24,34 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: dry-configurable
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rake
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
27
|
description: DeviceDetectorRegexes is an extension for device_detector gem that makes
|
56
28
|
it easy to add new regular expressions
|
57
29
|
email:
|
@@ -75,7 +47,7 @@ files:
|
|
75
47
|
- bin/setup
|
76
48
|
- device_detector_regexes.gemspec
|
77
49
|
- lib/device_detector_regexes.rb
|
78
|
-
- lib/device_detector_regexes/
|
50
|
+
- lib/device_detector_regexes/device_detector.rb
|
79
51
|
- lib/device_detector_regexes/version.rb
|
80
52
|
homepage: https://github.com/karpinovsky/device_detector_regexes
|
81
53
|
licenses:
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module DeviceDetectorRegexes
|
2
|
-
class ::DeviceDetector::Parser
|
3
|
-
private
|
4
|
-
|
5
|
-
def filepaths
|
6
|
-
filenames.each_with_object([]) do |filename, filenames|
|
7
|
-
|
8
|
-
# push custom files first due to higher precedence lookup than default files
|
9
|
-
custom_file_path = File.expand_path(filename, File.join(DeviceDetectorRegexes.config.dir, 'regexes'))
|
10
|
-
if File.exists?(custom_file_path)
|
11
|
-
filenames << [filename.to_sym, custom_file_path]
|
12
|
-
end
|
13
|
-
|
14
|
-
filenames << [filename.to_sym, File.join(ROOT, 'regexes', filename)]
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|