Class: GALoader
- Inherits:
-
Object
- Object
- GALoader
- Defined in:
- lib/ga_loader.rb
Overview
Class Method Summary collapse
-
.findFile(extension) ⇒ Object
Returns the first file with the given extension.
-
.findProject ⇒ Object
Returns a possible project, in case one is not provided in the configuration.
-
.findWorkspace ⇒ Object
Returns a possible workspace, in case one is not provided in the configuration.
-
.getFileFromArray(files) ⇒ Object
Returns a filename from a given array.
-
.outputConfiguration(configuration) ⇒ Object
Outputs a given configuration on the console.
-
.outputSampleConfiguration(eventuallyAbort = false) ⇒ Object
Outputs a sample configuration to let the user know how to create a valid one.
-
.readConfiguration(silent = false) ⇒ Object
Reads the configuration from the file guardian_angel.json.
-
.validateConfiguration(configuration) ⇒ Object
Validates a given configuration.
Class Method Details
.findFile(extension) ⇒ Object
Returns the first file with the given extension
49 50 51 52 53 54 |
# File 'lib/ga_loader.rb', line 49 def self.findFile(extension) files = Dir.glob("*.#{extension}") return nil if files.empty? return File.basename(files.first, ".*") end |
.findProject ⇒ Object
this searches only in the top level directory
Returns a possible project, in case one is not provided in the configuration
41 42 43 |
# File 'lib/ga_loader.rb', line 41 def self.findProject return findFile("xcodeproj") end |
.findWorkspace ⇒ Object
this searches only in the top level directory
Returns a possible workspace, in case one is not provided in the configuration
34 35 36 |
# File 'lib/ga_loader.rb', line 34 def self.findWorkspace return findFile("xcworkspace") end |
.getFileFromArray(files) ⇒ Object
the method will take the last element of the array
the method will take only the filename if the element of the array is a file, removing the extension and the path
Returns a filename from a given array
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/ga_loader.rb', line 134 def self.getFileFromArray(files) fileToTest = files.first if fileToTest.nil? GALogger.log('Failed to get file', :Error) abort else return File.basename(fileToTest, ".*") end end |
.outputConfiguration(configuration) ⇒ Object
Outputs a given configuration on the console
124 125 126 |
# File 'lib/ga_loader.rb', line 124 def self.outputConfiguration(configuration) GALogger.log(configuration.to_s, :Default, '') end |
.outputSampleConfiguration(eventuallyAbort = false) ⇒ Object
Outputs a sample configuration to let the user know how to create a valid one
(see #GAConfiguration)
114 115 116 117 118 119 |
# File 'lib/ga_loader.rb', line 114 def self.outputSampleConfiguration(eventuallyAbort = false) GALogger.log('Sample configuration JSON: ' + GAConfiguration.sample.to_s, :Warning, '') if eventuallyAbort abort end end |
.readConfiguration(silent = false) ⇒ Object
if the file is not found, it will try to build with default values instead
this also outputs the final GAConfiguration built on the console
Reads the configuration from the file guardian_angel.json
(see #GAConfiguration)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ga_loader.rb', line 14 def self.readConfiguration(silent = false) configuration = GAConfiguration.new begin jsonDictionary = JSON.parse(File.read(CONFIG_FILENAME)) configurationMerge = GAConfiguration.new(jsonDictionary) configuration = configuration.merge(configurationMerge) rescue GALogger.log("#{CONFIG_FILENAME} not found or not a valid JSON, using defaults", :Warning) unless silent end validateConfiguration(configuration) outputConfiguration(configuration) unless silent return configuration end |
.validateConfiguration(configuration) ⇒ Object
required attribute is workspace/project
if scheme is not specified, the same as the workspace/project will be used
if target is not specified, ‘workspace|projectTests’ will be used
the method will also make sure that the configured xctool executable can be found, or aborts otherwise
Validates a given configuration
63 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ga_loader.rb', line 63 def self.validateConfiguration(configuration) if configuration.workspace.nil? possibleWorkspace = findWorkspace() if !possibleWorkspace possibleProject = configuration.project if possibleProject.nil? possibleProject = findProject() if !possibleProject GALogger.log("workspace or project was not specified and cannot be found, exiting", :Error) outputSampleConfiguration(eventuallyAbort = true) end end configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationProject => possibleProject) else configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationWorkspace => possibleWorkspace) end configuration = configuration.merge(configurationMerge) end if configuration.scheme.nil? unless configuration.project.nil? configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationScheme => configuration.project) end unless configuration.workspace.nil? configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationScheme => configuration.workspace) end configuration = configuration.merge(configurationMerge) end if configuration.target.nil? configurationMerge = GAConfiguration.new(GAConfiguration::GAConfigurationTarget => configuration.scheme + 'Tests') configuration = configuration.merge(configurationMerge) end xctoolExists = system("which #{configuration.xctool_path} > /dev/null") if !xctoolExists GALogger.log(configuration.xctool_path + " can't be found. Aborting.", :Error) abort end end |