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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 458ba73e56fa8816165641a61acdbf1657742c65c943f78a5ac0bd5507bddbd6
4
- data.tar.gz: 9fce9bbad7375ab3c799595a7bb90333563b9d712041c257b53930893664e57b
3
+ metadata.gz: 24497676df61d5343c44418e2f8c4c8904eed8947cb5db1212196ac542ab91e0
4
+ data.tar.gz: c9bd55656c6e3daee2a7d995d3f057b5ea87b09f4e0c423a5d90eaa0df77e1d2
5
5
  SHA512:
6
- metadata.gz: e5928c890ed125c14fe5a1ca0dd5bf591108099e086b7513a4a33f8d6f02889fa922e9ca14b05eced518111738454b44a1fedb5a5dcb31e4c62fbebe70e48d69
7
- data.tar.gz: f44a1309a9851c466656f5b33f778be57bdc772e521c2b18c9b38173ebad84a5cf1a130832486aa007741bee70a506b8fa94b22a1fd6a37436a49f7c0e105076
6
+ metadata.gz: e5fafe5b9c03bd69c37ee0240d9c4fd86210ed3e20ae55d089be998c809e3cd1e5d445077ee8d7d939ce3307ddb2c760479166d997f4d0f271808f0c3e62e738
7
+ data.tar.gz: 4e130d6639c97c4afb210477289bdde0be6bbce0f1ca15df2e24199ab51e947c94b82f11452782ea9dbc03b32bbf115f58bac4d72dc1dcb32633200dfc513940
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Change log
2
2
 
3
+ ## [0.1.4]
4
+ Add an abillity to skip the piwik dd prefix, refactoring
5
+
3
6
  ## [0.1.3]
4
7
  Update missing Gemfile.lock
5
8
 
data/Gemfile.lock CHANGED
@@ -1,23 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- device_detector_regexes (0.1.2)
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
- Specify the folder that will contain the mapped device_detector [regexes folder](https://github.com/podigee/device_detector/tree/develop/regexes)
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
- DeviceDetectorRegexes.config.dir = "path/to/my/folder/name"
27
+ DeviceDetector.configure do |config|
28
+ config.dir = "path/to/your/custom/folder"
29
+ end
34
30
  ```
35
31
 
36
- Voila! Just add new regexes to the appropriate file
32
+ Add new regexes to the appropriate file
37
33
 
38
34
  ```yaml
39
- # my_folder_name/regexes/client/mobile_apps.yml
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"
@@ -27,6 +27,4 @@ Gem::Specification.new do |spec|
27
27
  spec.require_paths = ["lib"]
28
28
 
29
29
  spec.add_dependency "device_detector"
30
- spec.add_dependency "dry-configurable"
31
- spec.add_dependency "rake"
32
30
  end
@@ -1,11 +1,45 @@
1
1
  require "device_detector"
2
- require "dry/configurable"
3
2
 
4
- Gem.find_files('device_detector_regexes/*.rb').each { |path| require path }
3
+ module DeviceDetectorRegexes; end
5
4
 
6
- module DeviceDetectorRegexes
5
+ class DeviceDetector
6
+ class << self
7
+ class Configuration
8
+ def dir
9
+ @dir || Dir.pwd
10
+ end
7
11
 
8
- extend Dry::Configurable
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
- setting(:dir, Dir.pwd) { |dir| Pathname(dir) }
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
@@ -1,3 +1,3 @@
1
1
  module DeviceDetectorRegexes
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  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.3
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-15 00:00:00.000000000 Z
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/parser.rb
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