Class: Jazzy::PodspecDocumenter

Inherits:
Object
  • Object
show all
Defined in:
lib/jazzy/podspec_documenter.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(podspec) ⇒ PodspecDocumenter

Returns a new instance of PodspecDocumenter.



9
10
11
# File 'lib/jazzy/podspec_documenter.rb', line 9

def initialize(podspec)
  @podspec = podspec
end

Instance Attribute Details

#podspecObject (readonly)

Returns the value of attribute podspec.



7
8
9
# File 'lib/jazzy/podspec_documenter.rb', line 7

def podspec
  @podspec
end

Class Method Details

.apply_config_defaults(podspec, config) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/MethodLength



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/jazzy/podspec_documenter.rb', line 48

def self.apply_config_defaults(podspec, config)
  return unless podspec

  unless config.author_name_configured
    config.author_name = author_name(podspec)
    config.author_name_configured = true
  end
  unless config.module_name_configured
    config.module_name = podspec.module_name
    config.module_name_configured = true
  end
  unless config.author_url_configured
    config.author_url = podspec.homepage || github_file_prefix(podspec)
    config.author_url_configured = true
  end
  unless config.version_configured
    config.version = podspec.version.to_s
    config.version_configured = true
  end
  unless config.github_file_prefix_configured
    config.github_file_prefix = github_file_prefix(podspec)
    config.github_file_prefix_configured = true
  end
  unless config.swift_version_configured
    trunk_swift_build = podspec.attributes_hash['pushed_with_swift_version']
    config.swift_version = trunk_swift_build if trunk_swift_build
    config.swift_version_configured = true
  end
end

.create_podspec(podspec_path) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/jazzy/podspec_documenter.rb', line 37

def self.create_podspec(podspec_path)
  case podspec_path
  when Pathname, String
    require 'cocoapods'
    Pod::Specification.from_file(podspec_path)
  end
end

Instance Method Details

#sourcekitten_output(config) ⇒ Object

Build documentation from the given options

Parameters:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/jazzy/podspec_documenter.rb', line 15

def sourcekitten_output(config)
  installation_root = Pathname(Dir.mktmpdir(['jazzy', podspec.name]))
  installation_root.rmtree if installation_root.exist?
  Pod::Config.instance.with_changes(installation_root: installation_root,
                                    verbose: false) do
    sandbox = Pod::Sandbox.new(Pod::Config.instance.sandbox_root)
    installer = Pod::Installer.new(sandbox, podfile(config))
    installer.install!
    stdout = Dir.chdir(sandbox.root) do
      targets = installer.pod_targets
                         .select { |pt| pt.pod_name == podspec.root.name }
                         .map(&:label)

      targets.map do |t|
        args = %W[doc --module-name #{podspec.module_name} -- -target #{t}]
        SourceKitten.run_sourcekitten(args)
      end
    end
    stdout.reduce([]) { |a, s| a + JSON.parse(s) }.to_json
  end
end