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_android) ⇒ Object

Appをインストールする



52
53
54
55
56
57
# File 'lib/mdq/db.rb', line 52

def app_install(input, udid, is_android)
  output, = adb_command("install #{input}", udid) if is_android && input.end_with?('.apk')
  output, = apple_command("device install app #{input}", udid) if !is_android && input.end_with?('.ipa')

  { command: 'install', udid: udid, result: output }
end

#app_uninstall(input, udid, is_android) ⇒ Object

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



60
61
62
63
64
65
66
67
68
# File 'lib/mdq/db.rb', line 60

def app_uninstall(input, udid, is_android)
  if is_android
    output, = adb_command("uninstall #{input}", udid)
  else
    output, = apple_command("device uninstall app #{input}", udid)
  end

  { command: 'uninstall', udid: udid, result: output }
end

#device_screencap(output, udid, is_android) ⇒ Object

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



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

def device_screencap(output, udid, is_android)
  return unless is_android

  FileUtils.mkdir_p(output)
  file = "/sdcard/#{udid}.png"
  adb_command("shell screencap -p #{file}", udid)
  adb_command("pull #{file} #{output}", udid)
  adb_command("adb shell rm #{file}")

  { command: 'cap', udid: udid, result: nil }
end

#get(sql) ⇒ Object

クエリの実行



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/mdq/db.rb', line 12

def get(sql)
  reset
  # デバイスの発見
  android_discover
  apple_discover

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

    begin
      ActiveRecord::Base.connection.execute(sql)
    rescue StandardError => e
      { result: e }
    end
  else
    Device.all
  end
end