Skip to content

Commit 8733383

Browse files
committed
Get rid of Cliver
1 parent cdca4a1 commit 8733383

File tree

17 files changed

+169
-27
lines changed

17 files changed

+169
-27
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: "../../"

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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ Gem::Specification.new do |s|
2626
s.required_ruby_version = ">= 2.6.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

lib/ferrum/browser/options/base.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,7 @@ def except(*keys)
2424
end
2525

2626
def detect_path
27-
if Utils::Platform.mac?
28-
self.class::MAC_BIN_PATH.find { |n| File.exist?(n) }
29-
elsif Utils::Platform.windows?
30-
self.class::WINDOWS_BIN_PATH.find { |path| File.exist?(path) }
31-
else
32-
self.class::LINUX_BIN_PATH.find do |name|
33-
path = Cliver.detect(name) and break(path)
34-
end
35-
end
27+
Binary.find(self.class::PLATFORM_PATH[Utils::Platform.name])
3628
end
3729

3830
def merge_required(flags, options, user_data_dir)

lib/ferrum/browser/options/chrome.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ class Chrome < Base
5252
"C:/Program Files/Google/Chrome/Application/chrome.exe",
5353
"C:/Program Files/Google/Chrome Dev/Application/chrome.exe"
5454
].freeze
55+
PLATFORM_PATH = {
56+
mac: MAC_BIN_PATH,
57+
windows: WINDOWS_BIN_PATH,
58+
linux: LINUX_BIN_PATH
59+
}.freeze
5560

5661
def merge_required(flags, options, user_data_dir)
5762
port = options.fetch(:port, BROWSER_PORT)

lib/ferrum/browser/options/firefox.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ class Firefox < Base
1616
"C:/Program Files/Firefox Developer Edition/firefox.exe",
1717
"C:/Program Files/Mozilla Firefox/firefox.exe"
1818
].freeze
19+
PLATFORM_PATH = {
20+
mac: MAC_BIN_PATH,
21+
windows: WINDOWS_BIN_PATH,
22+
linux: LINUX_BIN_PATH
23+
}.freeze
1924

2025
def merge_required(flags, options, user_data_dir)
2126
port = options.fetch(:port, BROWSER_PORT)

0 commit comments

Comments
 (0)