Class: Pod::Specification::Set

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

Direct Known Subclasses

External

Defined Under Namespace

Classes: External

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pod_dir) ⇒ Set

Returns a new instance of Set.



22
23
24
25
# File 'lib/cocoapods/specification/set.rb', line 22

def initialize(pod_dir)
  @pod_dir = pod_dir
  @required_by = []
end

Instance Attribute Details

#pod_dirObject (readonly)

Returns the value of attribute pod_dir.



20
21
22
# File 'lib/cocoapods/specification/set.rb', line 20

def pod_dir
  @pod_dir
end

Class Method Details

.by_pod_dir(pod_dir) ⇒ Object

This keeps an identity map of sets so that you always get the same Set instance for the same pod directory.



14
15
16
17
18
# File 'lib/cocoapods/specification/set.rb', line 14

def self.by_pod_dir(pod_dir)
  set = new(pod_dir)
  sets[set.name] ||= set
  sets[set.name]
end

.by_specification_name(name) ⇒ Object



8
9
10
# File 'lib/cocoapods/specification/set.rb', line 8

def self.by_specification_name(name)
  sets[name]
end

.setsObject



4
5
6
# File 'lib/cocoapods/specification/set.rb', line 4

def self.sets
  @sets ||= {}
end

Instance Method Details

#==(other) ⇒ Object



67
68
69
# File 'lib/cocoapods/specification/set.rb', line 67

def ==(other)
  self.class === other && @pod_dir == other.pod_dir
end

#dependencyObject



39
40
41
42
43
# File 'lib/cocoapods/specification/set.rb', line 39

def dependency
  @required_by.inject(Dependency.new(name)) do |previous, spec|
    previous.merge(spec.dependency_by_name(name))
  end
end

#nameObject



49
50
51
# File 'lib/cocoapods/specification/set.rb', line 49

def name
  @pod_dir.basename.to_s
end

#only_part_of_other_pod?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/cocoapods/specification/set.rb', line 45

def only_part_of_other_pod?
  @required_by.all? { |spec| spec.dependency_by_name(name).only_part_of_other_pod? }
end

#required_by(specification) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cocoapods/specification/set.rb', line 27

def required_by(specification)
  dependency = specification.dependency_by_name(name)
  unless @required_by.empty? || dependency.requirement.satisfied_by?(required_version)
    # TODO add graph that shows which dependencies led to this.
    raise Informative, "#{specification} tries to activate `#{dependency}', " \
                       "but already activated version `#{required_version}' " \
                       "by #{@required_by.join(', ')}."
  end
  @specification = nil
  @required_by << specification
end

#required_versionObject

Return the first version that matches the current dependency.



62
63
64
65
# File 'lib/cocoapods/specification/set.rb', line 62

def required_version
  versions.find { |v| dependency.match?(name, v) } ||
    raise(Informative, "Required version (#{dependency}) not found for `#{name}'.")
end

#specificationObject



57
58
59
# File 'lib/cocoapods/specification/set.rb', line 57

def specification
  @specification ||= Specification.from_file(specification_path)
end

#specification_pathObject



53
54
55
# File 'lib/cocoapods/specification/set.rb', line 53

def specification_path
  @pod_dir + required_version.to_s + "#{name}.podspec"
end

#to_sObject Also known as: inspect



71
72
73
# File 'lib/cocoapods/specification/set.rb', line 71

def to_s
  "#<#{self.class.name} for `#{name}' with required version `#{required_version}'>"
end

#versionsObject

Returns Pod::Version instances, for each version directory, sorted from highest version to lowest.



78
79
80
81
82
83
# File 'lib/cocoapods/specification/set.rb', line 78

def versions
  @pod_dir.children.map do |v|
    basename = v.basename.to_s
    Version.new(basename) if v.directory? && basename[0,1] != '.'
  end.compact.sort.reverse
end