Class: Snapshot::SnapshotConfig
- Inherits:
-
Object
- Object
- Snapshot::SnapshotConfig
- Defined in:
- lib/snapshot/snapshot_config.rb
Instance Attribute Summary collapse
-
#blocks ⇒ Hash
All the blocks, which are called on specific actions.
-
#build_command ⇒ String
The build command, wich should build the app to build_dir (/tmp/snapshot by default).
-
#build_dir ⇒ String
The build directory, defaults to ‘/tmp/snapshot’.
-
#clear_previous_screenshots ⇒ BOOL
Clear previously generated screenshots before creating new ones.
-
#custom_args ⇒ String
This will be prepended before the actual build command.
-
#custom_build_args ⇒ String
This will be appended to the actual build command.
-
#custom_run_args ⇒ String
This will be appended to the run command.
-
#devices ⇒ Array
List of simulators to use.
-
#html_title ⇒ Object
Returns the value of attribute html_title.
-
#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.
-
#skip_alpha_removal ⇒ BOOL
Skip the removal of the alpha channel from the screenshots.
- #snapshot_file ⇒ SnapshotFile
Class Method Summary collapse
-
.shared_instance(path = nil) ⇒ Object
A shared singleton.
Instance Method Summary collapse
-
#initialize(path = nil) ⇒ SnapshotConfig
constructor
A new instance of SnapshotConfig.
-
#js_file(ipad = false) ⇒ Object
The JavaScript UIAutomation file.
- #load_env ⇒ Object
-
#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_default_simulators ⇒ Object
This has to be done after parsing the Snapfile (iOS version).
- #set_defaults ⇒ Object
-
#verify_devices ⇒ Object
This method takes care of appending the iOS version to the simulator name.
- #version_suffix(version) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ SnapshotConfig
Returns a new instance of SnapshotConfig.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/snapshot/snapshot_config.rb', line 61 def initialize(path = nil) DependencyChecker.check_simulators path ||= './Snapfile' set_defaults if File.exists?path Helper.log.info "Using '#{path}'".green if $verbose self.snapshot_file = SnapshotFile.new(path, self) self.verify_devices else if path != './Snapfile' raise "Could not find Snapfile at path '#{path}'. Make sure you pass the full path, including 'Snapfile'".red else # Using default settings, since user didn't provide a path 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.".red self.verify_devices end end load_env end |
Instance Attribute Details
#blocks ⇒ Hash
Returns All the blocks, which are called on specific actions.
50 51 52 |
# File 'lib/snapshot/snapshot_config.rb', line 50 def blocks @blocks end |
#build_command ⇒ String
Returns The build command, wich should build the app to build_dir (/tmp/snapshot by default).
29 30 31 |
# File 'lib/snapshot/snapshot_config.rb', line 29 def build_command @build_command end |
#build_dir ⇒ String
Returns The build directory, defaults to ‘/tmp/snapshot’.
32 33 34 |
# File 'lib/snapshot/snapshot_config.rb', line 32 def build_dir @build_dir end |
#clear_previous_screenshots ⇒ BOOL
Returns Clear previously generated screenshots before creating new ones.
38 39 40 |
# File 'lib/snapshot/snapshot_config.rb', line 38 def clear_previous_screenshots @clear_previous_screenshots end |
#custom_args ⇒ String
Returns This will be prepended before the actual build command.
41 42 43 |
# File 'lib/snapshot/snapshot_config.rb', line 41 def custom_args @custom_args end |
#custom_build_args ⇒ String
Returns This will be appended to the actual build command.
44 45 46 |
# File 'lib/snapshot/snapshot_config.rb', line 44 def custom_build_args @custom_build_args end |
#custom_run_args ⇒ String
Returns This will be appended to the run command.
47 48 49 |
# File 'lib/snapshot/snapshot_config.rb', line 47 def custom_run_args @custom_run_args 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_title ⇒ Object
Returns the value of attribute html_title.
52 53 54 |
# File 'lib/snapshot/snapshot_config.rb', line 52 def html_title @html_title 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 |
#skip_alpha_removal ⇒ BOOL
Returns Skip the removal of the alpha channel from the screenshots.
35 36 37 |
# File 'lib/snapshot/snapshot_config.rb', line 35 def skip_alpha_removal @skip_alpha_removal 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(path = nil) ⇒ Object
A shared singleton
56 57 58 |
# File 'lib/snapshot/snapshot_config.rb', line 56 def self.shared_instance(path = nil) @@instance ||= SnapshotConfig.new(path) end |
Instance Method Details
#js_file(ipad = false) ⇒ Object
The JavaScript UIAutomation file
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/snapshot/snapshot_config.rb', line 156 def js_file(ipad = false) return ENV["SNAPSHOT_JS_FILE"] if ENV["SNAPSHOT_JS_FILE"] result = manual_js_file unless result files = Dir.glob("./*.js").delete_if { |path| (path.include?"SnapshotHelper.js" or path.include?"iPad.js") } if files.count == 1 result = files.first end end if ipad ipad_file = result.split('.js').join('/') + '-iPad.js' if File.exists?(ipad_file) result = ipad_file end end unless File.exists?(result || '') raise "Could not determine which UIAutomation file to use. Please pass a path to your Javascript file using 'js_file'.".red end return result end |
#load_env ⇒ Object
142 143 144 145 146 |
# File 'lib/snapshot/snapshot_config.rb', line 142 def load_env # Load environment variables self.manual_scheme = ENV["SNAPSHOT_SCHEME"] if ENV["SNAPSHOT_SCHEME"] self.screenshots_path = ENV["SNAPSHOT_SCREENSHOTS_PATH"] if ENV["SNAPSHOT_SCREENSHOTS_PATH"] end |
#project_name ⇒ Object
Returns the file name of the project
151 152 153 |
# File 'lib/snapshot/snapshot_config.rb', line 151 def project_name File.basename(self.project_path, ".*" ) if self.project_path end |
#scheme ⇒ Object
The scheme to use (either it’s set, or there is only one, or user has to enter it)
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/snapshot/snapshot_config.rb', line 183 def scheme begin project_key = 'project' project_key = 'workspace' if project_path.end_with?'.xcworkspace' command = "xcodebuild -#{project_key} '#{project_path}' -list" Helper.log.debug command if $verbose schemes = `#{command}`.split("Schemes:").last.split("\n").each { |a| a.strip! }.delete_if { |a| a == '' } Helper.log.debug "Found available schemes: #{schemes}" if $verbose 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 => ex raise "Could not fetch available schemes: #{ex}".red end end |
#set_default_simulators ⇒ Object
This has to be done after parsing the Snapfile (iOS version)
116 117 118 119 120 121 122 123 |
# File 'lib/snapshot/snapshot_config.rb', line 116 def set_default_simulators self.devices ||= [ "iPhone 6" + version_suffix(self.ios_version), "iPhone 6 Plus" + version_suffix(self.ios_version), "iPhone 5" + version_suffix(self.ios_version), "iPhone 4s" + version_suffix(self.ios_version), ] end |
#set_defaults ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/snapshot/snapshot_config.rb', line 84 def set_defaults self.ios_version = Snapshot::LatestIosVersion.version self.languages = [ 'de-DE', 'en-US' ] self.screenshots_path = './screenshots' folders = ["./*.xcworkspace"] # we prefer workspaces folders << "./*.xcodeproj" folders << "../*.xcworkspace" folders << "../*.xcodeproj" folders.each do |current| self.project_path ||= (File.(Dir[current].first) rescue nil) end empty = Proc.new {} self.blocks = { setup_for_device_change: empty, teardown_device: empty, setup_for_language_change: empty, teardown_language: empty } self.html_title = self.project_name || 'KrauseFx/snapshot' end |
#verify_devices ⇒ Object
This method takes care of appending the iOS version to the simulator name
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/snapshot/snapshot_config.rb', line 126 def verify_devices self.set_default_simulators actual_devices = [] self.devices.each do |current| current += version_suffix(self.ios_version) unless current.include? " (" if Simulators.available_devices.include? current actual_devices << current else raise "Device '#{current}' not found. Available device types: #{Simulators.available_devices}".red end end self.devices = actual_devices end |
#version_suffix(version) ⇒ Object
223 224 225 226 227 228 229 230 231 |
# File 'lib/snapshot/snapshot_config.rb', line 223 def version_suffix version # Xcode 6 and before: "iPhone 5 (8.0 Simulator)" # Xcode 7 and later: "iPhone 6 (9.0)" if LatestIosVersion.version.to_i >= 9 " (#{version})" else " (#{version} Simulator)" end end |