Class: Xcodeproj::XCScheme::CommandLineArgument

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

Overview

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

[NSProcessInfo processInfo

arguments] 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_argument) ⇒ CommandLineArgument

Returns a new instance of CommandLineArgument.

Parameters:

  • node_or_argument (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 <CommandLineArgument> XML node to wrap

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



112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 112

def initialize(node_or_argument)
  create_xml_element_with_fallback(node_or_argument, COMMAND_LINE_ARG_NODE) do
    raise "Must pass a Hash with 'argument' and 'enabled'!" unless node_or_argument.is_a?(Hash) &&
        node_or_argument.key?(:argument) && node_or_argument.key?(:enabled)

    @xml_element.attributes['argument'] = node_or_argument[:argument]
    @xml_element.attributes['isEnabled'] = if node_or_argument.key?(:enabled)
                                             bool_to_string(node_or_argument[:enabled])
                                           else
                                             bool_to_string(false)
                                           end
  end
end

Instance Method Details

#argumentString

Returns the CommandLineArgument’s key

Returns:

  • (String)


129
130
131
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 129

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

#argument=(argument) ⇒ Object

Sets the CommandLineArgument’s key

Parameters:

  • key (String)


136
137
138
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 136

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

#enabledBool

Returns the CommandLineArgument’s enabled state

Returns:

  • (Bool)


143
144
145
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 143

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

#enabled=(enabled) ⇒ Object

Sets the CommandLineArgument’s enabled state

Parameters:

  • enabled (Bool)


150
151
152
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 150

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

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

Returns The command line argument XML node with attributes converted to a representative Hash.

Returns:

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

    The command line argument XML node with attributes converted to a representative Hash



157
158
159
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 157

def to_h
  { :argument => argument, :enabled => enabled }
end