Class: Pod::Source::FileSystemDataProvider
- Inherits:
-
AbstractDataProvider
- Object
- AbstractDataProvider
- Pod::Source::FileSystemDataProvider
- 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
-
#repo ⇒ Pathname
readonly
The path where the source is stored.
Required methods collapse
-
#name ⇒ String
The name of the source.
-
#pods ⇒ Array<String>
The list of the name of all the Pods known to the Source.
-
#specification(name, version) ⇒ Specification
The specification for a given version of a Pod.
-
#specification_contents(name, version) ⇒ Specification
The contents of the specification for a given version of a Pod.
-
#type ⇒ String
The user friendly type of the source.
-
#url ⇒ String
The URL of the source.
-
#versions(name) ⇒ Array<String>
All the available versions of a given Pod, sorted from highest to lowest.
Other methods collapse
-
#specification_path(name, version) ⇒ Pathname
Returns the path of the specification with the given name and version.
Instance Method Summary collapse
-
#initialize(repo) ⇒ FileSystemDataProvider
constructor
A new instance of FileSystemDataProvider.
Constructor Details
#initialize(repo) ⇒ FileSystemDataProvider
Returns a new instance of FileSystemDataProvider.
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
#repo ⇒ Pathname (readonly)
Returns 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
#name ⇒ String
Returns 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 |
#pods ⇒ Array<String>
Using Pathname#children is sensibly slower.
Returns 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.
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.
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.
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 |
#type ⇒ String
Returns 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 |
#url ⇒ String
Returns 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.
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 |