Class: CocoaPodsAcknowledgements::AddOns::PodsPlistModifier

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

Instance Method Summary collapse

Constructor Details

#initialize(target, sandbox) ⇒ PodsPlistModifier

A modifier to update:

  • Pods/Target Support Files/Pods-#app_name/Pods-#app_name-acknowledgements.plist|markdown

  • settings_bundle/#app_name-settings-metadata.plist“

Parameters:

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

    the xcodeproj target.

  • sandbox (Pod::Sandbox)

    the CocoaPods sandbox



17
18
19
20
21
22
23
24
25
# File 'lib/cocoapods_acknowledgements/addons/modifiers/pods_plist_modifier.rb', line 17

def initialize(target, sandbox)
  @markdown_path = sandbox.target_support_files_root + target.cocoapods_target_label + "#{target.cocoapods_target_label}-acknowledgements.markdown"
  @plist_path = sandbox.target_support_files_root + target.cocoapods_target_label + "#{target.cocoapods_target_label}-acknowledgements.plist"

  project = Xcodeproj::Project.open(target.user_project_path)
  file = project.files.find { |f| f.path =~ /Settings\.bundle$/ }
  settings_bundle = file&.real_path
  @settings_plist = settings_bundle + "#{target.cocoapods_target_label}-settings-metadata.plist" if settings_bundle&.exist?
end

Instance Method Details

#add(plist_metadata, excluded_names) ⇒ Object

Adds acknowledgements to the CocoaPods generated plist and markdown files 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.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cocoapods_acknowledgements/addons/modifiers/pods_plist_modifier.rb', line 53

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

  return if .empty?
  plist = (, excluded_names)

  [@plist_path, @settings_plist].each do |path|
    next unless path&.writable?
    Pod::UI.puts "Saving #{path}".green
    plist.save(path, CFPropertyList::List::FORMAT_XML)
  end

  File.write @markdown_path, markdown_text_with(plist)
end

#markdownString

Returns the acknowledgement texts at Pods/Target Support Files/Pods-#app_name/Pods-#app_name-acknowledgements.markdown.

Returns:

  • (String)

    the acknowledgement texts at Pods/Target Support Files/Pods-#app_name/Pods-#app_name-acknowledgements.markdown.



29
30
31
32
# File 'lib/cocoapods_acknowledgements/addons/modifiers/pods_plist_modifier.rb', line 29

def markdown
  return nil unless @markdown_path&.readable?
  File.read @markdown_path
end

#plistCFPropertyList::List

Returns the acknowledgement plist at Pods/Target Support Files/Pods-#app_name/Pods-#app_name-acknowledgements.plist.

Returns:

  • (CFPropertyList::List)

    the acknowledgement plist at Pods/Target Support Files/Pods-#app_name/Pods-#app_name-acknowledgements.plist.



36
37
38
39
# File 'lib/cocoapods_acknowledgements/addons/modifiers/pods_plist_modifier.rb', line 36

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

#settings_plistCFPropertyList::List

Returns the acknowledgement plist in the app Settings.bundle.

Returns:

  • (CFPropertyList::List)

    the acknowledgement plist in the app Settings.bundle.



43
44
45
46
# File 'lib/cocoapods_acknowledgements/addons/modifiers/pods_plist_modifier.rb', line 43

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