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.
Instance Attribute Summary collapse
-
#file_accessor ⇒ Sandbox::FileAccessor
The file accessor for the spec.
-
#linter ⇒ Specification::Linter
readonly
The linter instance from CocoaPods Core.
-
#local ⇒ Bool
writeonly
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.
-
#only_errors ⇒ Bool
Whether the validator should fail only on errors or also on warnings.
-
#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.
Instance Method Summary collapse
-
#file ⇒ Pathname
The path of the ‘podspec` file where #spec is defined.
-
#initialize(spec_or_path) ⇒ Validator
constructor
A new instance of Validator.
- #local? ⇒ Boolean
-
#print_results ⇒ void
Prints the result of the validation to the user.
- #result_color ⇒ Symbol
- #result_type ⇒ Symbol
-
#spec ⇒ Specification
The specification to lint.
-
#validate ⇒ Bool
Lints the specification adding a Specification::Linter::Result for any failed check to the #results list.
- #validated? ⇒ Boolean
-
#validation_dir ⇒ Pathname
The temporary directory used by the linter.
Methods included from Config::Mixin
Constructor Details
#initialize(spec_or_path) ⇒ Validator
Returns a new instance of Validator.
24 25 26 |
# File 'lib/cocoapods/validator.rb', line 24 def initialize(spec_or_path) @linter = Specification::Linter.new(spec_or_path) end |
Instance Attribute Details
#file_accessor ⇒ Sandbox::FileAccessor
Returns the file accessor for the spec.
45 46 47 |
# File 'lib/cocoapods/validator.rb', line 45 def file_accessor @file_accessor end |
#linter ⇒ Specification::Linter (readonly)
Returns the linter instance from CocoaPods Core.
19 20 21 |
# File 'lib/cocoapods/validator.rb', line 19 def linter @linter end |
#local=(value) ⇒ Bool (writeonly)
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.
111 112 113 |
# File 'lib/cocoapods/validator.rb', line 111 def local=(value) @local = value end |
#no_clean ⇒ Bool
Returns whether the linter should not clean up temporary files for inspection.
104 105 106 |
# File 'lib/cocoapods/validator.rb', line 104 def no_clean @no_clean end |
#only_errors ⇒ Bool
Returns Whether the validator should fail only on errors or also on warnings.
117 118 119 |
# File 'lib/cocoapods/validator.rb', line 117 def only_errors @only_errors end |
#quick ⇒ Bool
Returns whether the validation should skip the checks that requires the download of the library.
99 100 101 |
# File 'lib/cocoapods/validator.rb', line 99 def quick @quick end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
125 126 127 |
# File 'lib/cocoapods/validator.rb', line 125 def results @results end |
Instance Method Details
#file ⇒ Pathname
Returns the path of the ‘podspec` file where #spec is defined.
39 40 41 |
# File 'lib/cocoapods/validator.rb', line 39 def file @linter.file end |
#local? ⇒ Boolean
112 |
# File 'lib/cocoapods/validator.rb', line 112 def local?; @local; end |
#print_results ⇒ void
This method returns an undefined value.
Prints the result of the validation to the user.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/cocoapods/validator.rb', line 74 def print_results results.each do |result| if result.platforms == [:ios] = "[iOS] " elsif result.platforms == [:osx] = "[OSX] " 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
144 145 146 147 148 149 |
# File 'lib/cocoapods/validator.rb', line 144 def result_color case result_type when :error then :red when :warning then :yellow else :green end end |
#result_type ⇒ Symbol
135 136 137 138 139 140 |
# File 'lib/cocoapods/validator.rb', line 135 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.
32 33 34 |
# File 'lib/cocoapods/validator.rb', line 32 def spec @linter.spec end |
#validate ⇒ Bool
This method shows immediately which pod is being processed and overrides the printed line once the result is known.
Lints the specification adding a Specification::Linter::Result for any failed check to the #results list.
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cocoapods/validator.rb', line 57 def validate @results = [] UI.print " -> #{spec ? spec.name : file.basename}\r" unless config.silent? $stdout.flush perform_linting perform_extensive_analysis if spec && !quick UI.puts " -> ".send(result_color) << (spec ? spec.to_s : file.basename.to_s) print_results validated? end |
#validated? ⇒ Boolean
129 130 131 |
# File 'lib/cocoapods/validator.rb', line 129 def validated? result_type != :error && (result_type != :warning || only_errors) end |
#validation_dir ⇒ Pathname
Returns the temporary directory used by the linter.
153 154 155 |
# File 'lib/cocoapods/validator.rb', line 153 def validation_dir Pathname.new('/tmp/CocoaPods/Lint') end |