class Pod::Lockfile

Constants

PODFILE_LOCK

Public Instance Methods

merge_dependencies(links, before, after) click to toggle source

Will merge the DEPENDENCIES of the Podfile.lock before a link and after a link

@param links the installed links @param before the DEPENDENCIES in the Podfile.lock before the link occurs @param after the DEPENDENCIES after the link (includes new link that we want to filter out)

@returns the merged DEPENDENCIES replacing any links that were added with their previous value

# File lib/pod/lockfile.rb, line 157
def merge_dependencies(links, before, after)
  links.each do |link|
    before_index = find_dependency_index before, link
    after_index = find_dependency_index after, link
    unless before_index.nil? || after_index.nil?
      after[after_index] = before[before_index]
    end
  end
  return after
end
merge_hashes(links, before, after) click to toggle source

Will merge the hashes of the Podfile.lock before a link and after a link

@param links the installed links @param before the hash in the Podfile.lock before the link occurs @param after the hash after the link (includes new link that we want to filter out)

@returns the merged hash replacing any links that were added with their previous value

# File lib/pod/lockfile.rb, line 177
def merge_hashes(links, before, after)
  if before.nil?
    return after
  end
  links.each do |link|
    if before.has_key?(link)
      after[link] = before[link]
    else
      if after.has_key?(link)
        after.delete(link)
      end
    end
  end
  return after
end
merge_pods(links, before, after) click to toggle source
# File lib/pod/lockfile.rb, line 110
def merge_pods(links, before, after)
  links.each do |link|
    before_index = find_pod_index before, link
    after_index = find_pod_index after, link
    unless before_index.nil? || after_index.nil?
      
      # get previous value
      after_value = after[after_index]

      # update new value
      after[after_index] = before[before_index]

      # iterate and update all dependencies of previous value
      if after_value.is_a?(Hash)

        # clean all deps that may have been added as new deps
        after_value[after_value.keys[0]].each do |key|
          # key: CocoaLumberjack/Core or CocoaLumberjack/Extensions (= 1.9.2)
          key_desc = key.split(" (", 2)[0]

          inner_after_index = find_pod_index after, key_desc
          inner_before_index = find_pod_index before, key_desc
          
          unless inner_before_index.nil? && inner_after_index.nil?
            after[inner_after_index] = before[inner_before_index]
          else 
            # if it was removed in the new deps
            unless before_index.nil?
              after.insert(before_index, before[before_index])
            end
          end   
        end
      end
    end
  end
  return after
end
real_write_to_disk(path)
Alias for: write_to_disk
write_to_disk(path) click to toggle source

Hook the Podfile.lock file generation to allow us to filter out the links added to the Podfile.lock. The logic here is to replace the new Podfile.lock link content with what existed before the link was added. Currently, this is called for both Podfile.lock and Manifest.lock file so we only want to alter the Podfile.lock

@param path path to write the .lock file to

# File lib/pod/lockfile.rb, line 27
def write_to_disk(path)
  
  # code here mimics the original method but with link filtering
  filename = File.basename(path)
  path.dirname.mkpath unless path.dirname.exist?
  yaml = to_link_yaml
  File.open(path, 'w') { |f| f.write(yaml) }
  self.defined_in_file = path
end
Also aliased as: real_write_to_disk

Private Instance Methods

find_dependency_index(dependencies, name) click to toggle source

Find the index in the dependency array based on the link name. The dependency array also contains version/path information so we need to massage the dependency value for comparison. Dependencies are in the following format:

Name (requirements)

Example: Alamofire (= 1.1.3) Quick (from `github.com/Quick/Quick`, tag `v0.2.2`)

@param dependencies the array to search @param name the name of the dependency to find

@returns the index of nil

# File lib/pod/lockfile.rb, line 238
def find_dependency_index(dependencies, name)
  dependencies.index { |dependency| 
    dependency.split(" (", 2)[0] == name
  }
end
find_pod_index(pods, name) click to toggle source

Find the index in the pod array based on the link name. The pod array also contains version/path information so we need to massage the pod value for comparison. Pods are in the following format:

Name (requirements)

Example: Alamofire (= 1.1.3)

@param pods the array to search @param name the name of the pod to find

NOTE: the pods in the array can be strings or hashes, so we will check for both

@return the index of nil

# File lib/pod/lockfile.rb, line 212
def find_pod_index(pods, name)
  pods.index { |pod|
    desc = pod
    if pod.is_a?(Hash)
      desc = pod.keys[0]
    end
    desc.split(" (", 2)[0] == name
  }
end