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.



39
40
41
42
43
44
45
46
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 39

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.



79
80
81
82
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 79

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.



93
94
95
96
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 93

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)


113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 113

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.



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

def type
  'file system'
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)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 54

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