mdq 1.4.0 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa40709c2f0dca1610281b05d743cc6676126dd22e0c9ea8ee2a8b6719f97bdd
4
- data.tar.gz: ced38027b22c1265d03b635f2530cb79972b8abaf786fcb00228bd59c77d379f
3
+ metadata.gz: e82ce9d717037c9e6cb77fb68ebc07fbef2d3d1863b9bd9a0e5acde1b4f1ed65
4
+ data.tar.gz: b88aadd8b8a20ae0a3dc75e0902a29eed5b2c2b79ac00eef4d33161be6203519
5
5
  SHA512:
6
- metadata.gz: ce4c1cf1a3c96117646be0faac76fcec33e7e43b4badbf04ba7e5bf6dfbc5b9e058614934b51f34b19ec66f5b3fe9d501a91b5296d523d45e8df8b964cb020ea
7
- data.tar.gz: 37a99b2f330e2dd227ccb500e038d9d5d28af8c2305a4405b7580b5c230829e50716dba9c7d2b18aa510212ab167572d57da92bb1719919eea2806f597663fef
6
+ metadata.gz: 410d82e49b9464a9da80fe3be11090e4433135565defeedd7f7ba6b3a3a58067188960fed97116945a30e982cfa80252c82cf6e6c97b65797eab0d0d607d61cf
7
+ data.tar.gz: 3ceffaccda4efa440a2f1a50ea1d91608a4be64b357eb2928c78a45d7fb782241463a61841e7674b160ed1186f5bac3f5d18285467b86904f7629e49a0eb1267
data/lib/mdq/cli.rb CHANGED
@@ -29,9 +29,17 @@ module Mdq
29
29
  type: :boolean
30
30
  method_option :apple, desc: 'Show Apple devices', default: true,
31
31
  type: :boolean
32
+ method_option :physical, desc: 'Show physical devices', default: true,
33
+ type: :boolean
34
+ method_option :simulated, desc: 'Show simulated devices', default: true,
35
+ type: :boolean
32
36
  def devices
33
37
  db = Mdq::DB.new
34
- db.get(is_android: options[:android], is_apple: options[:apple], is_apps: false)
38
+ db.get(is_android: options[:android],
39
+ is_apple: options[:apple],
40
+ is_apps: false,
41
+ is_physical: options[:physical],
42
+ is_simulated: options[:simulated])
35
43
  puts(JSON.pretty_generate(Device.all.as_json))
36
44
  end
37
45
 
@@ -54,9 +62,15 @@ module Mdq
54
62
  method_option :query, desc: 'SQL to filter devices or apps', aliases: '-q', required: true
55
63
  def list
56
64
  db = Mdq::DB.new
57
- db.get(is_android: options[:android], is_apple: options[:apple])
58
- result = db.query(options['query'])
59
- puts(JSON.pretty_generate(result.as_json))
65
+ is_apps = db.query_contains_apps_table?(options[:query])
66
+ db.get(is_android: options[:android], is_apple: options[:apple], is_apps: is_apps)
67
+
68
+ begin
69
+ result = db.query(options['query'])
70
+ puts(JSON.pretty_generate(result.as_json))
71
+ rescue StandardError => e
72
+ warn e.message
73
+ end
60
74
  end
61
75
 
62
76
  desc 'cap', 'Path to save screenshots of the physical device.'
data/lib/mdq/db.rb CHANGED
@@ -3,17 +3,18 @@
3
3
  require 'mdq'
4
4
  require 'active_record'
5
5
  require 'fileutils'
6
+ require 'sql-parser'
6
7
 
7
8
  # Mdq
8
9
  module Mdq
9
10
  # DB
10
11
  class DB < Discovery
11
12
  # デバイスとアプリの取得
12
- def get(is_android: true, is_apple: true, is_apps: true)
13
+ def get(is_android: true, is_apple: true, is_apps: true, is_physical: true, is_simulated: true)
13
14
  reset
14
15
  # デバイスの発見
15
- android_discover if is_android
16
- apple_discover if is_apple
16
+ android_discover(is_physical) if is_android
17
+ apple_discover(is_physical, is_simulated) if is_apple
17
18
 
