Class: Pod::Source::Metadata

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash = {}) ⇒ Metadata

Returns a new instance of Metadata.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/cocoapods-core/source/metadata.rb', line 14

def initialize(hash = {})
  hash = hash.with_indifferent_access
  @minimum_cocoapods_version = hash['min']
  @minimum_cocoapods_version &&= Pod::Version.new(@minimum_cocoapods_version)
  @maximum_cocoapods_version = hash['max']
  @maximum_cocoapods_version &&= Pod::Version.new(@maximum_cocoapods_version)
  @latest_cocoapods_version = hash['last']
  @latest_cocoapods_version &&= Pod::Version.new(@latest_cocoapods_version)
  @prefix_lengths = Array(hash['prefix_lengths']).map!(&:to_i)
  @last_compatible_versions = Array(hash['last_compatible_versions']).map(&Pod::Version.method(:new)).sort
end

Instance Attribute Details

#last_compatible_versionsObject (readonly)

Returns the value of attribute last_compatible_versions.



12
13
14
# File 'lib/cocoapods-core/source/metadata.rb', line 12

def last_compatible_versions
  @last_compatible_versions
end

#latest_cocoapods_versionObject (readonly)

Returns the value of attribute latest_cocoapods_version.



10
11
12
# File 'lib/cocoapods-core/source/metadata.rb', line 10

def latest_cocoapods_version
  @latest_cocoapods_version
end

#maximum_cocoapods_versionObject (readonly)

Returns the value of attribute maximum_cocoapods_version.



9
10
11
# File 'lib/cocoapods-core/source/metadata.rb', line 9

def maximum_cocoapods_version
  @maximum_cocoapods_version
end

#minimum_cocoapods_versionObject (readonly)

Returns the value of attribute minimum_cocoapods_version.



8
9
10
# File 'lib/cocoapods-core/source/metadata.rb', line 8

def minimum_cocoapods_version
  @minimum_cocoapods_version
end

#prefix_lengthsObject (readonly)

Returns the value of attribute prefix_lengths.



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

def prefix_lengths
  @prefix_lengths
end

Class Method Details

.from_file(file) ⇒ Object



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

def self.from_file(file)
  hash = file.file? ? YAMLHelper.load_file(file) : {}
  new(hash)
end

Instance Method Details

#compatible?(version) ⇒ Boolean

Returns whether a source is compatible with the current version of CocoaPods.

Parameters:

  • dir (Pathname)

    The directory where the source is stored.

Returns:

  • (Boolean)

    whether the source is compatible.



69
70
71
72
73
74
75
76
# File 'lib/cocoapods-core/source/metadata.rb', line 69

def compatible?(version)
  bin_version  = Gem::Version.new(version)
  supports_min = !minimum_cocoapods_version ||
    (bin_version >= Gem::Version.new(minimum_cocoapods_version))
  supports_max = !maximum_cocoapods_version ||
    (bin_version <= Gem::Version.new(maximum_cocoapods_version))
  supports_min && supports_max
end

#last_compatible_version(target_version) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/cocoapods-core/source/metadata.rb', line 53

def last_compatible_version(target_version)
  return unless minimum_cocoapods_version
  return if minimum_cocoapods_version <= target_version
  @last_compatible_versions.reverse.bsearch { |v| v <= target_version }.tap do |version|
    raise Informative, 'Unable to find compatible version' unless version
  end
end

#path_fragment(pod_name, version = nil) ⇒ Object



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

def path_fragment(pod_name, version = nil)
  prefixes = if prefix_lengths.empty?
               []
             else
               hashed = Digest::MD5.hexdigest(pod_name)
               prefix_lengths.map do |length|
                 hashed.slice!(0, length)
               end
             end
  prefixes.concat([pod_name, version]).compact
end

#to_hashObject



31
32
33
34
35
36
37
38
39
# File 'lib/cocoapods-core/source/metadata.rb', line 31

def to_hash
  hash = ActiveSupport::HashWithIndifferentAccess.new
  hash['min'] = @minimum_cocoapods_version.to_s if @minimum_cocoapods_version
  hash['max'] = @maximum_cocoapods_version.to_s if @maximum_cocoapods_version
  hash['last'] = @latest_cocoapods_version.to_s if @latest_cocoapods_version
  hash['prefix_lengths'] = @prefix_lengths unless @prefix_lengths.empty?
  hash['last_compatible_versions'] = @last_compatible_versions.map(&:to_s) unless @last_compatible_versions.empty?
  hash
end