Class: Pod::Validator
- Inherits:
-
Object
- Object
- Pod::Validator
- Includes:
- Config::Mixin
- Defined in:
- lib/cocoapods/validator.rb
Overview
Validates a Specification.
Extends the Linter from the Core to add additional which require the LocalPod and the Installer.
In detail it checks that the file patterns defined by the user match actually do match at least a file and that the Pod builds, by installing it without integration and building the project with xcodebuild.
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#allow_warnings ⇒ Bool
Whether the validator should fail on warnings, or only on errors.
-
#fail_fast ⇒ Bool
Whether the linter should fail as soon as the first build variant causes an error.
-
#file_accessor ⇒ Sandbox::FileAccessor
The file accessor for the spec.
-
#linter ⇒ Specification::Linter
readonly
The linter instance from CocoaPods Core.
-
#local ⇒ Bool
(also: #local?)
Whether the validation should be performed against the root of the podspec instead to its original source.
-
#no_clean ⇒ Bool
Whether the linter should not clean up temporary files for inspection.
-
#no_subspecs ⇒ Bool
Whether the validator should validate all subspecs.
-
#only_subspec ⇒ String
Name of the subspec to check, if nil all subspecs are checked.
-
#quick ⇒ Bool
Whether the validation should skip the checks that requires the download of the library.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#use_frameworks ⇒ Bool
Whether frameworks should be used for the installation.
Instance Method Summary collapse
- #failure_reason ⇒ Object
-
#file ⇒ Pathname
The path of the ‘podspec` file where #spec is defined.
-
#initialize(spec_or_path, source_urls) ⇒ Validator
constructor
Initialize a new instance.
-
#print_results ⇒ void
Prints the result of the validation to the user.
-
#result_color ⇒ Symbol
The color, which should been used to display the result.
-
#result_type ⇒ Symbol
The type, which should been used to display the result.
-
#spec ⇒ Specification
The specification to lint.
- #validate ⇒ Bool
- #validated? ⇒ Boolean
-
#validation_dir ⇒ Pathname
The temporary directory used by the linter.
Methods included from Config::Mixin
Constructor Details
#initialize(spec_or_path, source_urls) ⇒ Validator
Initialize a new instance
30 31 32 33 |
# File 'lib/cocoapods/validator.rb', line 30 def initialize(spec_or_path, source_urls) @source_urls = source_urls.map { |url| SourcesManager.source_with_name_or_url(url) }.map(&:url) @linter = Specification::Linter.new(spec_or_path) end |
Instance Attribute Details
#allow_warnings ⇒ Bool
Returns Whether the validator should fail on warnings, or only on errors.
166 167 168 |
# File 'lib/cocoapods/validator.rb', line 166 def allow_warnings @allow_warnings end |
#fail_fast ⇒ Bool
Returns whether the linter should fail as soon as the first build variant causes an error. Helpful for i.e. multi-platforms specs, specs with subspecs.
154 155 156 |
# File 'lib/cocoapods/validator.rb', line 154 def fail_fast @fail_fast end |
#file_accessor ⇒ Sandbox::FileAccessor
Returns the file accessor for the spec.
52 53 54 |
# File 'lib/cocoapods/validator.rb', line 52 def file_accessor @file_accessor end |
#linter ⇒ Specification::Linter (readonly)
Returns the linter instance from CocoaPods Core.
20 21 22 |
# File 'lib/cocoapods/validator.rb', line 20 def linter @linter end |
#local ⇒ Bool Also known as: local?
Uses the ‘:path` option of the Podfile.
Returns whether the validation should be performed against the root of the podspec instead to its original source.
161 162 163 |
# File 'lib/cocoapods/validator.rb', line 161 def local @local end |
#no_clean ⇒ Bool
Returns whether the linter should not clean up temporary files for inspection.
148 149 150 |
# File 'lib/cocoapods/validator.rb', line 148 def no_clean @no_clean end |
#no_subspecs ⇒ Bool
Returns Whether the validator should validate all subspecs.
174 175 176 |
# File 'lib/cocoapods/validator.rb', line 174 def no_subspecs @no_subspecs end |
#only_subspec ⇒ String
Returns name of the subspec to check, if nil all subspecs are checked.
170 171 172 |
# File 'lib/cocoapods/validator.rb', line 170 def only_subspec @only_subspec end |
#quick ⇒ Bool
Returns whether the validation should skip the checks that requires the download of the library.
143 144 145 |
# File 'lib/cocoapods/validator.rb', line 143 def quick @quick end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
186 187 188 |
# File 'lib/cocoapods/validator.rb', line 186 def results @results end |
#use_frameworks ⇒ Bool
Returns Whether frameworks should be used for the installation.
178 179 180 |
# File 'lib/cocoapods/validator.rb', line 178 def use_frameworks @use_frameworks end |
Instance Method Details
#failure_reason ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cocoapods/validator.rb', line 119 def failure_reason results_by_type = results.group_by(&:type) results_by_type.default = [] return nil if validated? reasons = [] if (size = results_by_type[:error].size) && size > 0 reasons << "#{size} #{'error'.pluralize(size)}" end if !allow_warnings && (size = results_by_type[:warning].size) && size > 0 reason = "#{size} #{'warning'.pluralize(size)}" pronoun = size == 1 ? 'it' : 'them' reason << " (but you can use `--allow-warnings` to ignore #{pronoun})" if reasons.empty? reasons << reason end reasons.to_sentence end |
#file ⇒ Pathname
Returns the path of the ‘podspec` file where #spec is defined.
46 47 48 |
# File 'lib/cocoapods/validator.rb', line 46 def file @linter.file end |
#print_results ⇒ void
This method returns an undefined value.
Prints the result of the validation to the user.
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 114 115 116 117 |
# File 'lib/cocoapods/validator.rb', line 89 def print_results results.each do |result| if result.platforms == [:ios] = '[iOS] ' elsif result.platforms == [:osx] = '[OSX] ' elsif result.platforms == [:watchos] = '[watchOS] ' end = '' if result.is_a?(Result) subspecs = result.subspecs.uniq if subspecs.count > 2 = '[' + subspecs[0..2].join(', ') + ', and more...] ' elsif subspecs.count > 0 = '[' + subspecs.join(',') + '] ' end end case result.type when :error then type = 'ERROR' when :warning then type = 'WARN' when :note then type = 'NOTE' else raise "#{result.type}" end UI.puts " - #{type.ljust(5)} | #{}#{}#{result.}" end UI.puts end |
#result_color ⇒ Symbol
Returns The color, which should been used to display the result. One of: ‘:green`, `:yellow`, `:red`.
208 209 210 211 212 213 |
# File 'lib/cocoapods/validator.rb', line 208 def result_color case result_type when :error then :red when :warning then :yellow else :green end end |
#result_type ⇒ Symbol
Returns The type, which should been used to display the result. One of: ‘:error`, `:warning`, `:note`.
197 198 199 200 201 202 203 |
# File 'lib/cocoapods/validator.rb', line 197 def result_type types = results.map(&:type).uniq if types.include?(:error) then :error elsif types.include?(:warning) then :warning else :note end end |
#spec ⇒ Specification
Returns the specification to lint.
39 40 41 |
# File 'lib/cocoapods/validator.rb', line 39 def spec @linter.spec end |
#validate ⇒ Bool
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cocoapods/validator.rb', line 64 def validate @results = [] # Replace default spec with a subspec if asked for a_spec = spec if spec && @only_subspec a_spec = spec.subspec_by_name(@only_subspec) @subspec_name = a_spec.name end UI.print " -> #{a_spec ? a_spec.name : file.basename}\r" unless config.silent? $stdout.flush perform_linting perform_extensive_analysis(a_spec) if a_spec && !quick UI.puts ' -> '.send(result_color) << (a_spec ? a_spec.to_s : file.basename.to_s) print_results validated? end |
#validated? ⇒ Boolean
190 191 192 |
# File 'lib/cocoapods/validator.rb', line 190 def validated? result_type != :error && (result_type != :warning || allow_warnings) end |
#validation_dir ⇒ Pathname
Returns the temporary directory used by the linter.
217 218 219 |
# File 'lib/cocoapods/validator.rb', line 217 def validation_dir Pathname(Dir.tmpdir) + 'CocoaPods/Lint' end |