Skip to content

Commit e45da11

Browse files
committed
* Fix rubocop warnings
* Bump Ruby to 2.6 as 2.5 is EOL
1 parent e10ed1d commit e45da11

19 files changed

+82
-80
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
gemfile: [websocket-driver-0.6.x, websocket-driver-0.7.x]
16-
ruby: [2.5, 2.6, 2.7, 3.0]
16+
ruby: [2.6, 2.7, 3.0]
1717

1818
runs-on: ubuntu-latest
1919
env:

.rubocop.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
inherit_from: .rubocop_todo.yml
22

33
AllCops:
4-
TargetRubyVersion: 2.5
4+
TargetRubyVersion: 2.6
55
NewCops: enable
66

77
Layout/FirstArrayElementIndentation:
@@ -16,13 +16,19 @@ Metrics/BlockLength:
1616
- "*.gemspec"
1717

1818
Naming/MethodParameterName:
19+
MinNameLength: 2
1920
AllowedNames:
2021
- x
2122
- y
22-
- id
23-
- to
24-
- on
2523

2624
Naming/FileName:
2725
Exclude:
28-
- 'gemfiles/websocket-driver-*.gemfile'
26+
- 'gemfiles/*.gemfile'
27+
28+
Style/MultilineBlockChain:
29+
Exclude:
30+
- spec/**/*
31+
32+
Metrics/ModuleLength:
33+
Exclude:
34+
- spec/**/*

.rubocop_todo.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ Metrics/ModuleLength:
3636
Metrics/PerceivedComplexity:
3737
Max: 14
3838

39-
# Offense count: 2
40-
# Cop supports --auto-correct.
41-
# Configuration parameters: Keywords.
42-
# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW
43-
Style/CommentAnnotation:
44-
Exclude:
45-
- 'spec/node_spec.rb'
46-
4739
# Offense count: 45
4840
Style/Documentation:
4941
Enabled: false

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -858,9 +858,10 @@ browser.add_script_tag(url: "http://example.com/stylesheet.css") # => true
858858
browser.add_style_tag(content: "h1 { font-size: 40px; }") # => true
859859

860860
```
861-
#### bypass_csp(enabled) : `Boolean`
861+
#### bypass_csp(\*\*options) : `Boolean`
862862

863-
* enabled `Boolean`, `true` by default
863+
* options `Hash`
864+
* :enabled `Boolean`, `true` by default
864865

865866
```ruby
866867
browser.bypass_csp # => true
@@ -1001,7 +1002,7 @@ browser.go_to("https://www.w3schools.com/tags/tag_frame.asp")
10011002
browser.main_frame.doctype # => "<!DOCTYPE html>"
10021003
```
10031004

1004-
#### set_content(html)
1005+
#### content = html
10051006

10061007
Sets a content of a given frame.
10071008

@@ -1011,7 +1012,7 @@ Sets a content of a given frame.
10111012
browser.go_to("https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe")
10121013
frame = browser.frames[1]
10131014
frame.body # <html lang="en"><head><style>body {transition: opacity ease-in 0.2s; }...
1014-
frame.set_content("<html><head></head><body><p>lol</p></body></html>")
1015+
frame.content = "<html><head></head><body><p>lol</p></body></html>"
10151016
frame.body # => <html><head></head><body><p>lol</p></body></html>
10161017
```
10171018

ferrum.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Gem::Specification.new do |s|
2525
"source_code_uri" => "https://github.com/rubycdp/ferrum"
2626
}
2727

28-
s.required_ruby_version = ">= 2.5.0"
28+
s.required_ruby_version = ">= 2.6.0"
2929

3030
s.add_runtime_dependency "addressable", "~> 2.5"
3131
s.add_runtime_dependency "cliver", "~> 0.3"

