Class: RubyNative::CLI::Screenshots

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_native/cli/screenshots.rb

Constant Summary collapse

STORAGE_DIR =
".ruby_native"
STORAGE_FILE =
"screenshots_storage.json"
OUTPUT_DIR =
".ruby_native/screenshots"
CONFIG_PATH =
"config/ruby_native.yml"
SCALE =
3
WIDTH_PX =
1320
HEIGHT_PX =
2868
WIDTH_PT =

440

WIDTH_PX / SCALE
HEIGHT_PT =

956

HEIGHT_PX / SCALE
HOST =
ENV.fetch("RUBY_NATIVE_HOST", "https://rubynative.com")

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Screenshots

Returns a new instance of Screenshots.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ruby_native/cli/screenshots.rb', line 24

def initialize(argv)
  @url = parse_option(argv, "--url", nil)
  @port = parse_option(argv, "--port", nil)
  @output = parse_option(argv, "--output", OUTPUT_DIR)
  @login = argv.delete("--login")

  if @url
    unless @url.match?(%r{\Ahttps?://})
      host = @url.split(":", 2).first
      scheme = (host == "localhost" || host.match?(/\A\d+\.\d+\.\d+\.\d+\z/)) ? "http" : "https"
      @url = "#{scheme}://#{@url}"
    end
    @url = @url.chomp("/")
    @port = URI(@url).port if @port.nil?
  else
    @port = (@port || 3000).to_i
  end
end

Instance Method Details

#runObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/ruby_native/cli/screenshots.rb', line 43

def run
  load_config!
  check_node!
  check_playwright!

  if @login
    
  else
    run_setup unless screenshots_configured?
    check_server!
    capture_screenshots
    upload_screenshots if credentials_available?
  end
end