18
19
  return unless is_apps
19
20
 
@@ -30,8 +31,8 @@ module Mdq
30
31
  # クエリの実行
31
32
  def query(sql)
32
33
  ActiveRecord::Base.connection.execute(sql)
33
- rescue StandardError
34
- []
34
+ rescue StandardError => e
35
+ raise e
35
36
  end
36
37
 
37
38
  # Androidデバイスのスクリーンショットを撮る
@@ -115,5 +116,31 @@ module Mdq
115
116
  puts output unless output.empty?
116
117
  warn error unless error.empty?
117
118
  end
119
+
120
+ # クエリにappsテーブルが含まれているかを判定する
121
+ def query_contains_apps_table?(query)
122
+ parser = SQLParser::Parser.new
123
+ ast = parser.scan_str(query)
124
+ find_tables(ast).uniq.include?('apps')
125
+ rescue StandardError
126
+ false
127
+ end
128
+
129
+ private
130
+
131
+ def find_tables(node)
132
+ tables = []
133
+ if node.is_a?(SQLParser::Statement::Table)
134
+ tables << node.name
135
+ elsif node.respond_to?(:each)
136
+ node.each { |child| tables += find_tables(child) }
137
+ elsif node.instance_variables.any?
138
+ node.instance_variables.each do |var|
139
+ val = node.instance_variable_get(var)
140
+ tables += find_tables(val)
141
+ end
142
+ end
143
+ tables
144
+ end
118
145
  end
119
146
  end
data/lib/mdq/discovery.rb CHANGED
@@ -64,7 +64,9 @@ module Mdq
64
64
  end
65
65
 
66
66
  # Androidデバイス一覧を取得する
67
- def android_discover # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
67
+ def android_discover(is_physical = true) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Style/OptionalBooleanParameter
68
+ return if skip_device?(true, is_physical, false)
69
+
68
70
  output, = adb_command('devices -l')
69
71
  return if output.nil?
70
72
 
@@ -171,7 +173,7 @@ module Mdq
171
173
  end
172
174
 
173
175
  # Appleデバイス一覧を取得する
174
- def apple_discover
176
+ def apple_discover(is_physical = true, is_simulated = true) # rubocop:disable Style/OptionalBooleanParameter
175
177
  file = [@home, 'mdq.json'].join(File::Separator)
176
178
  result = apple_command("list devices -v -j #{file}")
177
179
  k = 1000.0
@@ -193,6 +195,8 @@ module Mdq
193
195
  reality == 'physical'
194
196
  end
195
197
 
198
+ next if skip_device?(physical, is_physical, is_simulated)
199
+
196
200
  Device.create({
197
201
  udid: udid,
198
202
  serial_number: device['hardwareProperties']['serialNumber'],
@@ -268,6 +272,14 @@ module Mdq
268
272
 
269
273
  "#{(size * 100).round / 100.0}#{units[i]}"
270
274
  end
275
+
276
+ # デバイスの物理/シミュレートのフラグをスキップするかどうか
277
+ # 物理デバイスの場合: is_physical が true ならスキップしない(false)、false ならスキップする(true)。
278
+ # シミュレータの場合: is_simulated が true ならスキップしない(false)、false ならスキップする(true)。
279
+ # 判定不能(nil)の場合: シミュレータとして扱い、is_simulated の設定に従う。
280
+ def skip_device?(physical, is_physical, is_simulated)
281
+ !((physical && is_physical) || (!physical && is_simulated))
282
+ end
271
283
  end
272
284
  end
273
285
 
data/lib/mdq/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mdq
4
- VERSION = '1.4.0'
4
+ VERSION = '1.5.1'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mdq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - arthur87
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2026-06-16 00:00:00.000000000 Z
10
+ date: 2026-06-20 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: rubocop
@@ -51,6 +51,20 @@ dependencies:
51
51
  - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: sql-parser
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
54
68
  - !ruby/object:Gem::Dependency
55
69
  name: thor
56
70
  requirement: !ruby/object:Gem::Requirement