Class: Pod::Generator::Header

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

Overview

Generates a header file.

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

Direct Known Subclasses

PrefixHeader, UmbrellaHeader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform) ⇒ Header

Initialize a new instance

Parameters:

  • platform (Symbol)

    @see platform



27
28
29
30
31
# File 'lib/cocoapods/generator/header.rb', line 27

def initialize(platform)
  @platform = platform
  @imports = []
  @module_imports = []
end

Instance Attribute Details

#importsArray<String>

Returns The list of the headers to import.

Returns:

  • (Array<String>)

    The list of the headers to import.



16
17
18
# File 'lib/cocoapods/generator/header.rb', line 16

def imports
  @imports
end

#module_importsArray<String>

Returns The list of the modules to import.

Returns:

  • (Array<String>)

    The list of the modules to import.



20
21
22
# File 'lib/cocoapods/generator/header.rb', line 20

def module_imports
  @module_imports
end

#platformSymbol (readonly)

Returns the platform for which the prefix header will be generated.

Returns:

  • (Symbol)

    the platform for which the prefix header will be generated.



12
13
14
# File 'lib/cocoapods/generator/header.rb', line 12

def platform
  @platform
end

Instance Method Details

#generateString

Note:

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.

Generates the contents of the header according to the platform.

Returns:

  • (String)


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

def generate
  result = ''
  result << generate_platform_import_header

  result << "\n"

  imports.each do |import|
    result << %(#import "#{import}"\n)
  end

  unless module_imports.empty?
    module_imports.each do |import|
      result << %(\n@import #{import})
    end
    result << "\n"
  end

  result
end

#save_as(path) ⇒ void

This method returns an undefined value.

Generates and saves the header to the given path.

Parameters:

  • path (Pathname)

    The path where the header should be stored.



68
69
70
# File 'lib/cocoapods/generator/header.rb', line 68

def save_as(path)
  path.open('w') { |header| header.write(generate) }
end