Class: Pod::Source::Acceptor

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

Overview

Checks whether a podspec can be accepted by a source. The check takes into account the introduction of 0.0.1 version if there are already tagged ones or whether there is change in the source.

Instance Attribute Summary collapse

Actions collapse

Private helpers collapse

Source helpers collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Acceptor

Returns a new instance of Acceptor.

Parameters:

  • repo (Pathname)

    @see Source#repo.



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

def initialize(repo)
  @source = Source.new(repo)
end

Instance Attribute Details

#sourceSource (readonly)

Returns the source where the podspec should be added.

Returns:

  • (Source)

    the source where the podspec should be added.



10
11
12
# File 'lib/cocoapods-core/source/acceptor.rb', line 10

def source
  @source
end

Instance Method Details

#analyze(spec, previous_spec = nil) ⇒ Array<String>

Checks whether the given specification can be accepted.

Returns:

  • (Array<String>)

    A list of errors. If the list is empty the specification should be accepted.



28
29
30
31
32
33
34
35
# File 'lib/cocoapods-core/source/acceptor.rb', line 28

def analyze(spec, previous_spec = nil)
  errors = []
  check_spec_source_change(spec, errors)
  check_if_untagged_version_is_acceptable(spec, previous_spec, errors)
  check_commit_change_for_untagged_version(spec, previous_spec, errors)
  check_dependencies(spec, errors)
  errors
end

#analyze_path(spec_path) ⇒ Array<String>

Checks whether the specification at the given path can be accepted.

Returns:

  • (Array<String>)

    A list of errors. If the list is empty the specification should be accepted.



42
43
44
45
46
47
# File 'lib/cocoapods-core/source/acceptor.rb', line 42

def analyze_path(spec_path)
  spec = Specification.from_file(spec_path)
  analyze(spec)
rescue
  ['Unable to load the specification.']
end

#check_commit_change_for_untagged_version(spec, previous_spec, errors) ⇒ void (private)

This method returns an undefined value.

If the previous specification for the given file is passed it is checked for any attempt to update the commit of a 0.0.1 version.



107
108
109
110
111
112
113
# File 'lib/cocoapods-core/source/acceptor.rb', line 107

def check_commit_change_for_untagged_version(spec, previous_spec, errors)
  return unless previous_spec
  return unless spec.version == Version.new('0.0.1')
  unless spec.source[:commit] == previous_spec.source[:commit]
    errors << 'Attempt to rewrite the commit of a 0.0.1 version.'
  end
end

#check_dependencies(spec, errors) ⇒ void (private)

This method returns an undefined value.

Checks that there is a specification available for each of the dependencies of the given specification.



120
121
122
123
124
125
126
127
128
# File 'lib/cocoapods-core/source/acceptor.rb', line 120

def check_dependencies(spec, errors)
  spec.dependencies.each do |dep|
    set = source.search(dep)
    unless set && set.specification
      errors << "Unable to find a specification for the `#{dep}` " \
        'dependency.'
    end
  end
end

#check_if_untagged_version_is_acceptable(spec, previous_spec, errors) ⇒ void (private)

This method returns an undefined value.

Checks there are already tagged specifications if the specification has a git source and doesn't specify a tag (i.e. rejects 0.0.1 specs if they are not admissible anymore).



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

def check_if_untagged_version_is_acceptable(spec, previous_spec, errors)
  return if !spec.source[:git] || spec.source[:tag]
  return unless related_specifications(spec)
  return if previous_spec
  has_tagged_spec = related_specifications(spec).any? do |s|
    s.version != '0.0.1'
  end
  if has_tagged_spec
    errors << 'There is already at least one versioned specification ' \
      'so untagged versions cannot be accepted.'
  end
end

#check_spec_source_change(spec, errors) ⇒ void (private)

Note:

HTTP Sources are ignored as they change per version.

This method returns an undefined value.

Checks whether the source of the proposed specification is different from the one of the reference specification.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/cocoapods-core/source/acceptor.rb', line 61

def check_spec_source_change(spec, errors)
  require 'cocoapods-core/http'

  return unless spec
  return if spec.source[:http]
  return unless reference_spec(spec)
  keys = Spec::DSL::SOURCE_KEYS.keys
  source = spec.source.values_at(*keys).compact.first
  old_source = reference_spec(spec).source.values_at(*keys).compact.first
  unless source == old_source
    source = HTTP.get_actual_url(source)
    old_source = HTTP.get_actual_url(old_source)
    unless source == old_source
      message = "The source of the spec doesn't match with the recorded "
      message << "ones. Source: `#{source}`. Previous: `#{old_source}`.\n "
      message << 'Please contact the specs repo maintainers if the '
      message << 'library changed location.'
      errors << message
    end
  end
end

#reference_spec(spec) ⇒ Specification, Nil (private)

Returns the most representative specification for the Pod of the given spec.

Parameters:

  • spec (Specification)

    The specification for which the representative spec is needed.

Returns:

  • (Specification)

    The specification with the highest version.

  • (Nil)

    If there are no other specifications stored.



162
163
164
165
# File 'lib/cocoapods-core/source/acceptor.rb', line 162

def reference_spec(spec)
  specs = related_specifications(spec)
  specs.last if specs
end

Returns the specifications related to the given spec.

Parameters:

  • spec (Specification)

    The specification for which the siblings specs are needed.

Returns:

  • (Array<Specification>)

    The other specifications of the Pod.

  • (Nil)

    If there are no other specifications stored.



144
145
146
147
148
149
150
# File 'lib/cocoapods-core/source/acceptor.rb', line 144

def related_specifications(spec)
  versions = source.versions(spec.name)
  return unless versions
  specs = versions.sort.map { |v| source.specification(spec.name, v) }
  specs.delete(spec)
  specs
end