Skip to content
This repository
Fetching contributors…

Cannot retrieve contributors at this time

file 84 lines (67 sloc) 2.322 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 77 78 79 80 81 82 83 84
require 'ruby-debug'
require 'fileutils'

module Pod
  class Sandbox
    attr_reader :root

    HEADERS_DIR = "Headers"

    def initialize(path)
      @root = Pathname.new(path)
      @header_search_paths = [HEADERS_DIR]

      FileUtils.mkdir_p(@root)
    end

    def implode
      root.rmtree
    end

    def headers_root
      root + HEADERS_DIR
    end

    def project_path
      root + "Pods.xcodeproj"
    end

    def add_header_file(namespace_path, relative_header_path)
      namespaced_header_path = headers_root + namespace_path
      namespaced_header_path.mkpath unless File.exist?(namespaced_header_path)
      source = (root + relative_header_path).relative_path_from(namespaced_header_path)
      Dir.chdir(namespaced_header_path) { FileUtils.ln_sf(source, relative_header_path.basename)}
      @header_search_paths << namespaced_header_path.relative_path_from(root)
      namespaced_header_path + relative_header_path.basename
    end

    def add_header_files(namespace_path, relative_header_paths)
      relative_header_paths.map { |path| add_header_file(namespace_path, path) }
    end

    def header_search_paths
      @header_search_paths.uniq.map { |path| "${PODS_ROOT}/#{path}" }
    end

    def prepare_for_install
      headers_root.rmtree if headers_root.exist?
    end

    def path_for_podspec_in_project(pod_name)
      Dir[root + "#{pod_name}/*.podspec"].first
    end

    def podspec_exists_in_project?(pod_name)
      !path_for_podspec_in_project(pod_name).nil?
    end

    def path_for_local_podspec(pod_name)
      Dir[root + "Local Podspecs/#{pod_name}.podspec"].first
    end

    def podspec_exists_in_local_dir?(pod_name)
      !path_for_local_podspec(pod_name).nil?
    end

    def podspec_for_name(name)
      # debugger
      if podspec_exists_in_project?(name)
        Pathname.new(path_for_podspec_in_project(name))
      elsif podspec_exists_in_local_dir?(name)
        Pathname.new(path_for_local_podspec(name))
      else
        return nil
        # raise "No podspec found for #{name}. Please specify the :podspec option instead to point to a podspec for the #{name} Pod"
      end
    end

    def installed_pod_named(name, platform)
      if spec_path = podspec_for_name(name)
        LocalPod.from_podspec(spec_path, self, platform)
      end
    end
  end
end
Something went wrong with that request. Please try again.