lib/ferrum/browser.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Browser
2020
delegate %i[targets create_target page pages windows] => :default_context
2121
delegate %i[go_to back forward refresh reload stop wait_for_reload
2222
at_css at_xpath css xpath current_url current_title url title
23-
body doctype set_content
23+
body doctype content=
2424
headers cookies network
2525
mouse keyboard
2626
screenshot pdf mhtml viewport_size

lib/ferrum/browser/process.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def initialize(options)
6767
if options[:url]
6868
url = URI.join(options[:url].to_s, "/json/version")
6969
response = JSON.parse(::Net::HTTP.get(url))
70-
set_ws_url(response["webSocketDebuggerUrl"])
70+
self.ws_url = response["webSocketDebuggerUrl"]
7171
parse_browser_versions
7272
return
7373
end
@@ -142,22 +142,22 @@ def parse_ws_url(read_io, timeout)
142142
begin
143143
output += read_io.read_nonblock(512)
144144
rescue IO::WaitReadable
145-
IO.select([read_io], nil, nil, max_time - now)
145+
read_io.wait_readable(max_time - now)
146146
else
147147
if output.match(regexp)
148-
set_ws_url(output.match(regexp)[1].strip)
148+
self.ws_url = output.match(regexp)[1].strip
149149
break
150150
end
151151
end
152152
end
153153

154-
unless ws_url
155-
@logger&.puts(output)
156-
raise ProcessTimeoutError.new(timeout, output)
157-
end
154+
return if ws_url
155+
156+
@logger&.puts(output)
157+
raise ProcessTimeoutError.new(timeout, output)
158158
end
159159

160-
def set_ws_url(url)
160+
def ws_url=(url)
161161
@ws_url = Addressable::URI.parse(url)
162162
@host = @ws_url.host
163163
@port = @ws_url.port

lib/ferrum/frame.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,15 @@ def main?
4242
@parent_id.nil?
4343
end
4444

45-
def set_content(html)
45+
def content=(html)
4646
evaluate_async(%(
4747
document.open();
4848
document.write(arguments[0]);
4949
document.close();
5050
arguments[1](true);
5151
), @page.timeout, html)
5252
end
53+
alias set_content content=
5354

5455
def execution_id?(execution_id)
5556
@execution_id == execution_id

lib/ferrum/frame/runtime.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,7 @@ def handle_response(response)
181181
Node.new(self, @page.target_id, node_id, description)
182182
when "array"
183183
reduce_props(object_id, []) do |memo, key, value|
184-
next(memo) unless begin
185-
Integer(key)
186-
rescue StandardError
187-
nil
188-
end
184+
next(memo) unless Integer(key, exception: false)
189185

190186
value = value["objectId"] ? handle_response(value) : value["value"]
191187
memo.insert(key.to_i, value)

lib/ferrum/keyboard.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,19 +77,19 @@ def normalize_keys(keys, pressed_keys = [], memo = [])
7777
pressed_keys.last.push(key)
7878
nil
7979
else
80-
_key = KEYS.fetch(KEYS_MAPPING[key.to_sym] || key.to_sym)
81-
_key[:modifiers] = pressed_keys.flatten.map { |k| MODIFIERS[k] }.reduce(0, :|)
82-
to_options(_key)
80+
key = KEYS.fetch(KEYS_MAPPING[key.to_sym] || key.to_sym)
81+
key[:modifiers] = pressed_keys.flatten.map { |k| MODIFIERS[k] }.reduce(0, :|)
82+
to_options(key)
8383
end
8484
when String
8585
pressed = pressed_keys.flatten
8686
keys.each_char.map do |char|
87+
key = KEYS[char] || {}
88+
8789
if pressed.empty?
88-
key = KEYS[char] || {}
8990
key = key.merge(text: char, unmodifiedText: char)
9091
[to_options(key)]
9192
else
92-
key = KEYS[char] || {}
9393
text = pressed == ["shift"] ? char.upcase : char
9494
key = key.merge(
9595
text: text,

0 commit comments

Comments
 (0)