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.
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.
44 45 46 47 48 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 44 def initialize(xcconfig_hash_or_file = {}) @attributes = {} @includes = [] merge!(extract_hash(xcconfig_hash_or_file)) 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 |
Instance Method Details
#==(other) ⇒ Object
54 55 56 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 54 def ==(other) other.attributes == attributes end |
#dup ⇒ Config
Returns A copy of the receiver.
152 153 154 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 152 def dup HMap::XCConfig.new(to_hash.dup) end |
#inspect ⇒ Object
50 51 52 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 50 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.
146 147 148 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 146 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.
129 130 131 132 133 134 135 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 129 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.
85 86 87 88 89 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 85 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`).
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 100 def to_hash(prefix = nil) list = [] 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.
71 72 73 74 75 |
# File 'lib/hmap/xc/target/xcconfig.rb', line 71 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 |