Class: Xcodeproj::XCScheme::EnvironmentVariable

Inherits:
XMLElementWrapper show all
Defined in:
lib/xcodeproj/scheme/environment_variables.rb

Overview

This class wraps the EnvironmentVariable node of a .xcscheme XML file. Environment variables are accessible via the NSDictionary returned from

[NSProcessInfo processInfo

environment] in your app code.

Instance Attribute Summary

Attributes inherited from XMLElementWrapper

#xml_element

Instance Method Summary collapse

Methods inherited from XMLElementWrapper

#to_s

Constructor Details

#initialize(node_or_variable) ⇒ EnvironmentVariable

Returns a new instance of EnvironmentVariable.

Parameters:

  • node_or_variable (nil, REXML::Element, Hash{Symbol => String,Bool})
    • If nil, it will create a default XML node to use

    • If a REXML::Element, should be a <EnvironmentVariable> XML node to wrap

    • If a Hash, must contain keys :key and :value (Strings) and optionally :enabled (Boolean)



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/xcodeproj/scheme/environment_variables.rb', line 104

def initialize(node_or_variable)
  create_xml_element_with_fallback(node_or_variable, VARIABLE_NODE) do
    raise "Must pass a Hash with 'key' and 'value'!" unless node_or_variable.is_a?(Hash) &&
        node_or_variable.key?(:key) && node_or_variable.key?(:value)

    @xml_element.attributes['key'] = node_or_variable[:key]
    @xml_element.attributes['value'] = node_or_variable[:value]

    @xml_element.attributes['isEnabled'] = if node_or_variable.key?(:enabled)
                                             bool_to_string(node_or_variable[:enabled])
                                           else
                                             bool_to_string(true)
                                           end
  end
end

Instance Method Details

#enabledBool

Returns the EnvironmentValue’s enabled state

Returns:

  • (Bool)


151
152
153
# File 'lib/xcodeproj/scheme/environment_variables.rb', line 151

def enabled
  string_to_bool(@xml_element.attributes['isEnabled'])
end

#enabled=(enabled) ⇒ Object

Sets the EnvironmentValue’s enabled state

Parameters:

  • enabled (Bool)


158
159
160
# File 'lib/xcodeproj/scheme/environment_variables.rb', line 158

def enabled=(enabled)
  @xml_element.attributes['isEnabled'] = bool_to_string(enabled)
end

#keyString

Returns the EnvironmentValue’s key

Returns:

  • (String)


123
124
125
# File 'lib/xcodeproj/scheme/environment_variables.rb', line 123

def key
  @xml_element.attributes['key']
end

#key=(key) ⇒ Object

Sets the EnvironmentValue’s key

Parameters:

  • key (String)


130
131
132
# File 'lib/xcodeproj/scheme/environment_variables.rb', line 130

def key=(key)
  @xml_element.attributes['key'] = key
end

#to_hHash{:key => String, :value => String, :enabled => Bool}

Returns The environment variable XML node with attributes converted to a representative Hash.

Returns:

  • (Hash{:key => String, :value => String, :enabled => Bool})

    The environment variable XML node with attributes converted to a representative Hash



165
166
167
# File 'lib/xcodeproj/scheme/environment_variables.rb', line 165

def to_h
  { :key => key, :value => value, :enabled => enabled }
end

#valueString

Returns the EnvironmentValue’s value

Returns:

  • (String)


137
138
139
# File 'lib/xcodeproj/scheme/environment_variables.rb', line 137

def value
  @xml_element.attributes['value']
end

#value=(value) ⇒ Object

Sets the EnvironmentValue’s value

Parameters:

  • value (String)


144
145
146
# File 'lib/xcodeproj/scheme/environment_variables.rb', line 144

def value=(value)
  @xml_element.attributes['value'] = value
end