class Pod::DeployTransformer

Attributes

lockfile[RW]
metadata[RW]
sandbox[RW]

Public Class Methods

new(lockfile, sandbox) click to toggle source
# File lib/cocoapods-deploy/deploy_transformer.rb, line 8
def initialize(lockfile, sandbox)
  @lockfile = lockfile
  @sandbox = sandbox
  @metadata = Source::Metadata.new({'prefix_lengths' => [1, 1, 1]})
end

Public Instance Methods

transform_dependency_name(name) click to toggle source
# File lib/cocoapods-deploy/deploy_transformer.rb, line 21
def transform_dependency_name(name)
  dependency_hash = transform_dependency(name)
  parse_dependency(dependency_hash)
end
transform_podfile(podfile) click to toggle source
# File lib/cocoapods-deploy/deploy_transformer.rb, line 14
def transform_podfile(podfile)
  internal_hash = podfile.to_hash
  new_hash = transform_internal_hash(internal_hash)

  Podfile.from_hash(new_hash, podfile.defined_in_file)
end

Private Instance Methods

collect_podspec_dependencies(name_or_hash) click to toggle source
# File lib/cocoapods-deploy/deploy_transformer.rb, line 73
def collect_podspec_dependencies(name_or_hash)
  dependency = parse_dependency(name_or_hash)
  specification = @sandbox.specification(dependency.root_name)

  dependencies = specification.dependencies.map do |dep|
    begin
      transform_dependency(dep.name)
    rescue Informative
      nil
    end
  end if specification

  dependencies.select { |dep|
    dep != nil
  }
end
parse_dependency(name_or_hash) click to toggle source
# File lib/cocoapods-deploy/deploy_transformer.rb, line 58
def parse_dependency(name_or_hash)
  if name_or_hash.is_a?(Hash)
    name = name_or_hash.keys.first
    requirements = name_or_hash.values.first
    Dependency.new(name, *requirements)
  else
    Dependency.new(name_or_hash)
  end
end
podspec_url(pod, version) click to toggle source
# File lib/cocoapods-deploy/deploy_transformer.rb, line 68
def podspec_url(pod, version)
  path_fragment = metadata.path_fragment(pod)
  "{root-url}/#{path_fragment}/#{version}/#{pod}"
end
transform_dependency(name_or_hash) click to toggle source
# File lib/cocoapods-deploy/deploy_transformer.rb, line 90
def transform_dependency(name_or_hash)
  dependency = parse_dependency(name_or_hash)
  pod = dependency.name
  checkout_options = @lockfile.checkout_options_for_pod_named(pod)

  unless checkout_options
    root_pod = dependency.root_name
    version = @lockfile.version(pod)
    raise Informative, "Missing dependency \"#{pod}\" in Lockfile please run `pod install` or `pod update`." unless version

    ({ "#{pod}" => [{ :podspec => podspec_url(root_pod, version) }] })
  else
    ({ "#{pod}" => [checkout_options] })
  end
end
transform_internal_hash(hash) click to toggle source
# File lib/cocoapods-deploy/deploy_transformer.rb, line 28
def transform_internal_hash(hash)
  targets = hash["target_definitions"]
  targets.map do |target|
    transform_target_definition_hash(target)
  end if targets

  hash
end
transform_target_definition_hash(hash) click to toggle source
# File lib/cocoapods-deploy/deploy_transformer.rb, line 37
def transform_target_definition_hash(hash)
  dependencies = hash["dependencies"]
  hash["dependencies"] = dependencies.map do |dep|
    transform_dependency(dep)
  end if dependencies

  #Duplicate this to prevent infinte loop
  dependencies = hash["dependencies"]
  dependencies.dup.map do |dep|
    podspec_dependencies = collect_podspec_dependencies(dep)
    hash["dependencies"].concat(podspec_dependencies) if podspec_dependencies
  end if dependencies && @sandbox

  children = hash["children"]
  hash["children"] = children.map do |target|
    transform_target_definition_hash(target)
  end if children

  hash
end