Class: Mdq::DB
Overview
DB
Instance Method Summary collapse
-
#app_install(input, udid, is_replace) ⇒ Object
Appをインストールする.
-
#app_uninstall(input, udid) ⇒ Object
Appをアンインストールする.
-
#device_screencap(output, udid = nil) ⇒ Object
Androidデバイスのスクリーンショットを撮る.
-
#get(is_android: true, is_apple: true, is_apps: true) ⇒ Object
デバイスとアプリの取得.
-
#query(sql) ⇒ Object
クエリの実行.
-
#query_contains_apps_table?(query) ⇒ Boolean
クエリにappsテーブルが含まれているかを判定する.
- #sim_screencap(output, is_android: true) ⇒ Object
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をインストールする
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/mdq/db.rb', line 81 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をアンインストールする
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mdq/db.rb', line 103 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 = nil) ⇒ Object
Androidデバイスのスクリーンショットを撮る
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mdq/db.rb', line 39 def device_screencap(output, udid = nil) devices = if udid.nil? Device.where(physical: true) else Device .where('udid LIKE ?', "#{udid}%") .where(physical: true) end if devices.empty? warn 'Device not found.' return end FileUtils.mkdir_p(output) devices.each do |device| file = "#{device.udid}-#{Time.now.strftime('%y%m%d-%H%M%S')}.png" if device.android? full_path = "/sdcard/#{file}" adb_command("shell screencap -p #{full_path}", device.udid) adb_command("pull #{full_path} #{output}", device.udid) adb_command("shell rm #{full_path}", device.udid) else apple_command("device capture screenshot --destination #{output}/#{file}", device.udid) end end end |
#get(is_android: true, is_apple: true, is_apps: true) ⇒ Object
デバイスとアプリの取得
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mdq/db.rb', line 13 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
クエリの実行
32 33 34 35 36 |
# File 'lib/mdq/db.rb', line 32 def query(sql) ActiveRecord::Base.connection.execute(sql) rescue StandardError => e raise e end |
#query_contains_apps_table?(query) ⇒ Boolean
クエリにappsテーブルが含まれているかを判定する
121 122 123 124 125 126 127 |
# File 'lib/mdq/db.rb', line 121 def query_contains_apps_table?(query) parser = SQLParser::Parser.new ast = parser.scan_str(query) find_tables(ast).uniq.include?('apps') rescue StandardError false end |
#sim_screencap(output, is_android: true) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mdq/db.rb', line 69 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 |