Skip to content

Commit 9d27ae0

Browse files
authored
Merge pull request #265 from rubycdp/cliver
Get rid of Cliver
2 parents cdca4a1 + 2a173ac commit 9d27ae0

20 files changed

+173
-31
lines changed

.github/gemfiles/websocket-driver-0.6.x.gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
source "https://rubygems.org"
44

55
gem "websocket-driver", "~> 0.6.5"
6-
gem "cliver", github: "route/cliver", branch: "develop"
76

87
gemspec path: "../../"

.github/gemfiles/websocket-driver-0.7.x.gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
source "https://rubygems.org"
44

55
gem "websocket-driver", "~> 0.7.1"
6-
gem "cliver", github: "route/cliver", branch: "develop"
76

87
gemspec path: "../../"

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
gemfile: [websocket-driver-0.6.x, websocket-driver-0.7.x]
15-
ruby: [2.6, 2.7, 3.0]
15+
ruby: [2.7, 3.0, 3.1]
1616
runs-on: ubuntu-latest
1717
env:
1818
FERRUM_PROCESS_TIMEOUT: 20

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
AllCops:
2-
TargetRubyVersion: 2.6
2+
TargetRubyVersion: 2.7
33
NewCops: enable
44

55
Layout/FirstArrayElementIndentation:

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ a block with this page, after which the page is closed.
2828
### Changed
2929

3030
- Use `Concurrent::MVar` as `execution_id` in `Ferrum::Frame`
31-
- Min Ruby version is 2.6 and 3.0 is supported
31+
- Min Ruby version >= 2.7
3232
- `Ferrum::Page#bypass_csp` accepts hash as argument `enabled: true` by default
3333
- `Ferrum::Context#has_target?` -> `Ferrum::Context#target?`
3434
- We now start looking for Chrome first instead of Chromium, the order for checking binaries has changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,6 @@ Returns bitfield for a given keys
731731

732732
Returns cookies hash
733733

734-
735734
```ruby
736735
browser.cookies.all # => {"NID"=>#<Ferrum::Cookies::Cookie:0x0000558624b37a40 @attributes={"name"=>"NID", "value"=>"...", "domain"=>".google.com", "path"=>"/", "expires"=>1583211046.575681, "size"=>178, "httpOnly"=>true, "secure"=>false, "session"=>false}>}
737736
```

ferrum.gemspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ Gem::Specification.new do |s|
2323
"rubygems_mfa_required" => "true"
2424
}
2525

26-
s.required_ruby_version = ">= 2.6.0"
26+
s.required_ruby_version = ">= 2.7.0"
2727

2828
s.add_runtime_dependency "addressable", "~> 2.5"
29-
s.add_runtime_dependency "cliver", "~> 0.3"
3029
s.add_runtime_dependency "concurrent-ruby", "~> 1.1"
3130
s.add_runtime_dependency "webrick", "~> 1.7"
3231
s.add_runtime_dependency "websocket-driver", ">= 0.6", "< 0.8"

lib/ferrum/browser.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
require "ferrum/browser/xvfb"
99
require "ferrum/browser/process"
1010
require "ferrum/browser/client"
11+
require "ferrum/browser/binary"
1112

1213
module Ferrum
1314
class Browser
@@ -18,7 +19,7 @@ class Browser
1819
extend Forwardable
1920
delegate %i[default_context] => :contexts
2021
delegate %i[targets create_target page pages windows] => :default_context
21-
delegate %i[go_to back forward refresh reload stop wait_for_reload
22+
delegate %i[go_to goto go back forward refresh reload stop wait_for_reload
2223
at_css at_xpath css xpath current_url current_title url title
2324
body doctype content=
2425
headers cookies network
@@ -27,7 +28,7 @@ class Browser
2728
frames frame_by main_frame
2829
evaluate evaluate_on evaluate_async execute evaluate_func
2930
add_script_tag add_style_tag bypass_csp
30-
on goto position position=
31+
on position position=
3132
playback_rate playback_rate=] => :page
3233
delegate %i[default_user_agent] => :process
3334

lib/ferrum/browser/binary.rb

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
module Ferrum
4+
class Browser
5+
module Binary
6+
module_function
7+
8+
def find(commands)
9+
enum(commands).first
10+
end
11+
12+
def all(commands)
13+
enum(commands).force
14+
end
15+
16+
def enum(commands)
17+
paths, exts = prepare_paths
18+
cmds = Array(commands).product(paths, exts)
19+
lazy_find(cmds)
20+
end
21+
22+
def prepare_paths
23+
exts = (ENV.key?("PATHEXT") ? ENV.fetch("PATHEXT").split(";") : []) << ""
24+
paths = ENV["PATH"].split(File::PATH_SEPARATOR)
25+
raise EmptyPathError if paths.empty?
26+
27+
[paths, exts]
28+
end
29+
30+
def lazy_find(cmds)
31+
cmds.lazy.filter_map do |cmd, path, ext|
32+
cmd = File.expand_path("#{cmd}#{ext}", path) unless File.absolute_path?(cmd)
33+
34+
next unless File.executable?(cmd)
35+
next if File.directory?(cmd)
36+
37+
cmd
38+
end
39+
end
40+
end
41+
end
42+
end

lib/ferrum/browser/command.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def initialize(defaults, options, user_data_dir)
3030
@options = options
3131
@user_data_dir = user_data_dir
3232
@path = options[:browser_path] || ENV.fetch("BROWSER_PATH", nil) || defaults.detect_path
33-
raise Cliver::Dependency::NotFound, NOT_FOUND unless @path
33+
raise BinaryNotFoundError, NOT_FOUND unless @path
3434

3535
merge_options
3636
end

0 commit comments

Comments
 (0)