Class: Pod::SourcesManager

Inherits:
Object
  • Object
show all
Extended by:
Config::Mixin, Executable
Defined in:
lib/cocoapods/sources_manager.rb

Overview

Manages all the sources known to the running CocoaPods Instance.

Class Attribute Summary collapse

Master repo collapse

Class Method Summary collapse

Methods included from Config::Mixin

config

Methods included from Executable

executable, execute_command

Class Attribute Details

.updated_search_indexHash{String => String}

Note:

This operation is fairly expensive, because of the YAML conversion.

Creates or updates the search data and returns it. The search data groups by name the following information for each set:

- version
- summary
- description
- authors

Returns:

  • (Hash{String => String})

    The up to date search data.



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cocoapods/sources_manager.rb', line 97

def updated_search_index
  unless @updated_search_index
    if search_index_path.exist?
      stored_index = YAML.load(search_index_path.read)
      if stored_index && stored_index.is_a?(Hash)
        search_index = aggregate.update_search_index(stored_index)
      else
        search_index = aggregate.generate_search_index
      end
    else
      search_index = aggregate.generate_search_index
    end

    File.open(search_index_path, 'w') {|f| f.write(search_index.to_yaml) }
    @updated_search_index = search_index
  end
  @updated_search_index
end

Class Method Details

.aggregateSource::Aggregate

Returns the aggregate of all the sources known to this installation of CocoaPods.

Returns:

  • (Source::Aggregate)

    the aggregate of all the sources known to this installation of CocoaPods.



14
15
16
# File 'lib/cocoapods/sources_manager.rb', line 14

def aggregate
  Source::Aggregate.new(config.repos_dir)
end

.allArray<Source>

Returns the list of all the sources known to this installation of CocoaPods.

Returns:

  • (Array<Source>)

    the list of all the sources known to this installation of CocoaPods.



21
22
23
# File 'lib/cocoapods/sources_manager.rb', line 21

def all
  aggregate.all
end

.all_setsArray<Specification::Set>

Returns the list of all the specification sets know to this installation of CocoaPods.

Returns:

  • (Array<Specification::Set>)

    the list of all the specification sets know to this installation of CocoaPods.



28
29
30
# File 'lib/cocoapods/sources_manager.rb', line 28

def all_sets
  aggregate.all_sets
end

.check_version_information(dir) ⇒ void

This method returns an undefined value.

Checks the version information of the source with the given directory. It raises if the source is not compatible and if there is CocoaPods update it informs the user.

Parameters:

  • dir (Pathname)

    The directory where the source is stored.

Raises:

  • If the source is not compatible.



185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/cocoapods/sources_manager.rb', line 185

def check_version_information(dir)
  versions = version_information(dir)
  unless repo_compatible?(dir)
    min, max = versions['min'], versions['max']
    version_msg = ( min == max ) ? min : "#{min} - #{max}"
    raise Informative, "The `#{dir.basename}` repo requires " \
    "CocoaPods #{version_msg}\n".red +
    "Update CocoaPods, or checkout the appropriate tag in the repo."
  end

  if config.new_version_message? && cocoapods_update?(versions)
    UI.puts "\nCocoaPods #{versions['last']} is available.\n".green
  end
end

.cocoapods_update?(version_information) ⇒ Bool

Checks whether there is a CocoaPods given the version information of a repo.

Parameters:

  • version_information (Hash)

    The version information of a repository.

Returns:

  • (Bool)

    whether there is an update.



226
227
228
229
# File 'lib/cocoapods/sources_manager.rb', line 226

def cocoapods_update?(version_information)
  version = version_information['last']
  version && Gem::Version.new(version) > Gem::Version.new(Pod::VERSION)
end

.git_repo?(dir) ⇒ Bool

Returns whether a source is a GIT repo.

Parameters:

  • dir (Pathname)

    The directory where the source is stored.

Returns:

  • (Bool)

    Wether the given source is a GIT repo.



169
170
171
172
# File 'lib/cocoapods/sources_manager.rb', line 169

def git_repo?(dir)
  Dir.chdir(dir) { `git rev-parse  >/dev/null 2>&1` }
  $?.exitstatus.zero?
end

.master_repo_dirPathname

Returns The path of the master repo.

Returns:

  • (Pathname)

    The path of the master repo.



258
259
260
# File 'lib/cocoapods/sources_manager.rb', line 258

def master_repo_dir
  config.repos_dir + 'master'
end

.master_repo_functional?Bool

Note:

Note this is used to automatically setup the master repo if needed.

Returns Checks if the master repo is usable.

