Class: Pod::Source::FileSystemDataProvider

Inherits:
AbstractDataProvider show all
Defined in:
lib/cocoapods-core/source/file_system_data_provider.rb

Overview

Data provider for a ‘Pod::Source` backed by a repository hosted in the file system.

Instance Attribute Summary collapse

Required methods collapse

Other methods collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ FileSystemDataProvider

Returns a new instance of FileSystemDataProvider.

Parameters:

  • repo (Pathname, String)

    @see #repo.



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

def initialize(repo)
  @repo = Pathname.new(repo)
end

Instance Attribute Details

#repoPathname (readonly)

Returns The path where the source is stored.

Returns:

  • (Pathname)

    The path where the source is stored.



9
10
11
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 9

def repo
  @repo
end

Instance Method Details

#nameString

Returns The name of the source.

Returns:

  • (String)

    The name of the source.



24
25
26
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 24

def name
  repo.basename.to_s
end

#podsArray<String>

Note:

Using Pathname#children is sensibly slower.

Returns The list of the name of all the Pods known to the Source.

Returns:

  • (Array<String>)

    The list of the name of all the Pods known to the Source.



48
49
50
51
52
53
54
55
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 48

def pods
  return nil unless specs_dir
  specs_dir_as_string = specs_dir.to_s
  Dir.entries(specs_dir).select do |entry|
    valid_name = entry[0, 1] != '.'
    valid_name && File.directory?(File.join(specs_dir_as_string, entry))
  end.sort
end

#specification(name, version) ⇒ Specification

Returns The specification for a given version of a Pod.

Parameters:

  • name (String)

    The name of the Pod.

  • version (String)

    The version of the Pod.

Returns:

  • (Specification)

    The specification for a given version of a Pod.



88
89
90
91
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 88

def specification(name, version)
  path = specification_path(name, version)
  Pod::Specification.from_file(path) if path && path.exist?
end

#specification_contents(name, version) ⇒ Specification

Returns The contents of the specification for a given version of a Pod.

Parameters:

  • name (String)

    the name of the Pod.

  • version (String)

    the version of the Pod.

Returns:

  • (Specification)

    The contents of the specification for a given version of a Pod.



102
103
104
105
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 102

def specification_contents(name, version)
  path = specification_path(name, version)
  File.open(path, 'r:utf-8') { |f| f.read } if path && path.exist?
end

#specification_path(name, version) ⇒ Pathname

Returns the path of the specification with the given name and version.

Parameters:

  • name (String)

    the name of the Pod.

  • version (Version, String)

    the version for the specification.

Returns:

  • (Pathname)

    The path of the specification.

Raises:

  • (ArgumentError)


122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 122

def specification_path(name, version)
  raise ArgumentError, 'No name' unless name
  raise ArgumentError, 'No version' unless version
  return nil unless specs_dir
  path = specs_dir + name + version.to_s
  specification_path = path + "#{name}.podspec.json"
  specification_path.exist?
  unless specification_path.exist?
    specification_path = path + "#{name}.podspec"
  end
  specification_path
end

#typeString

Returns The user friendly type of the source.

Returns:

  • (String)

    The user friendly type of the source.



39
40
41
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 39

def type
  'file system'
end

#urlString

Returns The URL of the source.

Returns:

  • (String)

    The URL of the source.



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

def url
  Dir.chdir(repo) do
    remote = `git ls-remote --get-url`.chomp
    remote if $?.success?
  end
end

#versions(name) ⇒ Array<String>

Returns All the available versions of a given Pod, sorted from highest to lowest.

Parameters:

  • name (String)

    The name of the Pod.

Returns:

  • (Array<String>)

    All the available versions of a given Pod, sorted from highest to lowest.

Raises:

  • (ArgumentError)


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

def versions(name)
  return nil unless specs_dir
  raise ArgumentError, 'No name' unless name
  pod_dir = specs_dir + name
  return unless pod_dir.exist?
  pod_dir.children.map do |v|
    basename = v.basename.to_s
    begin
      Version.new(basename) if v.directory? && basename[0, 1] != '.'
    rescue ArgumentError => e
      raise Informative, 'An unexpected version directory ' \
       "`#{basename}` was encountered for the " \
       "`#{pod_dir}` Pod in the `#{name}` repository."
    end
  end.compact.sort.reverse.map(&:to_s)
end