Class: Snapshot::SnapshotConfig
- Inherits:
-
Object
- Object
- Snapshot::SnapshotConfig
- Defined in:
- lib/snapshot/snapshot_config.rb
Instance Attribute Summary collapse
-
#build_command ⇒ String
The build command, wich should build the app to ‘/tmp/snapshot’.
-
#devices ⇒ Array
List of simulators to use.
-
#html_path ⇒ String
The path, in which the HTML file should be exported to.
-
#ios_version ⇒ String
The iOS version (e.g. 8.1).
-
#languages ⇒ Array
A list of languages which should be used.
-
#manual_js_file ⇒ String
The path to the JavaScript file to use.
-
#manual_scheme ⇒ String
The name of a scheme, manually set by the user using the config file.
-
#project_path ⇒ String
The path to the project/workspace.
-
#screenshots_path ⇒ String
The path, in which the screenshots should be stored.
- #snapshot_file ⇒ SnapshotFile
Class Method Summary collapse
-
.shared_instance ⇒ Object
A shared singleton.
Instance Method Summary collapse
-
#initialize(path = './Snapfile') ⇒ SnapshotConfig
constructor
A new instance of SnapshotConfig.
-
#js_file ⇒ Object
The JavaScript UIAutomation file.
-
#project_name ⇒ Object
Returns the file name of the project.
-
#scheme ⇒ Object
The scheme to use (either it’s set, or there is only one, or user has to enter it).
- #set_defaults ⇒ Object
Constructor Details
#initialize(path = './Snapfile') ⇒ SnapshotConfig
Returns a new instance of SnapshotConfig.
41 42 43 44 45 46 47 48 49 |
# File 'lib/snapshot/snapshot_config.rb', line 41 def initialize(path = './Snapfile') set_defaults if path and File.exists?path self.snapshot_file = SnapshotFile.new(path, self) else Helper.log.error "Could not find './Snapfile'. It is recommended to create a file using 'snapshot init' into the current directory. Using the defaults now." end end |
Instance Attribute Details
#build_command ⇒ String
Returns The build command, wich should build the app to ‘/tmp/snapshot’.
32 33 34 |
# File 'lib/snapshot/snapshot_config.rb', line 32 def build_command @build_command end |
#devices ⇒ Array
Returns List of simulators to use.
8 9 10 |
# File 'lib/snapshot/snapshot_config.rb', line 8 def devices @devices end |
#html_path ⇒ String
Returns The path, in which the HTML file should be exported to.
29 30 31 |
# File 'lib/snapshot/snapshot_config.rb', line 29 def html_path @html_path end |
#ios_version ⇒ String
Returns The iOS version (e.g. 8.1).
14 15 16 |
# File 'lib/snapshot/snapshot_config.rb', line 14 def ios_version @ios_version end |
#languages ⇒ Array
Returns A list of languages which should be used.
11 12 13 |
# File 'lib/snapshot/snapshot_config.rb', line 11 def languages @languages end |
#manual_js_file ⇒ String
Returns The path to the JavaScript file to use.
23 24 25 |
# File 'lib/snapshot/snapshot_config.rb', line 23 def manual_js_file @manual_js_file end |
#manual_scheme ⇒ String
Returns The name of a scheme, manually set by the user using the config file.
20 21 22 |
# File 'lib/snapshot/snapshot_config.rb', line 20 def manual_scheme @manual_scheme end |
#project_path ⇒ String
Returns The path to the project/workspace.
17 18 19 |
# File 'lib/snapshot/snapshot_config.rb', line 17 def project_path @project_path end |
#screenshots_path ⇒ String
Returns The path, in which the screenshots should be stored.
26 27 28 |
# File 'lib/snapshot/snapshot_config.rb', line 26 def screenshots_path @screenshots_path end |
#snapshot_file ⇒ SnapshotFile
5 6 7 |
# File 'lib/snapshot/snapshot_config.rb', line 5 def snapshot_file @snapshot_file end |
Class Method Details
.shared_instance ⇒ Object
A shared singleton
36 37 38 |
# File 'lib/snapshot/snapshot_config.rb', line 36 def self.shared_instance @@instance ||= SnapshotConfig.new end |
Instance Method Details
#js_file ⇒ Object
The JavaScript UIAutomation file
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/snapshot/snapshot_config.rb', line 82 def js_file return manual_js_file if manual_js_file files = Dir.glob("./*.js").delete_if { |path| path.include?"SnapshotHelper.js" } if files.count == 1 return files.first else raise "Could not determine which UIAutomation file to use. Please pass a path to your Javascript file using 'js_file'.".red end end |
#project_name ⇒ Object
Returns the file name of the project
77 78 79 |
# File 'lib/snapshot/snapshot_config.rb', line 77 def project_name (self.project_path.split('/').last.split('.').first rescue nil) end |
#scheme ⇒ Object
The scheme to use (either it’s set, or there is only one, or user has to enter it)
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/snapshot/snapshot_config.rb', line 94 def scheme begin command = "cd '#{project_path.split('/')[0..-2].join('/')}'; xcodebuild -list" schemes = `#{command}`.split("Schemes:").last.split("\n").each { |a| a.strip! }.delete_if { |a| a == '' } Helper.log.debug "Found available schemes: #{schemes}" self.manual_scheme = schemes.first if schemes.count == 1 if self.manual_scheme if not schemes.include?manual_scheme raise "Could not find requested scheme '#{self.manual_scheme}' in Xcode's schemes #{schemes}" else return self.manual_scheme end else # We have to ask the user first puts "Found the following schemes in your project:".green puts "You can use 'scheme \"Name\"' in your Snapfile".green puts "--------------------------------------------".green while not schemes.include?self.manual_scheme schemes.each_with_index do |current, index| puts "#{index + 1}) #{current}" end val = gets.strip.to_i if val > 0 self.manual_scheme = (schemes[val - 1] rescue nil) end end return self.manual_scheme end rescue Exception => ex raise "Could not fetch available schemes: #{ex}".red end end |
#set_defaults ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/snapshot/snapshot_config.rb', line 51 def set_defaults self.ios_version = '8.1' self.devices = [ "iPhone 6 (#{self.ios_version} Simulator)", "iPhone 6 Plus (#{self.ios_version} Simulator)", "iPhone 5 (#{self.ios_version} Simulator)", "iPhone 4s (#{self.ios_version} Simulator)" ] self.languages = [ 'de-DE', 'en-US' ] self.screenshots_path = './screenshots' self.project_path = (Dir.glob("./*.xcworkspace").first rescue nil) # prefer workspaces ofc self.project_path ||= (Dir.glob("./*.xcodeproj").first rescue nil) self.html_path = './screenshots.html' end |