Class: Pod::Generator::PrefixHeader

Inherits:
Header
  • Object
show all
Defined in:
lib/cocoapods/generator/prefix_header.rb

Overview

Generates a prefix header file for a Pods library. The prefix header is generated according to the platform of the target and the pods.

According to the platform the prefix header imports UIKit/UIKit.h or Cocoa/Cocoa.h.

Instance Attribute Summary collapse

Attributes inherited from Header

#imports, #module_imports, #platform

Instance Method Summary collapse

Methods inherited from Header

#save_as

Constructor Details

#initialize(file_accessors, platform) ⇒ PrefixHeader

Initialize a new instance

Parameters:

  • file_accessors (Array<FileAccessor>)

    @see #file_accessors

  • platform (Platform)

    @see Header#platform



23
24
25
26
# File 'lib/cocoapods/generator/prefix_header.rb', line 23

def initialize(file_accessors, platform)
  @file_accessors = file_accessors
  super platform
end

Instance Attribute Details

#file_accessorsArray<FileAccessor> (readonly)

Returns The file accessors for which to generate the prefix header.

Returns:

  • (Array<FileAccessor>)

    The file accessors for which to generate the prefix header.



13
14
15
# File 'lib/cocoapods/generator/prefix_header.rb', line 13

def file_accessors
  @file_accessors
end

Instance Method Details

#generateString

TODO:

Subspecs can specify prefix header information too.

TODO:

Check to see if we have a similar duplication issue with file_accessor.prefix_header.

Note:

Only unique prefix_header_contents are added to the prefix header.

Generates the contents of the prefix header according to the platform and the pods.

Returns:

  • (String)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/cocoapods/generator/prefix_header.rb', line 40

def generate
  result = super

  unique_prefix_header_contents = file_accessors.map do |file_accessor|
    file_accessor.spec_consumer.prefix_header_contents
  end.compact.uniq

  unique_prefix_header_contents.each do |prefix_header_contents|
    result << prefix_header_contents
    result << "\n"
  end

  file_accessors.map(&:prefix_header).compact.uniq.each do |prefix_header|
    result << Pathname(prefix_header).read
  end

  result
end