8
8
# Load appium.txt (toml format) into system ENV
9
9
# the basedir of this file + appium.txt is what's used
10
10
# @param opts [Hash] file: '/path/to/appium.txt', verbose: true
11
- # @return [nil]
11
+ # @return [Array<String>] the require files. nil if require doesn't exist
12
12
def load_appium_txt opts
13
13
raise 'opts must be a hash' unless opts . kind_of? Hash
14
14
opts . each_pair { |k , v | opts [ k . to_s . downcase . strip . intern ] = v }
@@ -17,7 +17,8 @@ def load_appium_txt opts
17
17
raise 'Must pass file' unless file
18
18
verbose = opts . fetch :verbose , false
19
19
# Check for env vars in .txt
20
- toml = File . expand_path File . join File . dirname ( file ) , 'appium.txt'
20
+ parent_dir = File . dirname file
21
+ toml = File . expand_path File . join parent_dir , 'appium.txt'
21
22
puts "appium.txt path: #{ toml } " if verbose
22
23
# @private
23
24
def update data , *args
@@ -29,6 +30,7 @@ def update data, *args
29
30
30
31
toml_exists = File . exists? toml
31
32
puts "Exists? #{ toml_exists } " if verbose
33
+ data = nil
32
34
33
35
if toml_exists
34
36
require 'toml'
@@ -39,9 +41,14 @@ def update data, *args
39
41
# toml requires A = "OK"
40
42
#
41
43
# A="OK" => A = "OK"
42
- data = File . read ( toml ) . gsub /([^\s ])\= (")/ , "\\ 1 = \\ 2"
44
+ data = File . read toml
45
+
46
+ data = data . split ( "\n " ) . map do |line |
47
+ line . sub /([^\s ])\= / , "\\ 1 = "
48
+ end . join "\n "
49
+
43
50
data = TOML ::Parser . new ( data ) . parsed
44
- ap data unless data . empty?
51
+ ap data unless data . empty? if verbose
45
52
46
53
update data , 'APP_PATH' , 'APP_APK' , 'APP_PACKAGE' ,
47
54
'APP_ACTIVITY' , 'APP_WAIT_ACTIVITY' ,
@@ -50,7 +57,19 @@ def update data, *args
50
57
# Ensure app path is absolute
51
58
ENV [ 'APP_PATH' ] = File . expand_path ENV [ 'APP_PATH' ] if ENV [ 'APP_PATH' ]
52
59
end
53
- nil
60
+
61
+ # return list of require files as an array
62
+ # nil if require doesn't exist
63
+ if data && data [ 'require' ]
64
+ r = data [ 'require' ]
65
+ r = r . kind_of? ( Array ) ? r : [ r ]
66
+ # ensure files are absolute
67
+ r . map! do |file |
68
+ file = file . include? ( File ::Separator ) ? file :
69
+ File . join ( parent_dir , file )
70
+ File . expand_path file
71
+ end
72
+ end
54
73
end
55
74
56
75
module Appium
@@ -209,6 +228,22 @@ def initialize opts={}
209
228
end # def initialize
210
229
211
230
# Returns the status payload
231
+ #
232
+ # ```ruby
233
+ # {"status"=>0,
234
+ # "value"=>
235
+ # {"build"=>
236
+ # {"version"=>"0.8.2",
237
+ # "revision"=>"f2a2bc3782e4b0370d97a097d7e04913cf008995"}},
238
+ # "sessionId"=>"8f4b34a7-a9a9-4ac5-b125-36258143446a"}
239
+ # ```
240
+ #
241
+ # Discover the Appium rev running on the server.
242
+ #
243
+ # `status["value"]["build"]["revision"]`
244
+ # `f2a2bc3782e4b0370d97a097d7e04913cf008995`
245
+ #
246
+ # @return [JSON]
212
247
def status
213
248
driver . status . payload
214
249
end
0 commit comments