Class: Pod::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/source.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo) ⇒ Source

Returns a new instance of Source.



31
32
33
# File 'lib/cocoapods/source.rb', line 31

def initialize(repo)
  @repo = repo
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



29
30
31
# File 'lib/cocoapods/source.rb', line 29

def repo
  @repo
end

Class Method Details

.allObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/cocoapods/source.rb', line 3

def self.all
  @sources ||= begin
    repos_dir = Config.instance.repos_dir
    unless repos_dir.exist?
      raise Informative, "No spec repos found in `#{repos_dir}'. " \
                         "To fetch the `master' repo run: $ pod setup"
    end
    repos_dir.children.select(&:directory?).map { |repo| new(repo) }
  end
end

.search(dependency) ⇒ Object



14
15
16
17
# File 'lib/cocoapods/source.rb', line 14

def self.search(dependency)
  all.map { |s| s.search(dependency) }.compact.first ||
    raise(Informative, "Unable to find a pod named `#{dependency.name}'")
end

.search_by_name(query, full_text_search) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/cocoapods/source.rb', line 19

def self.search_by_name(query, full_text_search)
  result = all.map { |s| s.search_by_name(query, full_text_search) }.flatten
  if result.empty?
    extra = ", summary, or description" if full_text_search
    raise(Informative, "Unable to find a pod with name" \
                       "#{extra} matching `#{query}'")
  end
  result
end

Instance Method Details

#pod_setsObject



35
36
37
38
39
40
41
# File 'lib/cocoapods/source.rb', line 35

def pod_sets
  @repo.children.map do |child|
    if child.directory? && child.basename.to_s != '.git'
      Specification::Set.by_pod_dir(child)
    end
  end.compact
end

#search(dependency) ⇒ Object



43
44
45
# File 'lib/cocoapods/source.rb', line 43

def search(dependency)
  pod_sets.find { |set| set.name == dependency.name }
end

#search_by_name(query, full_text_search) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cocoapods/source.rb', line 47

def search_by_name(query, full_text_search)
  pod_sets.map do |set|
    text = if full_text_search
      s = set.specification
      "#{s.name} #{s.summary} #{s.description}"
    else
      set.name
    end
    set if text.downcase.include?(query.downcase)
  end.compact
end