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 ‘/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.
-
#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 ⇒ 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_defaults ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ SnapshotConfig
Returns a new instance of SnapshotConfig.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/snapshot/snapshot_config.rb', line 47 def initialize(path = nil) path ||= './Snapfile' set_defaults if path and File.exists?path self.snapshot_file = SnapshotFile.new(path, self) else if path != './Snapfile' raise "Could not find Snapfile at path '#{path}'. Make sure you pass the full path, including 'Snapfile'".red 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.".red end end load_env end |
Instance Attribute Details
#blocks ⇒ Hash
Returns All the blocks, which are called on specific actions.
38 39 40 |
# File 'lib/snapshot/snapshot_config.rb', line 38 def blocks @blocks end |
#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 |
#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
42 43 44 |
# File 'lib/snapshot/snapshot_config.rb', line 42 def self.shared_instance(path = nil) @@instance ||= SnapshotConfig.new(path) end |
Instance Method Details
#js_file ⇒ Object
The JavaScript UIAutomation file
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/snapshot/snapshot_config.rb', line 109 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 |
#load_env ⇒ Object
95 96 97 98 99 |
# File 'lib/snapshot/snapshot_config.rb', line 95 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
104 105 106 |
# File 'lib/snapshot/snapshot_config.rb', line 104 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)
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/snapshot/snapshot_config.rb', line 121 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
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/snapshot/snapshot_config.rb', line 64 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' empty = Proc.new {} self.blocks = { setup_for_device_change: empty, teardown_device: empty, setup_for_language_change: empty, teardown_language: empty } end |