Class: Pod::Generator::PrefixHeader
- Inherits:
-
Object
- Object
- Pod::Generator::PrefixHeader
- 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
-
#file_accessors ⇒ Array<FileAccessor>
readonly
The file accessors for which to generate the prefix header.
-
#imports ⇒ Array<String>
readonly
The list of the headers to import (with quotes).
-
#platform ⇒ Platform
readonly
The platform for which the prefix header will be generated.
Instance Method Summary collapse
-
#generate ⇒ String
Generates the contents of the prefix header according to the platform and the pods.
-
#initialize(file_accessors, platform) ⇒ PrefixHeader
constructor
A new instance of PrefixHeader.
-
#save_as(path) ⇒ void
Generates and saves the prefix header to the given path.
Constructor Details
#initialize(file_accessors, platform) ⇒ PrefixHeader
Returns a new instance of PrefixHeader.
28 29 30 31 32 |
# File 'lib/cocoapods/generator/prefix_header.rb', line 28 def initialize(file_accessors, platform) @file_accessors = file_accessors @platform = platform @imports = [] end |
Instance Attribute Details
#file_accessors ⇒ Array<FileAccessor> (readonly)
Returns 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 |
#imports ⇒ Array<String> (readonly)
Returns The list of the headers to import (with quotes).
23 24 25 |
# File 'lib/cocoapods/generator/prefix_header.rb', line 23 def imports @imports end |
#platform ⇒ Platform (readonly)
Returns the platform for which the prefix header will be generated.
18 19 20 |
# File 'lib/cocoapods/generator/prefix_header.rb', line 18 def platform @platform end |
Instance Method Details
#generate ⇒ String
Subspecs can specify prefix header information too.
Check to see if we have a similar duplication issue with file_accessor.prefix_header.
If the platform is iOS an import call to UIKit/UIKit.h is added to the top of the prefix header. For OS X Cocoa/Cocoa.h is imported.
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.
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 |
# File 'lib/cocoapods/generator/prefix_header.rb', line 50 def generate result = "#ifdef __OBJC__\n" result << "#import #{platform == :ios ? '<UIKit/UIKit.h>' : '<Cocoa/Cocoa.h>'}\n" result << "#endif\n" imports.each do |import| result << %(\n#import "#{import}") end unique_prefix_header_contents = file_accessors.map do |file_accessor| file_accessor.spec_consumer.prefix_header_contents end.compact.uniq result << "\n" unique_prefix_header_contents.each do |prefix_header_contents| result << prefix_header_contents result << "\n" end file_accessors.each do |file_accessor| if prefix_header = file_accessor.prefix_header result << Pathname(prefix_header).read end end result end |
#save_as(path) ⇒ void
This method returns an undefined value.
Generates and saves the prefix header to the given path.
85 86 87 |
# File 'lib/cocoapods/generator/prefix_header.rb', line 85 def save_as(path) path.open('w') { |header| header.write(generate) } end |