Class: Trainer::XCResult::Helper
- Inherits:
-
Object
- Object
- Trainer::XCResult::Helper
- Defined in:
- trainer/lib/trainer/xcresult/helper.rb
Overview
Helper class for XML and node operations
Class Method Summary collapse
-
.create_xml_element(name, **attributes) ⇒ REXML::Element
Creates an XML element with the given name and attributes.
-
.find_json_children(node, *node_types) ⇒ Array<Hash>
Find children of a node by specified node types.
-
.supports_xcode16_xcresulttool? ⇒ Boolean
Check if the current xcresulttool supports new commands introduced in Xcode 16+.
Class Method Details
.create_xml_element(name, **attributes) ⇒ REXML::Element
Creates an XML element with the given name and attributes
13 14 15 16 17 18 19 20 21 22 |
# File 'trainer/lib/trainer/xcresult/helper.rb', line 13 def self.create_xml_element(name, **attributes) # Sanitize invalid XML characters (control chars except tab/CR/LF) to avoid errors when generating XML sanitizer = proc { |text| text.to_s.gsub(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/) { |c| format("\\u%04x", c.ord) } } element = REXML::Element.new(sanitizer.call(name)) attributes.compact.each do |key, value| safe_value = sanitizer.call(value.to_s) element.attributes[key.to_s] = safe_value end element end |
.find_json_children(node, *node_types) ⇒ Array<Hash>
Find children of a node by specified node types
29 30 31 32 33 |
# File 'trainer/lib/trainer/xcresult/helper.rb', line 29 def self.find_json_children(node, *node_types) return [] if node.nil? || node['children'].nil? node['children'].select { |child| node_types.include?(child['nodeType']) } end |
.supports_xcode16_xcresulttool? ⇒ Boolean
Check if the current xcresulttool supports new commands introduced in Xcode 16+
Since Xcode 16b3, xcresulttool has marked ‘get <object> –format json` as deprecated/legacy, and replaced it with `xcrun xcresulttool get test-results tests` instead.
41 42 43 44 45 46 47 48 49 50 |
# File 'trainer/lib/trainer/xcresult/helper.rb', line 41 def self.supports_xcode16_xcresulttool? # e.g. DEVELOPER_DIR=/Applications/Xcode_16_beta_3.app # xcresulttool version 23021, format version 3.53 (current) match = `xcrun xcresulttool version`.match(/xcresulttool version (?<version>[\d.]+)/) version = match[:version] Gem::Version.new(version) >= Gem::Version.new(23_021) rescue false end |