Class: CocoaPodsAcknowledgements::AddOns::MetadataPlistModifier

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods_acknowledgements/addons/modifiers/metadata_plist_modifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(target, sandbox) ⇒ MetadataPlistModifier

A modifier to update Pods/Pods-#app_name-metadata.plist.

Parameters:

  • target (Pod::Installer::PostInstallHooksContext::UmbrellaTargetDescription)

    the xcodeproj target.

  • sandbox (Pod::Sandbox)

    the CocoaPods sandbox



14
15
16
# File 'lib/cocoapods_acknowledgements/addons/modifiers/metadata_plist_modifier.rb', line 14

def initialize(target, sandbox)
  @plist_path = sandbox.root + "#{target.cocoapods_target_label}-metadata.plist"
end

Instance Method Details

#add(plist_metadata, excluded_names) ⇒ Object

Adds acknowledgements to the plist except the excluded ones.

Parameters:

  • plist_metadata (Array<Hash>)

    the array of acknowledgement plist metadata.

  • excluded_names (Array<String>)

    the array of names to ignore.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cocoapods_acknowledgements/addons/modifiers/metadata_plist_modifier.rb', line 30

def add(, excluded_names)
   = [*]
  excluded_names = [*excluded_names]

  return if .empty? or not @plist_path&.writable?

  plist = CFPropertyList::List.new(file: @plist_path)
  entries = plist.value.value["specs"].value
  existing_titles = entries.map { |spec| spec.value["name"].value }
  excluded_names.uniq!

  additions = .map do ||
    next if .nil? or existing_titles.include? [:name]
    Pod::UI.info "Adding #{[:name]} to #{@plist_path.basename}"
    CFPropertyList.guess()
  end.reject(&:nil?)

  acknowledgements = entries + additions
  acknowledgements
    .sort! { |a, b| a.value["name"].value <=> b.value["name"].value }
    .reject! do |entry|
      matches = excluded_names.any? do |excluded_name|
        pattern = %r(^#{Regexp.escape(excluded_name).gsub("\*", ".*?")})
        entry.value["name"].value =~ pattern
      end
      Pod::UI.info %(Removing #{entry.value["name"].value} from #{@plist_path.basename}) if matches
      matches
    end

  plist.value.value["specs"].value = acknowledgements
  plist.save(@plist_path, CFPropertyList::List::FORMAT_XML)

  Pod::UI.puts "Saving #{@plist_path}".green
end

#plistCFPropertyList::List

Returns the acknowledgement plist at Pods/Pods-#app_name-metadata.plist.

Returns:

  • (CFPropertyList::List)

    the acknowledgement plist at Pods/Pods-#app_name-metadata.plist.



20
21
22
23
# File 'lib/cocoapods_acknowledgements/addons/modifiers/metadata_plist_modifier.rb', line 20

def plist
  return nil unless @plist_path&.readable?
  CFPropertyList::List.new(file: @plist_path)
end