plasmo_xcodeproj 1.21.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +95 -0
- data/bin/xcodeproj +10 -0
- data/lib/xcodeproj/command/config_dump.rb +91 -0
- data/lib/xcodeproj/command/project_diff.rb +56 -0
- data/lib/xcodeproj/command/show.rb +60 -0
- data/lib/xcodeproj/command/sort.rb +44 -0
- data/lib/xcodeproj/command/target_diff.rb +43 -0
- data/lib/xcodeproj/command.rb +63 -0
- data/lib/xcodeproj/config/other_linker_flags_parser.rb +73 -0
- data/lib/xcodeproj/config.rb +386 -0
- data/lib/xcodeproj/constants.rb +465 -0
- data/lib/xcodeproj/differ.rb +239 -0
- data/lib/xcodeproj/gem_version.rb +5 -0
- data/lib/xcodeproj/helper.rb +30 -0
- data/lib/xcodeproj/plist.rb +94 -0
- data/lib/xcodeproj/project/case_converter.rb +90 -0
- data/lib/xcodeproj/project/object/build_configuration.rb +255 -0
- data/lib/xcodeproj/project/object/build_file.rb +84 -0
- data/lib/xcodeproj/project/object/build_phase.rb +369 -0
- data/lib/xcodeproj/project/object/build_rule.rb +109 -0
- data/lib/xcodeproj/project/object/configuration_list.rb +117 -0
- data/lib/xcodeproj/project/object/container_item_proxy.rb +116 -0
- data/lib/xcodeproj/project/object/file_reference.rb +338 -0
- data/lib/xcodeproj/project/object/group.rb +506 -0
- data/lib/xcodeproj/project/object/helpers/build_settings_array_settings_by_object_version.rb +72 -0
- data/lib/xcodeproj/project/object/helpers/file_references_factory.rb +245 -0
- data/lib/xcodeproj/project/object/helpers/groupable_helper.rb +260 -0
- data/lib/xcodeproj/project/object/native_target.rb +751 -0
- data/lib/xcodeproj/project/object/reference_proxy.rb +86 -0
- data/lib/xcodeproj/project/object/root_object.rb +100 -0
- data/lib/xcodeproj/project/object/swift_package_product_dependency.rb +29 -0
- data/lib/xcodeproj/project/object/swift_package_remote_reference.rb +33 -0
- data/lib/xcodeproj/project/object/target_dependency.rb +94 -0
- data/lib/xcodeproj/project/object.rb +534 -0
- data/lib/xcodeproj/project/object_attributes.rb +522 -0
- data/lib/xcodeproj/project/object_dictionary.rb +210 -0
- data/lib/xcodeproj/project/object_list.rb +223 -0
- data/lib/xcodeproj/project/project_helper.rb +341 -0
- data/lib/xcodeproj/project/uuid_generator.rb +132 -0
- data/lib/xcodeproj/project.rb +874 -0
- data/lib/xcodeproj/scheme/abstract_scheme_action.rb +100 -0
- data/lib/xcodeproj/scheme/analyze_action.rb +19 -0
- data/lib/xcodeproj/scheme/archive_action.rb +59 -0
- data/lib/xcodeproj/scheme/build_action.rb +298 -0
- data/lib/xcodeproj/scheme/buildable_product_runnable.rb +55 -0
- data/lib/xcodeproj/scheme/buildable_reference.rb +129 -0
- data/lib/xcodeproj/scheme/command_line_arguments.rb +162 -0
- data/lib/xcodeproj/scheme/environment_variables.rb +170 -0
- data/lib/xcodeproj/scheme/execution_action.rb +86 -0
- data/lib/xcodeproj/scheme/launch_action.rb +179 -0
- data/lib/xcodeproj/scheme/location_scenario_reference.rb +49 -0
- data/lib/xcodeproj/scheme/macro_expansion.rb +34 -0
- data/lib/xcodeproj/scheme/profile_action.rb +57 -0
- data/lib/xcodeproj/scheme/remote_runnable.rb +92 -0
- data/lib/xcodeproj/scheme/send_email_action_content.rb +84 -0
- data/lib/xcodeproj/scheme/shell_script_action_content.rb +77 -0
- data/lib/xcodeproj/scheme/test_action.rb +394 -0
- data/lib/xcodeproj/scheme/xml_element_wrapper.rb +82 -0
- data/lib/xcodeproj/scheme.rb +375 -0
- data/lib/xcodeproj/user_interface.rb +22 -0
- data/lib/xcodeproj/workspace/file_reference.rb +79 -0
- data/lib/xcodeproj/workspace/group_reference.rb +67 -0
- data/lib/xcodeproj/workspace/reference.rb +40 -0
- data/lib/xcodeproj/workspace.rb +277 -0
- data/lib/xcodeproj/xcodebuild_helper.rb +108 -0
- data/lib/xcodeproj.rb +29 -0
- metadata +208 -0
@@ -0,0 +1,394 @@
|
|
1
|
+
require 'xcodeproj/scheme/abstract_scheme_action'
|
2
|
+
|
3
|
+
module Xcodeproj
|
4
|
+
class XCScheme
|
5
|
+
# This class wraps the TestAction node of a .xcscheme XML file
|
6
|
+
#
|
7
|
+
class TestAction < AbstractSchemeAction
|
8
|
+
# @param [REXML::Element] node
|
9
|
+
# The 'TestAction' XML node that this object will wrap.
|
10
|
+
# If nil, will create a default XML node to use.
|
11
|
+
#
|
12
|
+
def initialize(node = nil)
|
13
|
+
create_xml_element_with_fallback(node, 'TestAction') do
|
14
|
+
self.build_configuration = 'Debug'
|
15
|
+
@xml_element.attributes['selectedDebuggerIdentifier'] = 'Xcode.DebuggerFoundation.Debugger.LLDB'
|
16
|
+
@xml_element.attributes['selectedLauncherIdentifier'] = 'Xcode.DebuggerFoundation.Launcher.LLDB'
|
17
|
+
self.should_use_launch_scheme_args_env = true
|
18
|
+
@xml_element.add_element('Testables')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Bool]
|
23
|
+
# Whether this Test Action should use the same arguments and environment variables
|
24
|
+
# as the Launch Action.
|
25
|
+
#
|
26
|
+
def should_use_launch_scheme_args_env?
|
27
|
+
string_to_bool(@xml_element.attributes['shouldUseLaunchSchemeArgsEnv'])
|
28
|
+
end
|
29
|
+
|
30
|
+
# @param [Bool] flag
|
31
|
+
# Set whether this Test Action should use the same arguments and environment variables
|
32
|
+
# as the Launch Action.
|
33
|
+
#
|
34
|
+
def should_use_launch_scheme_args_env=(flag)
|
35
|
+
@xml_element.attributes['shouldUseLaunchSchemeArgsEnv'] = bool_to_string(flag)
|
36
|
+
end
|
37
|
+
|
38
|
+
# @return [Bool]
|
39
|
+
# Whether this Test Action should disable detection of UI API misuse
|
40
|
+
# from background threads
|
41
|
+
#
|
42
|
+
def disable_main_thread_checker?
|
43
|
+
string_to_bool(@xml_element.attributes['disableMainThreadChecker'])
|
44
|
+
end
|
45
|
+
|
46
|
+
# @param [Bool] flag
|
47
|
+
# Set whether this Test Action should disable detection of UI API misuse
|
48
|
+
# from background threads
|
49
|
+
#
|
50
|
+
def disable_main_thread_checker=(flag)
|
51
|
+
@xml_element.attributes['disableMainThreadChecker'] = bool_to_string(flag)
|
52
|
+
end
|
53
|
+
|
54
|
+
# @return [Bool]
|
55
|
+
# Whether Clang Code Coverage is enabled ('Gather coverage data' turned ON)
|
56
|
+
#
|
57
|
+
def code_coverage_enabled?
|
58
|
+
string_to_bool(@xml_element.attributes['codeCoverageEnabled'])
|
59
|
+
end
|
60
|
+
|
61
|
+
# @param [Bool] flag
|
62
|
+
# Set whether Clang Code Coverage is enabled ('Gather coverage data' turned ON)
|
63
|
+
#
|
64
|
+
def code_coverage_enabled=(flag)
|
65
|
+
@xml_element.attributes['codeCoverageEnabled'] = bool_to_string(flag)
|
66
|
+
end
|
67
|
+
|
68
|
+
# @return [Array<TestableReference>]
|
69
|
+
# The list of TestableReference (test bundles) associated with this Test Action
|
70
|
+
#
|
71
|
+
def testables
|
72
|
+
return [] unless @xml_element.elements['Testables']
|
73
|
+
|
74
|
+
@xml_element.elements['Testables'].get_elements('TestableReference').map do |node|
|
75
|
+
TestableReference.new(node)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# @param [Array<TestableReference>] testables
|
80
|
+
# Sets the list of TestableReference (test bundles) associated with this Test Action
|
81
|
+
#
|
82
|
+
def testables=(testables)
|
83
|
+
@xml_element.delete_element('Testables')
|
84
|
+
testables_element = @xml_element.add_element('Testables')
|
85
|
+
testables.each do |testable|
|
86
|
+
testables_element.add_element(testable.xml_element)
|
87
|
+
end
|
88
|
+
testables
|
89
|
+
end
|
90
|
+
|
91
|
+
# @param [TestableReference] testable
|
92
|
+
# Add a TestableReference (test bundle) to this Test Action
|
93
|
+
#
|
94
|
+
def add_testable(testable)
|
95
|
+
testables = @xml_element.elements['Testables'] || @xml_element.add_element('Testables')
|
96
|
+
testables.add_element(testable.xml_element)
|
97
|
+
end
|
98
|
+
|
99
|
+
# @return [Array<MacroExpansion>]
|
100
|
+
# The list of MacroExpansion bound with this TestAction
|
101
|
+
#
|
102
|
+
def macro_expansions
|
103
|
+
@xml_element.get_elements('MacroExpansion').map do |node|
|
104
|
+
MacroExpansion.new(node)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# @param [MacroExpansion] macro_expansion
|
109
|
+
# Add a MacroExpansion to this TestAction
|
110
|
+
#
|
111
|
+
def add_macro_expansion(macro_expansion)
|
112
|
+
if testables = @xml_element.elements['Testables']
|
113
|
+
@xml_element.insert_before(testables, macro_expansion.xml_element)
|
114
|
+
else
|
115
|
+
@xml_element.add_element(macro_expansion.xml_element)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# @return [EnvironmentVariables]
|
120
|
+
# Returns the EnvironmentVariables that will be defined at test launch
|
121
|
+
#
|
122
|
+
def environment_variables
|
123
|
+
EnvironmentVariables.new(@xml_element.elements[XCScheme::VARIABLES_NODE])
|
124
|
+
end
|
125
|
+
|
126
|
+
# @param [EnvironmentVariables,nil] env_vars
|
127
|
+
# Sets the EnvironmentVariables that will be defined at test launch
|
128
|
+
# @return [EnvironmentVariables]
|
129
|
+
#
|
130
|
+
def environment_variables=(env_vars)
|
131
|
+
@xml_element.delete_element(XCScheme::VARIABLES_NODE)
|
132
|
+
@xml_element.add_element(env_vars.xml_element) if env_vars
|
133
|
+
env_vars
|
134
|
+
end
|
135
|
+
|
136
|
+
# @todo handle 'AdditionalOptions' tag
|
137
|
+
|
138
|
+
# @return [CommandLineArguments]
|
139
|
+
# Returns the CommandLineArguments that will be passed at app launch
|
140
|
+
#
|
141
|
+
def command_line_arguments
|
142
|
+
CommandLineArguments.new(@xml_element.elements[XCScheme::COMMAND_LINE_ARGS_NODE])
|
143
|
+
end
|
144
|
+
|
145
|
+
# @return [CommandLineArguments] arguments
|
146
|
+
# Sets the CommandLineArguments that will be passed at app launch
|
147
|
+
#
|
148
|
+
def command_line_arguments=(arguments)
|
149
|
+
@xml_element.delete_element(XCScheme::COMMAND_LINE_ARGS_NODE)
|
150
|
+
@xml_element.add_element(arguments.xml_element) if arguments
|
151
|
+
arguments
|
152
|
+
end
|
153
|
+
|
154
|
+
# @return [Array<BuildableReference>]
|
155
|
+
# The list of BuildableReference (code coverage targets) associated with this Test Action
|
156
|
+
#
|
157
|
+
def code_coverage_targets
|
158
|
+
return [] unless @xml_element.elements['CodeCoverageTargets']
|
159
|
+
|
160
|
+
@xml_element.elements['CodeCoverageTargets'].get_elements('BuildableReference').map do |node|
|
161
|
+
BuildableReference.new(node)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
# @param [Array<BuildableReference>] buildable_references
|
166
|
+
# Sets the list of BuildableReference (code coverage targets) associated with this Test Action
|
167
|
+
#
|
168
|
+
def code_coverage_targets=(buildable_references)
|
169
|
+
@xml_element.attributes['onlyGenerateCoverageForSpecifiedTargets'] = bool_to_string(true)
|
170
|
+
|
171
|
+
@xml_element.delete_element('CodeCoverageTargets')
|
172
|
+
coverage_targets_element = @xml_element.add_element('CodeCoverageTargets')
|
173
|
+
buildable_references.each do |reference|
|
174
|
+
coverage_targets_element.add_element(reference.xml_element)
|
175
|
+
end
|
176
|
+
|
177
|
+
code_coverage_targets
|
178
|
+
end
|
179
|
+
|
180
|
+
# @param [BuildableReference] buildable_reference
|
181
|
+
# Add a BuildableReference (code coverage target) to this Test Action
|
182
|
+
#
|
183
|
+
def add_code_coverage_target(buildable_reference)
|
184
|
+
@xml_element.attributes['onlyGenerateCoverageForSpecifiedTargets'] = bool_to_string(true)
|
185
|
+
|
186
|
+
coverage_targets_element = @xml_element.elements['CodeCoverageTargets'] || @xml_element.add_element('CodeCoverageTargets')
|
187
|
+
coverage_targets_element.add_element(buildable_reference.xml_element)
|
188
|
+
|
189
|
+
code_coverage_targets
|
190
|
+
end
|
191
|
+
|
192
|
+
#-------------------------------------------------------------------------#
|
193
|
+
|
194
|
+
class TestableReference < XMLElementWrapper
|
195
|
+
# @param [Xcodeproj::Project::Object::AbstractTarget, REXML::Element] target_or_node
|
196
|
+
# Either the Xcode target to reference,
|
197
|
+
# or an existing XML 'TestableReference' node element to reference,
|
198
|
+
# or nil to create an new, empty TestableReference
|
199
|
+
#
|
200
|
+
# @param [Xcodeproj::Project] the root project to reference from
|
201
|
+
# (when nil the project of the target is used)
|
202
|
+
#
|
203
|
+
def initialize(target_or_node = nil, root_project = nil)
|
204
|
+
create_xml_element_with_fallback(target_or_node, 'TestableReference') do
|
205
|
+
self.skipped = false
|
206
|
+
add_buildable_reference BuildableReference.new(target_or_node, root_project) unless target_or_node.nil?
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
# @return [Bool]
|
211
|
+
# Whether or not this TestableReference (test bundle) should be skipped or not
|
212
|
+
#
|
213
|
+
def skipped?
|
214
|
+
string_to_bool(@xml_element.attributes['skipped'])
|
215
|
+
end
|
216
|
+
|
217
|
+
# @param [Bool] flag
|
218
|
+
# Set whether or not this TestableReference (test bundle) should be skipped or not
|
219
|
+
#
|
220
|
+
def skipped=(flag)
|
221
|
+
@xml_element.attributes['skipped'] = bool_to_string(flag)
|
222
|
+
end
|
223
|
+
|
224
|
+
# @return [Bool]
|
225
|
+
# Whether or not this TestableReference (test bundle) should be run in parallel or not
|
226
|
+
#
|
227
|
+
def parallelizable?
|
228
|
+
string_to_bool(@xml_element.attributes['parallelizable'])
|
229
|
+
end
|
230
|
+
|
231
|
+
# @param [Bool] flag
|
232
|
+
# Set whether or not this TestableReference (test bundle) should be run in parallel or not
|
233
|
+
#
|
234
|
+
def parallelizable=(flag)
|
235
|
+
@xml_element.attributes['parallelizable'] = bool_to_string(flag)
|
236
|
+
end
|
237
|
+
|
238
|
+
# @return [String]
|
239
|
+
# The execution order for this TestableReference (test bundle)
|
240
|
+
#
|
241
|
+
def test_execution_ordering
|
242
|
+
@xml_element.attributes['testExecutionOrdering']
|
243
|
+
end
|
244
|
+
|
245
|
+
# @param [String] order
|
246
|
+
# Set the execution order for this TestableReference (test bundle)
|
247
|
+
#
|
248
|
+
def test_execution_ordering=(order)
|
249
|
+
@xml_element.attributes['testExecutionOrdering'] = order
|
250
|
+
end
|
251
|
+
|
252
|
+
# @return [Bool]
|
253
|
+
# Whether or not this TestableReference (test bundle) should be run in randomized order.
|
254
|
+
#
|
255
|
+
def randomized?
|
256
|
+
test_execution_ordering == 'random'
|
257
|
+
end
|
258
|
+
|
259
|
+
# @return [Array<BuildableReference>]
|
260
|
+
# The list of BuildableReferences this action will build.
|
261
|
+
# (The list usually contains only one element)
|
262
|
+
#
|
263
|
+
def buildable_references
|
264
|
+
@xml_element.get_elements('BuildableReference').map do |node|
|
265
|
+
BuildableReference.new(node)
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
# @param [BuildableReference] ref
|
270
|
+
# The BuildableReference to add to the list of targets this action will build
|
271
|
+
#
|
272
|
+
def add_buildable_reference(ref)
|
273
|
+
@xml_element.add_element(ref.xml_element)
|
274
|
+
end
|
275
|
+
|
276
|
+
# @param [BuildableReference] ref
|
277
|
+
# The BuildableReference to remove from the list of targets this entry will build
|
278
|
+
#
|
279
|
+
def remove_buildable_reference(ref)
|
280
|
+
@xml_element.delete_element(ref.xml_element)
|
281
|
+
end
|
282
|
+
|
283
|
+
# @return [Array<Test>]
|
284
|
+
# The list of SkippedTest this action will skip.
|
285
|
+
#
|
286
|
+
def skipped_tests
|
287
|
+
return [] if @xml_element.elements['SkippedTests'].nil?
|
288
|
+
@xml_element.elements['SkippedTests'].get_elements('Test').map do |node|
|
289
|
+
Test.new(node)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
# @param [Array<Test>] tests
|
294
|
+
# Set the list of SkippedTest this action will skip.
|
295
|
+
#
|
296
|
+
def skipped_tests=(tests)
|
297
|
+
@xml_element.delete_element('SkippedTests')
|
298
|
+
if tests.nil?
|
299
|
+
return
|
300
|
+
end
|
301
|
+
entries = @xml_element.add_element('SkippedTests')
|
302
|
+
tests.each do |skipped|
|
303
|
+
entries.add_element(skipped.xml_element)
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
# @param [Test] skipped_test
|
308
|
+
# The SkippedTest to add to the list of tests this action will skip
|
309
|
+
#
|
310
|
+
def add_skipped_test(skipped_test)
|
311
|
+
entries = @xml_element.elements['SkippedTests'] || @xml_element.add_element('SkippedTests')
|
312
|
+
entries.add_element(skipped_test.xml_element)
|
313
|
+
end
|
314
|
+
|
315
|
+
# @return [Bool]
|
316
|
+
# Whether or not this TestableReference (test bundle) should use a whitelist or not
|
317
|
+
#
|
318
|
+
def use_test_selection_whitelist?
|
319
|
+
string_to_bool(@xml_element.attributes['useTestSelectionWhitelist'])
|
320
|
+
end
|
321
|
+
|
322
|
+
# @param [Bool] flag
|
323
|
+
# Set whether or not this TestableReference (test bundle) should use a whitelist or not
|
324
|
+
#
|
325
|
+
def use_test_selection_whitelist=(flag)
|
326
|
+
@xml_element.attributes['useTestSelectionWhitelist'] = bool_to_string(flag)
|
327
|
+
end
|
328
|
+
|
329
|
+
# @return [Array<Test>]
|
330
|
+
# The list of SelectedTest this action will run.
|
331
|
+
#
|
332
|
+
def selected_tests
|
333
|
+
return [] if @xml_element.elements['SelectedTests'].nil?
|
334
|
+
@xml_element.elements['SelectedTests'].get_elements('Test').map do |node|
|
335
|
+
Test.new(node)
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
# @param [Array<Test>] tests
|
340
|
+
# Set the list of SelectedTest this action will run.
|
341
|
+
#
|
342
|
+
def selected_tests=(tests)
|
343
|
+
@xml_element.delete_element('SelectedTests')
|
344
|
+
return if tests.nil?
|
345
|
+
entries = @xml_element.add_element('SelectedTests')
|
346
|
+
tests.each do |selected|
|
347
|
+
entries.add_element(selected.xml_element)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
# @param [Test] selected_test
|
352
|
+
# The SelectedTest to add to the list of tests this action will run.
|
353
|
+
#
|
354
|
+
def add_selected_test(selected_test)
|
355
|
+
entries = @xml_element.elements['SelectedTests'] || @xml_element.add_element('SelectedTests')
|
356
|
+
entries.add_element(selected_test.xml_element)
|
357
|
+
end
|
358
|
+
|
359
|
+
class Test < XMLElementWrapper
|
360
|
+
# @param [REXML::Element] node
|
361
|
+
# The 'Test' XML node that this object will wrap.
|
362
|
+
# If nil, will create a default XML node to use.
|
363
|
+
#
|
364
|
+
def initialize(node = nil)
|
365
|
+
create_xml_element_with_fallback(node, 'Test') do
|
366
|
+
self.identifier = node.attributes['Identifier'] unless node.nil?
|
367
|
+
end
|
368
|
+
end
|
369
|
+
|
370
|
+
# @return [String]
|
371
|
+
# Skipped test class name
|
372
|
+
#
|
373
|
+
def identifier
|
374
|
+
@xml_element.attributes['Identifier']
|
375
|
+
end
|
376
|
+
|
377
|
+
# @param [String] value
|
378
|
+
# Set the name of the skipped test class name
|
379
|
+
#
|
380
|
+
def identifier=(value)
|
381
|
+
@xml_element.attributes['Identifier'] = value
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
# Aliased to`Test` for compatibility
|
386
|
+
# @todo Remove in Xcodeproj 2
|
387
|
+
#
|
388
|
+
SkippedTest = Test
|
389
|
+
|
390
|
+
# @todo handle 'AdditionalOptions' tag
|
391
|
+
end
|
392
|
+
end
|
393
|
+
end
|
394
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
module Xcodeproj
|
2
|
+
class XCScheme
|
3
|
+
# Abstract base class used for other XCScheme classes wrapping an XML element
|
4
|
+
#
|
5
|
+
class XMLElementWrapper
|
6
|
+
# @return [REXML::Element]
|
7
|
+
# The XML node wrapped and manipulated by this XMLElementWrapper object
|
8
|
+
#
|
9
|
+
attr_reader :xml_element
|
10
|
+
|
11
|
+
# @return [String]
|
12
|
+
# The XML representation of the node this XMLElementWrapper wraps,
|
13
|
+
# formatted in the same way that Xcode would.
|
14
|
+
def to_s
|
15
|
+
formatter = XMLFormatter.new(2)
|
16
|
+
formatter.compact = false
|
17
|
+
out = ''
|
18
|
+
formatter.write(@xml_element, out)
|
19
|
+
out.gsub!("<?xml version='1.0' encoding='UTF-8'?>", '')
|
20
|
+
out << "\n"
|
21
|
+
out
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# This is a method intended to be used to facilitate the implementation of the initializers.
|
27
|
+
#
|
28
|
+
# - Create the @xml_element attribute based on the node passed as parameter, only if
|
29
|
+
# that parameter is of type REXML::Element and its name matches the tag_name given.
|
30
|
+
# - Otherwise, create a brand new REXML::Element with the proper tag name and
|
31
|
+
# execute the block given as a fallback to let the caller the chance to configure it
|
32
|
+
#
|
33
|
+
# @param [REXML::Element, *] node
|
34
|
+
# The node this XMLElementWrapper is expected to wrap
|
35
|
+
# or any other object (typically an AbstractTarget instance, or nil) the initializer might expect
|
36
|
+
#
|
37
|
+
# @param [String] tag_name
|
38
|
+
# The expected name for the node, which will also be the name used to create the new node
|
39
|
+
# if that `node` parameter is not a REXML::Element itself.
|
40
|
+
#
|
41
|
+
# @yield a parameter-less block if the `node` parameter is not actually a REXML::Element
|
42
|
+
#
|
43
|
+
# @raise Informative
|
44
|
+
# If the `node` parameter is a REXML::Element instance but the node's name
|
45
|
+
# doesn't match the one provided by the `tag_name` parameter.
|
46
|
+
#
|
47
|
+
def create_xml_element_with_fallback(node, tag_name)
|
48
|
+
if node && node.is_a?(REXML::Element)
|
49
|
+
raise Informative, 'Wrong XML tag name' unless node.name == tag_name
|
50
|
+
@xml_element = node
|
51
|
+
else
|
52
|
+
@xml_element = REXML::Element.new(tag_name)
|
53
|
+
yield if block_given?
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [Bool]
|
58
|
+
# The boolean we want to represent as a string
|
59
|
+
#
|
60
|
+
# @return [String]
|
61
|
+
# The string representaiton of that boolean used in the XML ('YES' or 'NO')
|
62
|
+
#
|
63
|
+
def bool_to_string(flag)
|
64
|
+
flag ? 'YES' : 'NO'
|
65
|
+
end
|
66
|
+
|
67
|
+
# @param [String]
|
68
|
+
# The string representaiton of a boolean used in the XML ('YES' or 'NO')
|
69
|
+
#
|
70
|
+
# @return [Bool]
|
71
|
+
# The boolean interpretation of that string
|
72
|
+
#
|
73
|
+
# @raise Informative
|
74
|
+
# If the string is not representing a boolean (i.e. is neither 'YES' nor 'NO')
|
75
|
+
#
|
76
|
+
def string_to_bool(str)
|
77
|
+
raise Informative, 'Invalid tag value. Expected YES or NO.' unless %w(YES NO).include?(str)
|
78
|
+
str == 'YES'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|