Class: ProjectGen::HeadersStore

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-project-gen/gen/build/headers_store.rb

Overview

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

Defined Under Namespace

Classes: SEARCH_PATHS_KEY

Instance Attribute Summary collapse

Adding headers collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandbox, relative_path, visibility_scope) ⇒ 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.

  • visibility_scope (Symbol)

    the header visibility scope to use in this store. Can be ‘:private` or `:public`.



36
37
38
39
40
41
42
# File 'lib/cocoapods-project-gen/gen/build/headers_store.rb', line 36

def initialize(sandbox, relative_path, visibility_scope)
  @sandbox       = sandbox
  @relative_path = relative_path
  @search_paths  = []
  @search_paths_cache = {}
  @visibility_scope = visibility_scope
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.



25
26
27
# File 'lib/cocoapods-project-gen/gen/build/headers_store.rb', line 25

def sandbox
  @sandbox
end

Instance Method Details

#add_file(namespace, relative_header_path, ln: false, mkdir: true, source: false) ⇒ Pathname

Note:

This method does not add the file to the search paths.

Adds a header to the directory.

Parameters:

  • namespace (Pathname)

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

  • relative_header_path (Pathname)

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

Returns:

  • (Pathname)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/cocoapods-project-gen/gen/build/headers_store.rb', line 83

def add_file(namespace, relative_header_path, ln: false, mkdir: true, source: false)
  namespaced_path = root(source: source) + namespace
  namespaced_path.mkpath if mkdir

  absolute_source = (sandbox.root + relative_header_path)
  source = absolute_source.relative_path_from(namespaced_path)
  full_namespaced_path = namespaced_path.join(relative_header_path.basename)
  return full_namespaced_path if full_namespaced_path.exist?

  if ln
    if Gem.win_platform?
      FileUtils.ln(absolute_source, namespaced_path, force: true)
    else
      FileUtils.ln_sf(source, namespaced_path)
    end
  else
    FileUtils.cp_r(absolute_source, namespaced_path)
  end
  full_namespaced_path
end

#add_files(namespace, relative_header_paths, ln: false, source: false) ⇒ Array<Pathname>

Note:

This method does not add 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>)


62
63
64
65
66
67
# File 'lib/cocoapods-project-gen/gen/build/headers_store.rb', line 62

def add_files(namespace, relative_header_paths, ln: false, source: false)
  root(source: source).join(namespace).mkpath unless relative_header_paths.empty?
  relative_header_paths.map do |relative_header_path|
    add_file(namespace, relative_header_path, ln: ln, mkdir: false, source: source)
  end
end

#root(source: false) ⇒ Pathname

Returns the absolute path of this header directory.

Returns:

  • (Pathname)

    the absolute path of this header directory.



13
14
15
16
17
18
19
20
21
# File 'lib/cocoapods-project-gen/gen/build/headers_store.rb', line 13

def root(source: false)
  root = if source
           sandbox.sources_root
         else
           sandbox.headers_root
         end

  root + @relative_path
end