Class: HMap::XcodeprojHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/hmap/xc/target/xcconfig_helper.rb

Overview

A collection of xcodeproj Helper functions used throughout hmap.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ XcodeprojHelper

Returns a new instance of XcodeprojHelper.



14
15
16
17
18
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 14

def initialize(path)
  xc = Pathname(path)
  @xcconfig_path = xc
  @xcconfig = XCConfig.new(xc)
end

Instance Attribute Details

#xcconfig_pathObject (readonly)

Returns the value of attribute xcconfig_path.



12
13
14
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 12

def xcconfig_path
  @xcconfig_path
end

Instance Method Details

#add_build_setting(key, value, use_origin) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 36

def add_build_setting(key, value, use_origin)
  return if value.nil?

  if key.start_with?(HMAP_XCKEY_START)
    @xcconfig.attributes[key] = value
  else
    save_origin = save_build_setting(key)
    e_value = value
    e_value = "${#{save_xckey(key)}} #{e_value} " if use_origin && !save_origin.nil?
    @xcconfig.attributes[hmap_xckey(key)] = e_value
    @xcconfig.attributes[key] = "${#{hmap_xckey(key)}}"
  end
end

#add_build_settings(settings, use_origin) ⇒ Object



30
31
32
33
34
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 30

def add_build_settings(settings, use_origin)
  settings.each do |key, value|
    add_build_setting(key.to_s, value, use_origin)
  end
end

#add_build_settings_and_save(settings, use_origin: true) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 20

def add_build_settings_and_save(settings, use_origin: true)
  add_build_settings(settings, use_origin)
  if use_origin
    remove_build_settings(settings)
  else
    save_build_settings(settings)
  end
  save_as
end

#remove_build_setting(setting) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 78

def remove_build_setting(setting)
  save_origin = @xcconfig.attributes[save_xckey(setting)]
  origin = @xcconfig.attributes[setting]
  @xcconfig.attributes.delete(setting) if save_origin.nil? && !origin.nil? && origin.include?(hmap_xckey(setting))
  @xcconfig.attributes[setting] = save_origin unless save_origin.nil?
  @xcconfig.attributes.delete(hmap_xckey(setting))
  @xcconfig.attributes.delete(save_xckey(setting))
end

#remove_build_settings(settings) ⇒ Object



73
74
75
76
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 73

def remove_build_settings(settings)
  settings ||= []
  settings.each { |setting| remove_build_setting(setting) }
end

#remove_build_settings_and_saveObject



64
65
66
67
68
69
70
71
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 64

def remove_build_settings_and_save
  hmap_ks = @xcconfig.attributes.keys.each_with_object([]) do |key, sum|
    sum << key[HMAP_XCKEY_START.length..] if key.start_with?(HMAP_XCKEY_START)
    sum << key[SAVE_XCKEY_START.length..] if key.start_with?(SAVE_XCKEY_START)
  end.compact
  remove_build_settings(hmap_ks)
  save_as
end

#save_as(path = nil) ⇒ Object



87
88
89
90
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 87

def save_as(path = nil)
  path = xcconfig_path if path.nil?
  @xcconfig.save_as(path)
end

#save_build_setting(key) ⇒ Object



55
56
57
58
59
60
61
62
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 55

def save_build_setting(key)
  origin = @xcconfig.attributes[key]
  if origin.nil? || !origin.include?(hmap_xckey(key))
    @xcconfig.attributes[save_xckey(key)] = origin unless origin.nil?
    @xcconfig.attributes.delete(key)
  end
  @xcconfig.attributes[save_xckey(key)]
end

#save_build_settings(settings) ⇒ Object



50
51
52
53
# File 'lib/hmap/xc/target/xcconfig_helper.rb', line 50

def save_build_settings(settings)
  settings ||= []
  settings.each { |key| save_build_setting(key) }
end