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.
-
#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.
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
#repo ⇒ Pathname (readonly)
Returns 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
#name ⇒ String
Returns 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 |
#pods ⇒ Array<String>
Using Pathname#children is sensibly slower.
Returns 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.
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.
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.
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 |
#type ⇒ String
Returns 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.
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 |