Returns:

  • (Bool)

    Checks if the master repo is usable.



267
268
269
# File 'lib/cocoapods/sources_manager.rb', line 267

def master_repo_functional?
  master_repo_dir.exist? && repo_compatible?(master_repo_dir)
end

.repo_compatible?(dir) ⇒ Bool

Returns whether a source is compatible with the current version of CocoaPods.

Parameters:

  • dir (Pathname)

    The directory where the source is stored.

Returns:

  • (Bool)

    whether the source is compatible.



208
209
210
211
212
213
214
215
216
# File 'lib/cocoapods/sources_manager.rb', line 208

def repo_compatible?(dir)
  versions = version_information(dir)

  min, max = versions['min'], versions['max']
  bin_version  = Gem::Version.new(Pod::VERSION)
  supports_min = !min || bin_version >= Gem::Version.new(min)
  supports_max = !max || bin_version <= Gem::Version.new(max)
  supports_min && supports_max
end

.search(dependency) ⇒ Set?

Search all the sources to match the set for the given dependency.

Returns:

  • (Set, nil)

    a set for a given dependency including all the Source that contain the Pod. If no sources containing the Pod where found it returns nil.

Raises:

  • If no source including the set can be found.



40
41
42
# File 'lib/cocoapods/sources_manager.rb', line 40

def search(dependency)
  aggregate.search(dependency)
end

.search_by_name(query, full_text_search = false) ⇒ Array<Set>

Note:

Full text search requires to load the specification for each pod, hence is considerably slower.

Search all the sources with the given search term.

Parameters:

  • query (String)

    The search term.

  • full_text_search (Bool) (defaults to: false)

    Whether the search should be limited to the name of the Pod or should include also the author, the summary, and the description.

Returns:

  • (Array<Set>)

    The sets that contain the search term.

Raises:

  • If no source including the set can be found.



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

def search_by_name(query, full_text_search = false)
  if full_text_search
    set_names = []
    updated_search_index.each do |name, set_data|
      text = name.dup
      if full_text_search
        text << set_data['authors'].to_s if set_data['authors']
        text << set_data['summary']      if set_data['summary']
        text << set_data['description']  if set_data['description']
      end
      set_names << name if text.downcase.include?(query.downcase)
    end
    sets = set_names.sort.map { |name| aggregate.represenative_set(name) }
  else
    sets = aggregate.search_by_name(query, false)
  end
  if sets.empty?
    extra = ", author, summary, or description" if full_text_search
    raise Informative, "Unable to find a pod with name#{extra} matching `#{query}`"
  end
  sets
end

.search_index_pathPathname

Returns The path where the search index should be stored.

Returns:

  • (Pathname)

    The path where the search index should be stored.



122
123
124
# File 'lib/cocoapods/sources_manager.rb', line 122

def search_index_path
  CACHE_ROOT + 'search_index.yaml'
end

.update(source_name = nil, show_output = false) ⇒ void

This method returns an undefined value.

Updates the local clone of the spec-repo with the given name or of all the git repos if the name is omitted.

Parameters:

  • name (String)


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/cocoapods/sources_manager.rb', line 141

def update(source_name = nil, show_output = false)
  if source_name
    specified_source = aggregate.all.find { |s| s.name == source_name }
    raise Informative, "Unable to find the `#{source_name}` repo."    unless specified_source
    raise Informative, "The `#{source_name}` repo is not a git repo." unless git_repo?(specified_source.repo)
    sources = [specified_source]
  else
    sources = aggregate.all.select { |source| git_repo?(source.repo) }
  end

  sources.each do |source|
    UI.section "Updating spec repo `#{source.name}`" do
      Dir.chdir(source.repo) do
        output = git!("pull")
        UI.puts output if show_output && !config.verbose?
      end
      check_version_information(source.repo)
    end
  end
end

.version_information(dir) ⇒ Hash

Returns the contents of the ‘CocoaPods-version.yml` file, which stores information about CocoaPods versions.

This file is a hash with the following keys:

  • last: the last version of CocoaPods known to the source.

  • min: the minimum version of CocoaPods supported by the source.

  • max: the maximum version of CocoaPods supported by the source.

Parameters:

  • dir (Pathname)

    The directory where the source is stored.

Returns:

  • (Hash)

    the versions information from the repo.



245
246
247
248
249
# File 'lib/cocoapods/sources_manager.rb', line 245

def version_information(dir)
  require 'yaml'
  yaml_file  = dir + 'CocoaPods-version.yml'
  yaml_file.exist? ? YAML.load_file(yaml_file) : {}
end