browserino 4.1.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +19 -0
- data/.gitignore +2 -0
- data/.rspec +1 -1
- data/.rubocop.yml +10 -4
- data/.travis.yml +3 -2
- data/browserino.gemspec +4 -2
- data/lib/browserino/client.rb +89 -120
- data/lib/browserino/config.rb +20 -24
- data/lib/browserino/definitions/aliasses.rb +13 -8
- data/lib/browserino/definitions/filters.rb +40 -26
- data/lib/browserino/definitions/labels.rb +36 -35
- data/lib/browserino/definitions/matchers/bots.rb +208 -0
- data/lib/browserino/definitions/matchers/browsers.rb +377 -0
- data/lib/browserino/definitions/matchers/emails.rb +22 -0
- data/lib/browserino/definitions/matchers/global.rb +52 -0
- data/lib/browserino/definitions/matchers/libraries.rb +16 -0
- data/lib/browserino/definitions/matchers/mediaplayers.rb +12 -0
- data/lib/browserino/definitions/matchers/rss.rb +46 -0
- data/lib/browserino/definitions/matchers/validators.rb +37 -0
- data/lib/browserino/definitions/matchers.rb +7 -555
- data/lib/browserino/matcher.rb +5 -5
- data/lib/browserino/methods.rb +18 -17
- data/lib/browserino/options.rb +8 -0
- data/lib/browserino/version.rb +4 -4
- metadata +34 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2d30f42c7e1a63c8e19cbad7586428a031131b3
|
4
|
+
data.tar.gz: b42852889bef245e914e0f7e595ba0901461bfeb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e723963f0ec847654a3fa638cb11b8d660f62062a2be94eef57b05c30b9c8585456b3eef02002d46b536e8d743f2a9c4f4b34b39572692c9a29394c7d8ec9b2
|
7
|
+
data.tar.gz: 02be67d0b2ff279028a0596f077bf684c401bde84e1316422d535580b9e57818d6e01e2863a1466c85288347983af9082b1dc45990de33ea0fcc3cc083ab6833
|
data/.codeclimate.yml
ADDED
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--format
|
1
|
+
--format progress
|
2
2
|
--color
|
data/.rubocop.yml
CHANGED
@@ -1,12 +1,18 @@
|
|
1
1
|
AllCops:
|
2
2
|
Exclude:
|
3
|
-
- 'spec
|
3
|
+
- 'spec/**/*'
|
4
4
|
- 'Guardfile'
|
5
5
|
- '*.gemspec'
|
6
6
|
- 'Rakefile'
|
7
7
|
- 'tmp/**/*'
|
8
8
|
- 'vendor/**/*'
|
9
9
|
|
10
|
+
Style/ExtraSpacing:
|
11
|
+
Enabled: true
|
12
|
+
|
13
|
+
SpaceAroundOperators:
|
14
|
+
Enabled: false
|
15
|
+
|
10
16
|
Documentation:
|
11
17
|
Enabled: false
|
12
18
|
|
@@ -26,12 +32,12 @@ Metrics/BlockLength:
|
|
26
32
|
Enabled: false
|
27
33
|
|
28
34
|
Metrics/AbcSize:
|
29
|
-
Max:
|
35
|
+
Max: 15
|
30
36
|
|
31
37
|
Metrics/ClassLength:
|
32
38
|
CountComments: false
|
33
|
-
Max:
|
39
|
+
Max: 150
|
34
40
|
|
35
41
|
Metrics/MethodLength:
|
36
42
|
CountComments: false
|
37
|
-
Max:
|
43
|
+
Max: 10
|
data/.travis.yml
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
sudo: false
|
2
|
-
cache: bundler
|
3
2
|
language: ruby
|
3
|
+
cache: bundler
|
4
4
|
rvm:
|
5
5
|
- 2.0.0
|
6
6
|
- 2.1.0
|
7
7
|
- 2.2.0
|
8
8
|
- 2.3.0
|
9
9
|
- 2.4.0
|
10
|
-
before_install: gem
|
10
|
+
before_install: gem update bundler
|
11
11
|
script:
|
12
12
|
- bundle exec rspec spec
|
13
|
+
- bundle exec codeclimate-test-reporter
|
13
14
|
- bundle exec rubocop
|
data/browserino.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'browserino/version'
|
@@ -17,10 +18,11 @@ Gem::Specification.new do |spec|
|
|
17
18
|
spec.executables = ['browserino']
|
18
19
|
spec.require_paths = ["lib"]
|
19
20
|
|
20
|
-
spec.add_development_dependency "bundler"
|
21
|
-
spec.add_development_dependency "rake"
|
21
|
+
spec.add_development_dependency "bundler"
|
22
|
+
spec.add_development_dependency "rake"
|
22
23
|
spec.add_development_dependency "rspec"
|
23
24
|
spec.add_development_dependency "rubocop"
|
24
25
|
spec.add_development_dependency "coveralls"
|
25
26
|
spec.add_development_dependency "pry"
|
27
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
26
28
|
end
|
data/lib/browserino/client.rb
CHANGED
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
module Browserino
|
4
4
|
class Client
|
5
|
-
attr_reader :property_names
|
6
|
-
|
7
5
|
def initialize(props = {}, like = nil)
|
8
6
|
@property_names = props.keys
|
9
7
|
@like = like
|
@@ -12,28 +10,16 @@ module Browserino
|
|
12
10
|
# order below. First, seperate static value methods from procs,
|
13
11
|
# procs will be able to call methods in this instances' context
|
14
12
|
# therefore we need to define static methods before procs
|
13
|
+
generate_preset_methods! props
|
15
14
|
|
16
|
-
# for each
|
17
|
-
# -- define a method that returns it's property value
|
18
|
-
# -- define a question method that returns it's property value or
|
19
|
-
# checks version against supplied value if truthy
|
20
|
-
define_simple_methods! props
|
21
|
-
|
22
|
-
# for each proc property:
|
23
|
-
# -- define a method that returns it's instance evalled block value
|
24
|
-
# -- define a question method that returns it's instance evalled block
|
25
|
-
# value or checks version against supplied value if truthy
|
26
|
-
define_proc_methods! props
|
27
|
-
|
28
|
-
# for each of #name, #engine and #platform, use their results as
|
15
|
+
# for each of #name, #engine, #platform and #device use their results as
|
29
16
|
# methods names, this will create a method #firefox? for the output
|
30
17
|
# of a #name # => :firefox for example.
|
31
|
-
|
32
|
-
|
33
|
-
#
|
34
|
-
|
35
|
-
|
36
|
-
define_label_methods!
|
18
|
+
# NOTE: labels do not have to be added, they will be extracted
|
19
|
+
# and inserted by this method, this method will also add aliasses
|
20
|
+
# of all the names as methods.
|
21
|
+
generate_result_methods! props, :name, :engine, :platform, :device
|
22
|
+
generate_proc_methods! props
|
37
23
|
end
|
38
24
|
|
39
25
|
def properties
|
@@ -46,43 +32,40 @@ module Browserino
|
|
46
32
|
@like ||= self
|
47
33
|
end
|
48
34
|
|
49
|
-
def like?(sym
|
50
|
-
|
51
|
-
must = []
|
52
|
-
must << like.is?(sym) if sym
|
53
|
-
must << like.version?(opts[:version]) if opts[:version]
|
54
|
-
|
55
|
-
must.any? && must.all?
|
35
|
+
def like?(sym, opts = {})
|
36
|
+
invertable like.is?(sym, opts)
|
56
37
|
end
|
57
38
|
|
58
39
|
def x64?
|
59
|
-
@
|
40
|
+
invertable(@x64 ||= architecture == :x64)
|
60
41
|
end
|
61
42
|
|
62
43
|
def x32?
|
63
|
-
@
|
44
|
+
invertable(@x32 ||= architecture == :x32)
|
64
45
|
end
|
65
46
|
|
66
47
|
def arm?
|
67
|
-
@
|
48
|
+
invertable(@arm ||= architecture == :arm)
|
49
|
+
end
|
50
|
+
|
51
|
+
def is?(sm, opts = {})
|
52
|
+
return invertable send("#{sm}?", opts[:version]) if opts && opts[:version]
|
53
|
+
invertable send("#{sm}?")
|
68
54
|
end
|
69
55
|
|
70
|
-
|
71
|
-
|
72
|
-
def is?(sym, opts = {})
|
73
|
-
return send "#{sym}?", opts[:version] if opts[:version]
|
74
|
-
send "#{sym}?"
|
56
|
+
def not?(sym, opts = {})
|
57
|
+
!is? sym, opts
|
75
58
|
end
|
76
59
|
|
77
60
|
def ===(other)
|
78
|
-
return false unless name
|
61
|
+
return invertable false unless name
|
79
62
|
|
80
|
-
case other
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
63
|
+
invertable case other
|
64
|
+
when Regexp then other =~ name
|
65
|
+
when String then other.to_sym == name
|
66
|
+
when Symbol, Client then other == name
|
67
|
+
else false
|
68
|
+
end
|
86
69
|
end
|
87
70
|
|
88
71
|
def ==(other)
|
@@ -98,21 +81,22 @@ module Browserino
|
|
98
81
|
end
|
99
82
|
|
100
83
|
def to_json(*args)
|
101
|
-
@
|
102
|
-
|
103
|
-
|
104
|
-
end.to_h.to_json(*args)
|
84
|
+
@json ||= properties.each_with_object({}) do |(prop, val), hsh|
|
85
|
+
hsh[prop] = val.is_a?(Version) && val.full || val
|
86
|
+
end.to_json(*args)
|
105
87
|
end
|
106
88
|
|
107
|
-
def
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
a = l ? l : [n, (v.major if v > '0.0.0')].join.to_sym
|
89
|
+
def label_or_version_name(prop)
|
90
|
+
ver = version_for prop
|
91
|
+
label_for(prop) || ver && [properties[prop].to_s.strip,
|
92
|
+
(ver.major if ver > '0.0.0')].join.strip
|
93
|
+
end
|
113
94
|
|
114
|
-
|
115
|
-
|
95
|
+
def to_s
|
96
|
+
@str ||= %i[name engine platform device].each_with_object([]) do |prop, a|
|
97
|
+
a << properties[prop].to_s.strip
|
98
|
+
a << label_or_version_name(prop)
|
99
|
+
end.compact.reject(&:empty?).uniq.join ' '
|
116
100
|
end
|
117
101
|
|
118
102
|
def to_hash
|
@@ -130,7 +114,7 @@ module Browserino
|
|
130
114
|
# scary, I know, but a falsy value is all we need to return if some
|
131
115
|
# property isn't known or true as any property can be defined on the Client
|
132
116
|
def method_missing(_, *__, &___)
|
133
|
-
nil
|
117
|
+
invertable nil
|
134
118
|
end
|
135
119
|
|
136
120
|
# always respond to missing, read method_missing comment
|
@@ -138,96 +122,81 @@ module Browserino
|
|
138
122
|
true
|
139
123
|
end
|
140
124
|
|
125
|
+
# if you wish for a method to respond to the #not method,
|
126
|
+
# you'll have to return the result of a function using the `invertable`
|
127
|
+
# method as seen in `method_missing` - this will apply the state of the
|
128
|
+
# instance variable and invert the state aswell as the result if set,
|
129
|
+
# otherwise it will just return the value without touching it
|
130
|
+
def not
|
131
|
+
@not = true && self
|
132
|
+
end
|
133
|
+
|
141
134
|
private
|
142
135
|
|
143
|
-
def
|
144
|
-
|
145
|
-
properties[mtd]
|
136
|
+
def invertable(result)
|
137
|
+
@not ? @not = false || !result : result
|
146
138
|
end
|
147
139
|
|
148
|
-
def label_for(sym)
|
149
|
-
|
150
|
-
|
140
|
+
def label_for(sym, from = properties)
|
141
|
+
return from[:label] if %i[version label name].include? sym
|
142
|
+
from["#{sym}_label".to_sym]
|
151
143
|
end
|
152
144
|
|
153
|
-
def
|
154
|
-
|
155
|
-
|
145
|
+
def name_for(sym, from = properties)
|
146
|
+
return from[:name] if %i[version label name].include? sym
|
147
|
+
from["#{sym}_name".to_sym]
|
156
148
|
end
|
157
149
|
|
158
|
-
def
|
159
|
-
|
160
|
-
|
161
|
-
ver && incl ? version_for(mtd) == ver : incl
|
150
|
+
def version_for(sym, from = properties)
|
151
|
+
return from[:version] if %i[version label name].include? sym
|
152
|
+
from["#{sym}_version".to_sym]
|
162
153
|
end
|
163
154
|
|
164
|
-
def
|
155
|
+
def generate_preset_methods!(props)
|
165
156
|
props.each do |name, value|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
val = val.to_sym if ver
|
175
|
-
get_answer name, value, ver, val
|
157
|
+
methods = [name, *Browserino.config.aliasses[name]]
|
158
|
+
methods.each do |mtd|
|
159
|
+
define_singleton_method(mtd) { value }
|
160
|
+
define_singleton_method("#{mtd}?") do |val = nil|
|
161
|
+
return value == val if val
|
162
|
+
value && true
|
163
|
+
end
|
164
|
+
end
|
176
165
|
end
|
177
166
|
end
|
178
167
|
|
179
|
-
def
|
168
|
+
def generate_proc_methods!(props)
|
180
169
|
props.select { |_, val| val.respond_to? :call }.each do |name, value|
|
181
170
|
result = instance_eval(&value)
|
182
|
-
define_singleton_method(name)
|
171
|
+
define_singleton_method(name) { invertable result }
|
172
|
+
define_singleton_method("#{name}?") { invertable result && true }
|
183
173
|
end
|
184
174
|
end
|
185
175
|
|
186
|
-
def
|
187
|
-
|
188
|
-
|
189
|
-
ver_res = version_for(prop)
|
176
|
+
def generate_result_methods!(info, *property_names)
|
177
|
+
property_names.each do |prop|
|
178
|
+
ver_res = version_for prop, info
|
190
179
|
|
191
|
-
|
192
|
-
|
193
|
-
# (ex: name # => firefox # => "firefox?")
|
194
|
-
# -- when supplied with a value, check it against {prop_res}_version
|
195
|
-
# -- when called without argument, return result
|
196
|
-
define_singleton_method("#{result}?") do |value = nil|
|
197
|
-
return ver_res == value if value
|
198
|
-
result && true
|
199
|
-
end
|
200
|
-
|
201
|
-
# for each of the aliasses found:
|
202
|
-
# -- define a question method using the current alias
|
203
|
-
# -- when supplied with a value, check it against {prop_res}_version
|
204
|
-
# -- when called without argument, return result
|
205
|
-
Browserino.config.aliasses[result].each do |alt|
|
206
|
-
define_singleton_method("#{alt}?") do |value = nil|
|
207
|
-
return ver_res == value if value
|
208
|
-
result && true
|
209
|
-
end
|
210
|
-
end
|
180
|
+
create_question! info[prop], version: ver_res, aliasses: true
|
181
|
+
create_question! label_for(prop, info), version: ver_res, aliasses: true
|
211
182
|
end
|
212
183
|
end
|
213
184
|
|
214
|
-
def
|
215
|
-
|
216
|
-
|
217
|
-
ver_res = version_for(prop.to_s.split('_').first)
|
185
|
+
def create_question!(result, opts = {})
|
186
|
+
methods = [result]
|
187
|
+
methods += Browserino.config.aliasses[result] if opts[:aliasses]
|
218
188
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
end
|
223
|
-
|
224
|
-
Browserino.config.aliasses[result].each do |alt|
|
225
|
-
define_singleton_method("#{alt}?") do |value = nil|
|
226
|
-
return ver_res == value if value
|
227
|
-
result && true
|
228
|
-
end
|
189
|
+
methods.each do |mtd|
|
190
|
+
define_singleton_method("#{mtd}?") do |val = nil|
|
191
|
+
invertable(val ? opts[:version] == val : true)
|
229
192
|
end
|
230
193
|
end
|
231
194
|
end
|
195
|
+
|
196
|
+
def get_answer(mtd, res, ver = nil, val = nil)
|
197
|
+
return res.is_a?(Version) ? res > '0.0.0' : res && true unless val
|
198
|
+
incl = res == val
|
199
|
+
ver && incl ? version_for(mtd) == ver : incl
|
200
|
+
end
|
232
201
|
end
|
233
202
|
end
|
data/lib/browserino/config.rb
CHANGED
@@ -4,16 +4,9 @@ module Browserino
|
|
4
4
|
class Config < Options
|
5
5
|
def define(&block)
|
6
6
|
instance_eval(&block)
|
7
|
-
|
8
|
-
|
9
|
-
properties << matcher.properties.keys
|
10
|
-
types << matcher.type
|
11
|
-
names << matcher.name
|
7
|
+
matchers.each_with_object types do |mtch, types_arr|
|
8
|
+
types_arr << mtch.type unless types_arr.include?(mtch.type)
|
12
9
|
end
|
13
|
-
|
14
|
-
properties.flatten!.uniq!
|
15
|
-
types.uniq!
|
16
|
-
names.uniq!
|
17
10
|
end
|
18
11
|
|
19
12
|
def label(name, **opts)
|
@@ -32,11 +25,6 @@ module Browserino
|
|
32
25
|
end
|
33
26
|
|
34
27
|
def match(rgxp = nil, **opts, &block)
|
35
|
-
if rgxp.is_a? Hash
|
36
|
-
opts = rgxp.dup
|
37
|
-
rgxp = nil
|
38
|
-
end
|
39
|
-
|
40
28
|
opts = @tmp_defaults.merge opts if @tmp_defaults.is_a? Hash
|
41
29
|
|
42
30
|
if rgxp && opts[:like]
|
@@ -69,28 +57,36 @@ module Browserino
|
|
69
57
|
@tmp_defaults = @preset_store.last
|
70
58
|
end
|
71
59
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
60
|
+
# the order of these methods is the same as seen at the top of the
|
61
|
+
# definitions/matchers.rb file. It is the current "order" required
|
62
|
+
# for Browserino to work properly, maybe tweaking some regexes can lighten
|
63
|
+
# this up but it's OK for now.
|
76
64
|
def emails(opts = {}, &block)
|
77
65
|
preset opts.merge(type: :email), &block
|
78
66
|
end
|
79
67
|
|
80
|
-
def validators(opts = {}, &block)
|
81
|
-
preset opts.merge(type: :validator), &block
|
82
|
-
end
|
83
|
-
|
84
68
|
def browsers(opts = {}, &block)
|
85
69
|
preset opts.merge(type: :browser), &block
|
86
70
|
end
|
87
71
|
|
72
|
+
def like(tmp, opts = {}, &block)
|
73
|
+
preset opts.merge(like: tmp.to_sym), &block
|
74
|
+
end
|
75
|
+
|
76
|
+
def rss(opts = {}, &block)
|
77
|
+
preset opts.merge(type: :rss), &block
|
78
|
+
end
|
79
|
+
|
88
80
|
def bots(opts = {}, &block)
|
89
|
-
preset opts.merge(type: :bot), &block
|
81
|
+
preset opts.merge(type: :bot, text: true), &block
|
82
|
+
end
|
83
|
+
|
84
|
+
def validators(opts = {}, &block)
|
85
|
+
preset opts.merge(type: :validator, text: true), &block
|
90
86
|
end
|
91
87
|
|
92
88
|
def libraries(opts = {}, &block)
|
93
|
-
preset opts.merge(type: :library), &block
|
89
|
+
preset opts.merge(type: :library, text: true), &block
|
94
90
|
end
|
95
91
|
|
96
92
|
def with_alias(pattern, **opts, &block)
|