Class: Dryrun::DryrunUtils

Inherits:
Object
  • Object
show all
Defined in:
lib/dryrun/dryrun_utils.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#deviceObject

Returns the value of attribute device.



8
9
10
# File 'lib/dryrun/dryrun_utils.rb', line 8

def device
  @device
end

#sdkObject

Returns the value of attribute sdk.



7
8
9
# File 'lib/dryrun/dryrun_utils.rb', line 7

def sdk
  @sdk
end

Class Method Details

.execute(command) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/dryrun/dryrun_utils.rb', line 10

def self.execute(command)
  is_success = system command
  unless is_success
    puts "\n\n======================================================\n\n"
    puts ' Something went wrong while executing this:'.red
    puts "  $ #{command}\n".yellow
    puts "======================================================\n\n"
    exit 1
  end
end

.is_folder?(path) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/dryrun/dryrun_utils.rb', line 49

def self.is_folder? (path)
  File.directory?(path)
end

.latest_versionObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/dryrun/dryrun_utils.rb', line 21

def self.latest_version
  url = 'https://raw.githubusercontent.com/cesarferreira/dryrun/master/lib/dryrun/version.rb'
  page_string = nil

  if Gem.win_platform?
    open(url, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE) do |f|
      page_string = f.read
    end
  else
    open(url) do |f|
      page_string = f.read
    end
  end

  page_string[/#{Regexp.escape('\'')}(.*?)#{Regexp.escape('\'')}/m, 1]
end

.run(path) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/dryrun/dryrun_utils.rb', line 53

def self.run(path)
  Open3.popen3(path) do |_stdin, stdout, _stderr|
    devices = []
    stdout.each do |line|
      line = line.strip
      if !line.empty? && line !~ /^List of devices/ && !line.start_with?('adb') && !line.start_with?('*')
        parts = line.split
        devices << Dryrun::Device.new(parts[0], parts[1])
      end
    end
    devices
  end
end

.run_adb(args) ⇒ Object

:yields: stdout



43
44
45
46
47
# File 'lib/dryrun/dryrun_utils.rb', line 43

def self.run_adb(args) # :yields: stdout
  adb_arg = " -s #{$device.name} " unless $device.nil?
  path = "#{$sdk} #{adb_arg} #{args} "
  run(path)
end

.up_to_dateObject



38
39
40
41
# File 'lib/dryrun/dryrun_utils.rb', line 38

def self.up_to_date
  latest = latest_version
  latest.to_s <= Dryrun::VERSION.to_s
end