Method: Xcodeproj::Config#to_hash

Defined in:
lib/xcodeproj/config.rb

#to_hash(prefix = nil) ⇒ Hash Also known as: to_h

Note:

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`).

Returns:

  • (Hash)

    The hash representation



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/xcodeproj/config.rb', line 122

def to_hash(prefix = nil)
  list = []
  list += other_linker_flags[:simple].to_a.sort
  modifiers = {
    :frameworks => '-framework ',
    :weak_frameworks => '-weak_framework ',
    :libraries => '-l',
    :arg_files => '@',
    :force_load => '-force_load',
  }
  [:libraries, :frameworks, :weak_frameworks, :arg_files, :force_load].each do |key|
    modifier = modifiers[key]
    sorted = other_linker_flags[key].to_a.sort
    if key == :force_load
      list += sorted.map { |l| %(#{modifier} #{l}) }
    else
      list += sorted.map { |l| %(#{modifier}"#{l}") }
    end
  end

  result = attributes.dup
  result['OTHER_LDFLAGS'] = list.join(' ') unless list.empty?
  result.reject! { |_, v| INHERITED.any? { |i| i == v.to_s.strip } }

  result = @includes.map do |incl|
    path = File.expand_path(incl, @filepath.dirname)
    if File.readable? path
      Xcodeproj::Config.new(path).to_hash
    else
      {}
    end
  end.inject(&:merge).merge(result) unless @filepath.nil? || @includes.empty?

  if prefix
    Hash[result.map { |k, v| [prefix + k, v] }]
  else
    result
  end
end