Class: HMap::XCConfig
- Inherits:
-
Object
- Object
- HMap::XCConfig
- Defined in:
- lib/hmap/xc/target/xcconfig.rb
Overview
This class holds the data for a Xcode build settings file (xcconfig) and provides support for serialization.
Instance Attribute Summary collapse
-
#attributes ⇒ Hash{String => String}
The attributes of the settings file excluding frameworks, weak_framework and libraries.
-
#includes_paths ⇒ Array
The list of the configuration files included by this configuration file (`#include “SomeConfig”`).
Serialization collapse
-
#save_as(pathname, prefix = nil) ⇒ void
Writes the serialized representation of the internal data to the given path.
-
#to_hash(prefix = nil) ⇒ Hash
(also: #to_h)
The hash representation of the xcconfig.
-
#to_s(prefix = nil) ⇒ String
Sorts the internal data by setting name and serializes it in the xcconfig format.
Merging collapse
-
#dup ⇒ Config
A copy of the receiver.
-
#merge(config) ⇒ Config
Creates a new #Config with the data of the receiver merged with the given xcconfig representation.
-
#merge!(xcconfig) ⇒ void
(also: #<<)
Merges the given xcconfig representation in the receiver.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(xcconfig_hash_or_file = {}) ⇒ Hash{Symbol => Set<String>}
constructor
The other linker flags by key.
- #inspect ⇒ Object
Constructor Details
#initialize(xcconfig_hash_or_file = {}) ⇒ Hash{Symbol => Set<String>}
Returns The other linker flags by key. Xcodeproj handles them in a dedicated way to prevent duplication of the libraries and of the frameworks.
49 50 51 52 53 54 55 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 49 def initialize(xcconfig_hash_or_file = {}) @attributes = {} @includes = [] @include_attributes = {} merge!(extract_hash(xcconfig_hash_or_file)) @includes_paths = @includes.map { |i| File.(i, @filepath.dirname) } end |
Instance Attribute Details
#attributes ⇒ Hash{String => String}
Returns The attributes of the settings file excluding frameworks, weak_framework and libraries.
38 39 40 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 38 def attributes @attributes end |
#includes_paths ⇒ Array
Returns The list of the configuration files included by this configuration file (`#include “SomeConfig”`).
43 44 45 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 43 def includes_paths @includes_paths end |
Instance Method Details
#==(other) ⇒ Object
61 62 63 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 61 def ==(other) other.attributes == attributes && other.includes_paths = @includes_paths end |
#dup ⇒ Config
Returns A copy of the receiver.
157 158 159 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 157 def dup HMap::XCConfig.new(to_hash.dup) end |
#inspect ⇒ Object
57 58 59 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 57 def inspect to_hash.inspect end |
#merge(config) ⇒ Config
Creates a new #Config with the data of the receiver merged with the given xcconfig representation.
151 152 153 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 151 def merge(config) dup.tap { |x| x.merge!(config) } end |
#merge!(xcconfig) ⇒ void Also known as: <<
The logic to normalize an hash should be extracted and the initializer should not call this method.
If a key in the given hash already exists in the internal data then its value is appended.
This method returns an undefined value.
Merges the given xcconfig representation in the receiver.
134 135 136 137 138 139 140 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 134 def merge!(xcconfig) if xcconfig.is_a? XCConfig merge_attributes!(xcconfig.attributes) else merge_attributes!(xcconfig.to_hash) end end |
#save_as(pathname, prefix = nil) ⇒ void
This method returns an undefined value.
Writes the serialized representation of the internal data to the given path.
92 93 94 95 96 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 92 def save_as(pathname, prefix = nil) return if File.exist?(pathname) && (XCConfig.new(pathname) == self) pathname.open('w') { |file| file << to_s(prefix) } end |
#to_hash(prefix = nil) ⇒ Hash Also known as: to_h
All the values are sorted to have a consistent output in Ruby 1.8.7.
The hash representation of the xcconfig. The hash includes the frameworks, the weak frameworks, the libraries and the simple other linker flags in the `Other Linker Flags` (`OTHER_LDFLAGS`).
107 108 109 110 111 112 113 114 115 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 107 def to_hash(prefix = nil) result = attributes.dup result.reject! { |_, v| INHERITED.any? { |i| i == v.to_s.strip } } if prefix Hash[result.map { |k, v| [prefix + k, v] }] else result end end |
#to_s(prefix = nil) ⇒ String
Sorts the internal data by setting name and serializes it in the xcconfig format.
78 79 80 81 82 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 78 def to_s(prefix = nil) include_lines = @includes.map { |path| "#include \"#{normalized_xcconfig_path(path)}\"" } settings = to_hash(prefix).sort_by(&:first).map { |k, v| "#{k} = #{v}".strip } (include_lines + settings).join("\n") << "\n" end |