Class: Xcodeproj::XCScheme::CommandLineArguments
- Inherits:
-
XMLElementWrapper
- Object
- XMLElementWrapper
- Xcodeproj::XCScheme::CommandLineArguments
- Defined in:
- lib/xcodeproj/scheme/command_line_arguments.rb
Overview
This class wraps the CommandLineArguments node of a .xcscheme XML file. This is just a container of CommandLineArgument objects. It can either appear on a LaunchAction or TestAction scheme group.
Instance Attribute Summary
Attributes inherited from XMLElementWrapper
Instance Method Summary collapse
-
#[](argument) ⇒ CommandLineArgument
Argument Returns the matching command line argument for a specified key.
-
#[]=(argument, enabled) ⇒ CommandLineArgument
Assigns a value for a specified key.
-
#all_arguments ⇒ Array<CommandLineArgument>
The key value pairs currently set in @xml_element.
-
#assign_argument(argument) ⇒ Array<CommandLineArgument>
Adds a given argument to the set of command line arguments, or replaces it if that key already exists.
-
#initialize(node_or_arguments = nil) ⇒ CommandLineArguments
constructor
A new instance of CommandLineArguments.
-
#remove_argument(argument) ⇒ Array<CommandLineArgument>
Removes a specified argument (by string or object) from the set of command line arguments.
-
#to_a ⇒ Array<Hash{Symbol => String,Bool}>
The current command line arguments represented as an array.
Methods inherited from XMLElementWrapper
Constructor Details
#initialize(node_or_arguments = nil) ⇒ CommandLineArguments
Returns a new instance of CommandLineArguments.
19 20 21 22 23 24 |
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 19 def initialize(node_or_arguments = nil) create_xml_element_with_fallback(node_or_arguments, COMMAND_LINE_ARGS_NODE) do @all_arguments = [] node_or_arguments.each { |var| assign_argument(var) } unless node_or_arguments.nil? end end |
Instance Method Details
#[](argument) ⇒ CommandLineArgument
Argument Returns the matching command line argument for a specified key
76 77 78 |
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 76 def [](argument) all_arguments.find { |var| var.argument == argument } end |
#[]=(argument, enabled) ⇒ CommandLineArgument
Assigns a value for a specified key
89 90 91 92 |
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 89 def []=(argument, enabled) assign_argument(:argument => argument, :enabled => enabled) self[argument] end |
#all_arguments ⇒ Array<CommandLineArgument>
Returns The key value pairs currently set in @xml_element.
29 30 31 |
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 29 def all_arguments @all_arguments ||= @xml_element.get_elements(COMMAND_LINE_ARG_NODE).map { |argument| CommandLineArgument.new(argument) } end |
#assign_argument(argument) ⇒ Array<CommandLineArgument>
Adds a given argument to the set of command line arguments, or replaces it if that key already exists
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 42 def assign_argument(argument) command_line_arg = if argument.is_a?(CommandLineArgument) argument else CommandLineArgument.new(argument) end all_arguments.each { |existing_var| remove_argument(existing_var) if existing_var.argument == command_line_arg.argument } @xml_element.add_element(command_line_arg.xml_element) @all_arguments << command_line_arg end |
#remove_argument(argument) ⇒ Array<CommandLineArgument>
Removes a specified argument (by string or object) from the set of command line arguments
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 60 def remove_argument(argument) command_line_arg = if argument.is_a?(CommandLineArgument) argument else CommandLineArgument.new(argument) end raise "Unexpected parameter type: #{command_line_arg.class}" unless command_line_arg.is_a?(CommandLineArgument) @xml_element.delete_element(command_line_arg.xml_element) @all_arguments -= [command_line_arg] end |
#to_a ⇒ Array<Hash{Symbol => String,Bool}>
Returns The current command line arguments represented as an array.
97 98 99 |
# File 'lib/xcodeproj/scheme/command_line_arguments.rb', line 97 def to_a all_arguments.map(&:to_h) end |