Class: Pod::Validator

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Config::Mixin

#config

Constructor Details

#initialize(spec_or_path) ⇒ Validator

Returns a new instance of Validator.

Parameters:

  • spec_or_path (Specification, Pathname, String)

    the Specification or the path of the ‘podspec` file to lint.



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_accessorSandbox::FileAccessor

Returns the file accessor for the spec.

Returns:



45
46
47
# File 'lib/cocoapods/validator.rb', line 45

def file_accessor
  @file_accessor
end

#linterSpecification::Linter (readonly)

Returns the linter instance from CocoaPods Core.

Returns:

  • (Specification::Linter)

    the linter instance from CocoaPods Core.



19
20
21
# File 'lib/cocoapods/validator.rb', line 19

def linter
  @linter
end

#local=(value) ⇒ Bool (writeonly)

Note:

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.

Returns:

  • (Bool)

    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_cleanBool

Returns whether the linter should not clean up temporary files for inspection.

Returns:

  • (Bool)

    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_errorsBool

Returns Whether the validator should fail only on errors or also on warnings.

Returns:

  • (Bool)

    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

#quickBool

Returns whether the validation should skip the checks that requires the download of the library.

Returns:

  • (Bool)

    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

#resultsObject (readonly)

Returns the value of attribute results.



125
126
127
# File 'lib/cocoapods/validator.rb', line 125

def results
  @results
end

Instance Method Details

#filePathname

Returns the path of the ‘podspec` file where #spec is defined.

Returns:

  • (Pathname)

    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

Returns:

  • (Boolean)


112
# File 'lib/cocoapods/validator.rb', line 112

def local?; @local; end

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]
      platform_message = "[iOS] "
    elsif result.platforms == [:osx]
      platform_message = "[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)} | #{platform_message}#{result.message}"
  end
  UI.puts
end

#result_colorSymbol

Returns:

  • (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_typeSymbol

Returns:

  • (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

#specSpecification

Returns the specification to lint.

Returns:



32
33
34
# File 'lib/cocoapods/validator.rb', line 32

def spec
  @linter.spec
end

#validateBool

Note:

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.

Returns:

  • (Bool)

    whether the specification passed validation.



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

Returns:

  • (Boolean)


129
130
131
# File 'lib/cocoapods/validator.rb', line 129

def validated?
  result_type != :error && (result_type != :warning || only_errors)
end

#validation_dirPathname

Returns the temporary directory used by the linter.

Returns:

  • (Pathname)

    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