Class: Pod::Generator::TargetEnvironmentHeader
- Inherits:
-
Object
- Object
- Pod::Generator::TargetEnvironmentHeader
- Defined in:
- lib/cocoapods/generator/target_environment_header.rb
Overview
Generates a header which allows to inspect at compile time the installed pods and the installed specifications of a pod.
Example output:
#define COCOAPODS_POD_AVAILABLE_ObjectiveSugar 1
#define COCOAPODS_VERSION_MAJOR_ObjectiveSugar 0
#define COCOAPODS_VERSION_MINOR_ObjectiveSugar 6
#define COCOAPODS_VERSION_PATCH_ObjectiveSugar 2
Example usage:
#ifdef COCOAPODS
#ifdef COCOAPODS_POD_AVAILABLE_ObjectiveSugar
#import "ObjectiveSugar.h"
#endif
#else
// Non CocoaPods code
#endif
Instance Attribute Summary collapse
-
#specs_by_configuration ⇒ Hash{String => LocalPod}
readonly
The specifications installed for the target by build configuration name.
Instance Method Summary collapse
-
#generate ⇒ void
Generates and saves the file.
-
#initialize(specs_by_configuration) ⇒ TargetEnvironmentHeader
constructor
A new instance of TargetEnvironmentHeader.
- #save_as(path) ⇒ Object
Constructor Details
#initialize(specs_by_configuration) ⇒ TargetEnvironmentHeader
Returns a new instance of TargetEnvironmentHeader.
33 34 35 |
# File 'lib/cocoapods/generator/target_environment_header.rb', line 33 def initialize(specs_by_configuration) @specs_by_configuration = specs_by_configuration end |
Instance Attribute Details
#specs_by_configuration ⇒ Hash{String => LocalPod} (readonly)
Returns the specifications installed for the target by build configuration name.
29 30 31 |
# File 'lib/cocoapods/generator/target_environment_header.rb', line 29 def specs_by_configuration @specs_by_configuration end |
Instance Method Details
#generate ⇒ void
This method returns an undefined value.
Generates and saves the file.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cocoapods/generator/target_environment_header.rb', line 44 def generate result = "\n#{notice}\n\n" common_specs = common_specs(specs_by_configuration) common_specs.each { |spec| result << spec_defines(spec) } specs_by_config = specs_scoped_by_configuration(common_specs, specs_by_configuration) specs_by_config.each do |config, specs| result << "// #{config} build configuration\n" result << "#ifdef #{config.gsub(/[^a-zA-Z0-9_]/, '_').upcase}\n\n" specs.each { |spec| result << spec_defines(spec, 1) } result << "#endif\n" end result end |
#save_as(path) ⇒ Object
59 60 61 |
# File 'lib/cocoapods/generator/target_environment_header.rb', line 59 def save_as(path) path.open('w') { |header| header.write(generate) } end |