Class: CocoaPodsAcknowledgements::AddOns::Acknowledgement

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Acknowledgement

Returns a new instance of Acknowledgement.

Parameters:

  • path (String)

    the path string to a pod spec.



10
11
12
13
14
15
16
# 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

Instance Attribute Details

#specObject (readonly)

Returns the value of attribute spec.



6
7
8
# File 'lib/cocoapods_acknowledgements/addons/acknowledgement.rb', line 6

def spec
  @spec
end

Instance Method Details

#license_text(podspec, directory) ⇒ String, Nil

Parameters:

  • podspec (Pod::Specification)
  • directory (Pathname)

Returns:

  • (String)

    the text of the license.

  • (Nil)

    if it’s not found.



24
25
26
27
28
29
30
31
32
33
34
35
36
# 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_itemHash, Nil

Returns:

  • (Hash)

    the acknowledgement info for the Pods metadata plist.

  • (Nil)

    if the license text is missing.



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cocoapods_acknowledgements/addons/acknowledgement.rb', line 41

def 
  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_itemHash, Nil

Returns:

  • (Hash)

    the acknowledgement info for the Settings.bundle plist.

  • (Nil)

    if the license text is missing.



58
59
60
61
62
63
64
65
# 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