class CocoaPodsAcknowledgements::AddOns::Acknowledgement

Attributes

spec[R]

Public Class Methods

new(file) click to toggle source

@param path [String] the path string to a pod spec.

# File lib/cocoapods_acknowledgements/addons/acknowledgement.rb, line 10
def initialize(file)
  path = Pathname(file).expand_path if file
  directory = path.dirname

  @spec = Pod::Specification.from_file(file) if path.exist?
  @license_text = license_text(@spec, directory)
end

Public Instance Methods

license_text(podspec, directory) click to toggle source

@param podspec [Pod::Specification] @param directory [Pathname]

@return [String] the text of the license. @return [Nil] if it's not found.

# File lib/cocoapods_acknowledgements/addons/acknowledgement.rb, line 24
def license_text(podspec, directory)
  return nil unless podspec
  text = podspec.license[:text]

  if text.nil?
    license_file = podspec.license[:file] || "LICENSE"
    license_path = directory + license_file
    return nil unless license_path.exist?
    text = File.read(license_path)
  end

  text
end
metadata_plist_item() click to toggle source

@return [Hash] the acknowledgement info for the Pods metadata plist. @return [Nil] if the license text is missing.

# File lib/cocoapods_acknowledgements/addons/acknowledgement.rb, line 41
def metadata_plist_item
  return nil unless @spec and @license_text
  {
    name: @spec.name,
    version: @spec.version.to_s,
    authors: Hash[@spec.authors.map { |k, v| [k, v || ""] }],
    socialMediaURL: @spec.social_media_url || "",
    summary: @spec.summary,
    licenseType: @spec.license[:type],
    licenseText: @license_text,
    homepage: @spec.homepage
  }
end
settings_plist_item() click to toggle source

@return [Hash] the acknowledgement info for the Settings.bundle plist. @return [Nil] if the license text is missing.

# File lib/cocoapods_acknowledgements/addons/acknowledgement.rb, line 58
def settings_plist_item
  return nil unless @spec and @license_text
  {
    Title: @spec.name,
    Type: "PSGroupSpecifier",
    FooterText: @license_text
  }
end