Class: Pod::Sandbox::HeadersStore

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/sandbox/headers_store.rb

Overview

Provides support for managing a header directory. It also keeps track of the header search paths.

Instance Attribute Summary collapse

Adding headers collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, relative_path) ⇒ HeadersStore

Returns a new instance of HeadersStore.

Parameters:

  • @see (Sandbox)

    sandbox

  • relative_path (String)

    the relative path to the sandbox root and hence to the Pods project.



23
24
25
26
27
# File 'lib/cocoapods/sandbox/headers_store.rb', line 23

def initialize(sandbox, relative_path)
  @sandbox       = sandbox
  @relative_path = relative_path
  @search_paths  = []
end

Instance Attribute Details

#sandboxSandbox (readonly)

Returns the sandbox where this header directory is stored.

Returns:

  • (Sandbox)

    the sandbox where this header directory is stored.



15
16
17
# File 'lib/cocoapods/sandbox/headers_store.rb', line 15

def sandbox
  @sandbox
end

Instance Method Details

#add_files(namespace, relative_header_paths, platform) ⇒ Array<Pathname>

Note:

This method adds the files to the search paths.

Adds headers to the directory.

Parameters:

  • namespace (Pathname)

    the path where the header file should be stored relative to the headers directory.

  • relative_header_paths (Array<Pathname>)

    the path of the header file relative to the Pods project (‘PODS_ROOT` variable of the xcconfigs).

Returns:

  • (Array<Pathname>)


73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/cocoapods/sandbox/headers_store.rb', line 73

def add_files(namespace, relative_header_paths, platform)
  add_search_path(namespace, platform)
  namespaced_path = root + namespace
  namespaced_path.mkpath unless File.exist?(namespaced_path)

  relative_header_paths.map do |relative_header_path|
    absolute_source = (sandbox.root + relative_header_path)
    source = absolute_source.relative_path_from(namespaced_path)
    Dir.chdir(namespaced_path) do
      FileUtils.ln_sf(source, relative_header_path.basename)
    end
    namespaced_path + relative_header_path.basename
  end
end

#add_search_path(path, platform) ⇒ void

This method returns an undefined value.

Adds an header search path to the sandbox.

Parameters:

  • path (Pathname)

    the path tho add.

  • platform (String)

    the platform the search path applies to



98
99
100
# File 'lib/cocoapods/sandbox/headers_store.rb', line 98

def add_search_path(path, platform)
  @search_paths << { :platform => platform, :path => (Pathname.new(@relative_path) + path) }
end

#implode!void

This method returns an undefined value.

Removes the directory as it is regenerated from scratch during each installation.



49
50
51
# File 'lib/cocoapods/sandbox/headers_store.rb', line 49

def implode!
  root.rmtree if root.exist?
end

#rootPathname

Returns the absolute path of this header directory.

Returns:

  • (Pathname)

    the absolute path of this header directory.



9
10
11
# File 'lib/cocoapods/sandbox/headers_store.rb', line 9

def root
  sandbox.headers_root + @relative_path
end

#search_paths(platform) ⇒ Array<String>

Returns All the search paths of the header directory in xcconfig format. The paths are specified relative to the pods root with the ‘$PODS_ROOT` variable.

Parameters:

  • platform (Platform)

    the platform for which the header search paths should be returned

Returns:

  • (Array<String>)

    All the search paths of the header directory in xcconfig format. The paths are specified relative to the pods root with the ‘$PODS_ROOT` variable.



37
38
39
40
41
42
# File 'lib/cocoapods/sandbox/headers_store.rb', line 37

def search_paths(platform)
  platform_search_paths = @search_paths.select { |entry| entry[:platform] == platform }

  headers_dir = root.relative_path_from(sandbox.root).dirname
  ["${PODS_ROOT}/#{headers_dir}/#{@relative_path}"] + platform_search_paths.uniq.map { |entry| "${PODS_ROOT}/#{headers_dir}/#{entry[:path]}" }
end