class Pod::Command::Dependsay

Attributes

output[R]

Public Class Methods

arguments() click to toggle source
Calls superclass method
# File lib/cocoapods-dependsay/command/dependsay.rb, line 19
def self.arguments
  [
    CLAide::Argument.new('PODSPEC', false)
  ].concat(super)
end
new(argv) click to toggle source
Calls superclass method
# File lib/cocoapods-dependsay/command/dependsay.rb, line 27
def initialize(argv)
  @output = output_file
  @podspec_name = argv.shift_argument
  @ignore_lockfile = argv.flag?('ignore-lockfile', false)
  @repo_update = argv.flag?('repo-update', false)
  super
end
options() click to toggle source
Calls superclass method
# File lib/cocoapods-dependsay/command/dependsay.rb, line 12
def self.options
  [
    ['--ignore-lockfile', 'Whether the lockfile should be ignored when calculating the dependency graph'],
    ['--repo-update', 'Fetch external podspecs and run `pod repo update` before calculating the dependency graph']
  ].concat(super)
end

Public Instance Methods

data() click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 134
def data
  @data ||= begin
    definitions = []
    relations = []
    pod_to_dependencies.each do |key, value|
      definitions << {
        'type' => 'Class',
        'namespace' => key,
        'circular' => false,
        'line' => 0,
        'lines' => 0
      }
    end

    pod_to_dependencies.each do |key, value|
      value.each do |v|
        relations << {
          'type' => 'Base',
          'resolved_namespace' => pick(v, definitions),
          'caller' => key,
          'circular' => false,
          'lines' => 0
        }
      end
    end

    definitions.each do |value|
      ns = value['namespace']
      relations.each do |v|
        value['lines'] += 1 if [v['caller'], v['resolved_namespace']].include? ns
      end
    end

    definitions.each do |value|
      value['namespace'] = name_transform(value['namespace'])
    end

    relations.each do |value|
      value['resolved_namespace'] = name_transform(value['resolved_namespace'])
      value['caller'] = name_transform(value['caller'])
    end

    data = { 'definitions' => definitions, 'relations' => relations }
    data.to_s.gsub(/=>/, ':')
  end
end
dependencies() click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 87
def dependencies
  @dependencies ||= begin
    analyzer = Installer::Analyzer.new(
      sandbox,
      podfile,
      @ignore_lockfile || @podspec ? nil : config.lockfile
    )

    specs = config.with_changes(skip_repo_update: !@repo_update) do
      analyzer.analyze(@repo_update || @podspec).specs_by_target.values.flatten(1)
    end

    lockfile = Lockfile.generate(podfile, specs, {})
    lockfile.to_hash['PODS']
  end
end
erb(template) click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 77
def erb(template)
  path = resolve_file_path("/views/#{template}.erb")
  file = File.open(path).read
  ERB.new(file).result binding
end
file(path) click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 73
def file(path)
  File.read(resolve_file_path("/public/#{path}"))
end
layout() click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 69
def layout
  'null'
end
name_transform(name) click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 181
def name_transform(name)
  name.instance_of?(String) ? name.gsub(/ \(/,"@").gsub(/\./, "-").gsub(/\)/, "") : name
end
output_file(path = nil) click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 35
def output_file(path = nil)
  File.open(path.nil? ? 'output.html' : path, 'w')
end
output_file_basename() click to toggle source

Basename to use for output files.

# File lib/cocoapods-dependsay/command/dependsay.rb, line 207
def output_file_basename
  return 'Podfile' unless @podspec_name
  File.basename(@podspec_name, File.extname(@podspec_name))
end
pick(key, pool) click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 185
def pick(key, pool)
  pool.each do |v|
    return v['namespace'] if sanitized_pod_name(key) == sanitized_pod_name(v['namespace'])
  end
end
pod_to_dependencies() click to toggle source

Returns a [String: [String]] containing resolved mappings from the name of a pod to an array of the names of its dependencies.

# File lib/cocoapods-dependsay/command/dependsay.rb, line 202
def pod_to_dependencies
  dependencies.map { |d| d.is_a?(Hash) ? d : { d => [] } }.reduce({}) { |combined, individual| combined.merge!(individual) }
end
podfile() click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 104
def podfile
  @podfile ||= begin
    if podspec = @podspec
      platform = podspec.available_platforms.first
      platform_name = platform.name
      platform_version = platform.deployment_target.to_s
      source_urls = Config.instance.sources_manager.all.map(&:url).compact
      Podfile.new do
        install! 'cocoapods', integrate_targets: false, warn_for_multiple_pod_sources: false
        source_urls.each { |u| source(u) }
        platform platform_name, platform_version
        pod podspec.name, podspec: podspec.defined_in_file
        target 'Dependencies'
      end
    else
      verify_podfile_exists!
      config.podfile
    end
  end
end
podfile_dependencies() click to toggle source

Returns a Set of Strings of the names of dependencies specified in the Podfile.

# File lib/cocoapods-dependsay/command/dependsay.rb, line 197
def podfile_dependencies
  Set.new(podfile.target_definitions.values.map { |t| t.dependencies.map { |d| d.name } }.flatten)
end
resolve_file_path(path) click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 83
def resolve_file_path(path)
  File.expand_path("../../../..#{path}", __FILE__)
end
run() click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 58
def run
  UI.title 'Calculating dependencies' do
    dependencies
  end
  output.write(erb(:index))
end
sandbox() click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 125
def sandbox
  if @podspec
    require 'tmpdir'
    Sandbox.new(Dir.mktmpdir)
  else
    config.sandbox
  end
end
sanitized_pod_name(name) click to toggle source

Truncates the input string after a pod's name removing version requirements, etc.

# File lib/cocoapods-dependsay/command/dependsay.rb, line 192
def sanitized_pod_name(name)
  Pod::Dependency.from_string(name).name
end
toolbox?() click to toggle source
# File lib/cocoapods-dependsay/command/dependsay.rb, line 65
def toolbox?
  false
end
validate!() click to toggle source
Calls superclass method
# File lib/cocoapods-dependsay/command/dependsay.rb, line 39
def validate!
  super
  if @podspec_name
    require 'pathname'
    path = Pathname.new(@podspec_name)
    if path.file?
      @podspec = Specification.from_file(path)
    else
      sets = Config
             .instance
             .sources_manager
             .search(Dependency.new(@podspec_name))
      spec = sets && sets.specification
      @podspec = spec && spec.subspec_by_name(@podspec_name)
      raise Informative, "Cannot find `#{@podspec_name}`." unless @podspec
    end
  end
end