Class: Mdq::DB

Inherits:
Discovery show all
Defined in:
lib/mdq/db.rb

Overview

DB

Instance Method Summary collapse

Methods inherited from Discovery

#android_discoverable?, #apple_discoverable?, #initialize

Constructor Details

This class inherits a constructor from Mdq::Discovery

Instance Method Details

#app_install(input, udid, is_replace) ⇒ Object

Appをインストールする



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/mdq/db.rb', line 65

def app_install(input, udid, is_replace)
  device = Device.find_by(udid: udid)
  if device.nil?
    warn 'Device not found.'
    return
  end

  if device.android?
    if is_replace
      output, error = adb_command("install -r #{input}", udid)
    else
      output, error = adb_command("install #{input}", udid)
    end
  else
    output, error = apple_command("device install app #{input}", udid)
  end

  puts output unless output.empty?
  warn error unless error.empty?
end

#app_uninstall(input, udid) ⇒ Object

Appをアンインストールする



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/mdq/db.rb', line 87

def app_uninstall(input, udid)
  device = Device.find_by(udid: udid)
  if device.nil?
    warn 'Device not found.'
    return
  end

  if device.android?
    output, error = adb_command("uninstall #{input}", udid)
  else
    output, error = apple_command("device uninstall app #{input}", udid)
  end

  puts output unless output.empty?
  warn error unless error.empty?
end

#device_screencap(output, udid) ⇒ Object

Androidデバイスのスクリーンショットを撮る



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mdq/db.rb', line 38

def device_screencap(output, udid)
  device = Device.find_by(udid: udid)
  if device.nil? || !device.android?
    warn 'Device not found or not an Android device.'
    return
  end

  FileUtils.mkdir_p(output)
  file = "#{udid}-#{Time.now.strftime('%y%m%d-%H%M%S')}.png"
  full_path = "/sdcard/#{file}"
  adb_command("shell screencap -p #{full_path}", udid)
  adb_command("pull #{full_path} #{output}", udid)
  adb_command("shell rm #{full_path}", udid)
end

#get(is_android: true, is_apple: true, is_apps: true) ⇒ Object

デバイスとアプリの取得



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/mdq/db.rb', line 12

def get(is_android: true, is_apple: true, is_apps: true)
  reset
  # デバイスの発見
  android_discover if is_android
  apple_discover if is_apple

  return unless is_apps

  Device.all.each do |model|
    # インストール済みAppの取得
    if model.android?
      android_apps(model.udid)
    else
      apple_apps(model.udid)
    end
  end
end

#query(sql) ⇒ Object

クエリの実行



31
32
33
34
35
# File 'lib/mdq/db.rb', line 31

def query(sql)
  ActiveRecord::Base.connection.execute(sql)
rescue StandardError
  []
end

#sim_screencap(output, is_android: true) ⇒ Object



53
54
55
56
57
58
59
60
61
62
# File 'lib/mdq/db.rb', line 53

def sim_screencap(output, is_android: true)
  if is_android
    output, error = adb_command("emu screenrecord #{output}}")
  else
    output, error = apple_sim_command("io booted screenshot #{output}")
  end

  puts output unless output.empty?
  warn error unless error.empty?
end