Class: Pod::Source::Acceptor
- Inherits:
-
Object
- Object
- Pod::Source::Acceptor
- 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
-
#source ⇒ Source
readonly
The source where the podspec should be added.
Actions collapse
-
#analyze(spec, previous_spec = nil) ⇒ Array<String>
Checks whether the given specification can be accepted.
-
#analyze_path(spec_path) ⇒ Array<String>
Checks whether the specification at the given path can be accepted.
Private helpers collapse
-
#check_commit_change_for_untagged_version(spec, previous_spec, errors) ⇒ void
private
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.
-
#check_dependencies(spec, errors) ⇒ void
private
Checks that there is a specification available for each of the dependencies of the given specification.
-
#check_if_untagged_version_is_acceptable(spec, previous_spec, errors) ⇒ void
private
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).
-
#check_spec_source_change(spec, errors) ⇒ void
private
Checks whether the source of the proposed specification is different from the one of the reference specification.
Source helpers collapse
-
#reference_spec(spec) ⇒ Specification, Nil
private
Returns the most representative specification for the Pod of the given spec.
-
#related_specifications(spec) ⇒ Array<Specification>, Nil
private
Returns the specifications related to the given spec.
Instance Method Summary collapse
-
#initialize(repo) ⇒ Acceptor
constructor
A new instance of Acceptor.
Constructor Details
Instance Attribute Details
#source ⇒ Source (readonly)
Returns 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.
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.
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 (spec) return if previous_spec has_tagged_spec = (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)
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 = "The source of the spec doesn't match with the recorded " << "ones. Source: `#{source}`. Previous: `#{old_source}`.\n " << 'Please contact the specs repo maintainers if the ' << 'library changed location.' errors << end end end |
#reference_spec(spec) ⇒ Specification, Nil (private)
Returns the most representative specification for the Pod of the given spec.
162 163 164 165 |
# File 'lib/cocoapods-core/source/acceptor.rb', line 162 def reference_spec(spec) specs = (spec) specs.last if specs end |
#related_specifications(spec) ⇒ Array<Specification>, Nil (private)
Returns the specifications related to the given spec.
144 145 146 147 148 149 150 |
# File 'lib/cocoapods-core/source/acceptor.rb', line 144 def (spec) versions = source.versions(spec.name) return unless versions specs = versions.sort.map { |v| source.specification(spec.name, v) } specs.delete(spec) specs end |