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.



15
16
17
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 15

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.



11
12
13
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 11

def repo
  @repo
end

Instance Method Details

#nameString

Returns The name of the source.

Returns:

  • (String)

    The name of the source.



26
27
28
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 26

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.



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

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 == '.' || entry == '..' || entry == '.git')
    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.



75
76
77
78
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 75

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.



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

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)


109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cocoapods-core/source/file_system_data_provider.rb', line 109

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.



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

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)


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

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
    basename if v.directory? && basename[0, 1] != '.'
  end.compact.sort.reverse
end