Class: Pod::Source::HealthReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-core/source/health_reporter.rb

Overview

Checks a source for errors and warnings.

Defined Under Namespace

Classes: HealthReport

Actions collapse

Instance Attribute Summary collapse

Configuration collapse

Actions collapse

Private helpers collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ HealthReporter

Returns a new instance of HealthReporter

Parameters:

  • repo (Pathname)

    @see Source#repo.


12
13
14
15
16
# File 'lib/cocoapods-core/source/health_reporter.rb', line 12

def initialize(repo)
  @source = Source.new(repo)
  @errors = {}
  @linter_results = {}
end

Instance Attribute Details

#reportHealtReport (readonly)

Returns The report produced by the analysis.

Returns:

  • (HealtReport)

    The report produced by the analysis.


69
70
71
# File 'lib/cocoapods-core/source/health_reporter.rb', line 69

def report
  @report
end

#sourceSource (readonly)

Returns the source to check.

Returns:

  • (Source)

    the source to check.


8
9
10
# File 'lib/cocoapods-core/source/health_reporter.rb', line 8

def source
  @source
end

Instance Method Details

#analyzeHealthReport

Analyzes all the specification files in the source.

Returns:

  • (HealthReport)

    A report which contains the information about the state of the source.


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cocoapods-core/source/health_reporter.rb', line 50

def analyze
  @report = HealthReport.new(source)

  source.pods.each do |name|
    source.versions(name).each do |version|
      @pre_check_callback.call(name, version) if @pre_check_callback
      spec_path = source.specification_path(name, version)
      spec = lint_spec(name, version, spec_path)
      check_spec_path(name, version, spec) if spec
      report.analyzed_paths << spec_path
    end
  end

  check_stray_specs
  report
end

#check_spec_path(name, version, spec) ⇒ void (private)

This method returns an undefined value.

Ensures that the name and the version of the specification correspond to the ones expected by the repo given its path.

Parameters:

  • name (String)

    The name of the Pod.

  • version (Version)

    The version of the specification.

  • spec (Specification)

    The specification to check.


114
115
116
117
118
119
# File 'lib/cocoapods-core/source/health_reporter.rb', line 114

def check_spec_path(name, version, spec)
  unless spec.name == name && spec.version.to_s == version.to_s
    message = "Incorrect path #{ spec.defined_in_file }"
    report.add_message(:error, message, name, spec.version)
  end
end

#check_stray_specsvoid (private)

This method returns an undefined value.

Checks for any stray specification in the repo.

Parameters:

  • analyzed_paths (Array<Pathname>)

    The specification to check.


128
129
130
131
132
133
134
# File 'lib/cocoapods-core/source/health_reporter.rb', line 128

def check_stray_specs
  all_paths = Pathname.glob(source.repo + '**/*.podspec{,.json}')
  stray_specs = all_paths - report.analyzed_paths
  stray_specs.each do |path|
    report.add_message(:error, 'Stray spec', path)
  end
end

#lint_spec(name, version, spec_path) ⇒ Specification, Nil (private)

Checks the validity of the specification with the linter.

Parameters:

  • name (String)

    The name of the Pod.

  • version (Version)

    The version of the specification.

  • spec_path (Pathname)

    The path of the specification to check.

Returns:

  • (Specification)

    The specification loaded by the linter.

  • (Nil)

    If the specifications raised during evaluation.


90
91
92
93
94
95
96
97
98
# File 'lib/cocoapods-core/source/health_reporter.rb', line 90

def lint_spec(name, version, spec_path)
  linter = Specification::Linter.new(spec_path)
  linter.lint
  linter.results.each do |result|
    type = result.type == :error ? :error : :warning
    report.add_message(type, result.message, name, version)
  end
  linter.spec
end

#pre_check(&block) ⇒ void

This method returns an undefined value.

Allows to specify an optional callback which is called before analysing every spec. Suitable for UI.

Parameters:

  • A (Proc)

    callback which is called before checking any specification. It receives the name and the version of the spec.


34
35
36
# File 'lib/cocoapods-core/source/health_reporter.rb', line 34

def pre_check(&block)
  @pre_check_callback = block
end