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.
-
#devices ⇒ Array
List of simulators to use.
-
#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.
Constructor Details
#initialize(path = nil) ⇒ SnapshotConfig
Returns a new instance of SnapshotConfig.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/snapshot/snapshot_config.rb', line 56 def initialize(path = nil) DependencyChecker.check_simulators path ||= './Snapfile' set_defaults if File.exists?path Helper.log.info "Using '#{path}'".green 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.
47 48 49 |
# File 'lib/snapshot/snapshot_config.rb', line 47 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 |
#devices ⇒ Array
Returns List of simulators to use.
8 9 10 |
# File 'lib/snapshot/snapshot_config.rb', line 8 def devices @devices 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
51 52 53 |
# File 'lib/snapshot/snapshot_config.rb', line 51 def self.shared_instance(path = nil) @@instance ||= SnapshotConfig.new(path) end |
Instance Method Details
#js_file(ipad = false) ⇒ Object
The JavaScript UIAutomation file
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/snapshot/snapshot_config.rb', line 148 def js_file(ipad = false) 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
134 135 136 137 138 |
# File 'lib/snapshot/snapshot_config.rb', line 134 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
143 144 145 |
# File 'lib/snapshot/snapshot_config.rb', line 143 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)
173 174 175 176 177 178 179 180 181 182 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 |
# File 'lib/snapshot/snapshot_config.rb', line 173 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 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 => 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)
108 109 110 111 112 113 114 115 |
# File 'lib/snapshot/snapshot_config.rb', line 108 def set_default_simulators 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)" ] end |
#set_defaults ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/snapshot/snapshot_config.rb', line 79 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 } end |
#verify_devices ⇒ Object
This method takes care of appending the iOS version to the simulator name
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/snapshot/snapshot_config.rb', line 118 def verify_devices self.set_default_simulators actual_devices = [] self.devices.each do |current| current += " (#{self.ios_version} Simulator)" unless current.include?"Simulator" unless Simulators.available_devices.include?current raise "Device '#{current}' not found. Available device types: #{Simulators.available_devices}".red else actual_devices << current end end self.devices = actual_devices end |