• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / tigerdata-app / fa5427d1-c616-4db4-8869-6c67d0eea350

23 Jun 2025 06:40PM UTC coverage: 71.937% (-0.2%) from 72.107%
fa5427d1-c616-4db4-8869-6c67d0eea350

Pull #1533

circleci

jrgriffiniii
Introducing some additional refactoring steps for the ProjectXmlPresenter; Implements a route for retrieving the Mediaflux XML document for project metadata
Pull Request #1533: Implements a route for retrieving the Mediaflux XML document for project metadata

4 of 18 branches covered (22.22%)

4 of 15 new or added lines in 3 files covered. (26.67%)

18 existing lines in 2 files now uncovered.

2994 of 4162 relevant lines covered (71.94%)

485.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.83
/app/services/xml_tree_builder.rb
1
# frozen_string_literal: true
2

3
class XmlNullBuilder < XmlNodeBuilder
1✔
4
  def build
1✔
UNCOV
5
    document
×
6
  end
7

8
  def blank?
1✔
UNCOV
9
    true
×
10
  end
11

12
  # No-op for null builder
13
  def add_child(_child)
1✔
14
    nil
15
  end
16

17
  def name
1✔
18
    nil
19
  end
20

21
  def initialize(**_options)
1✔
22
    super(document: nil)
600✔
23
  end
24
end
25

26
class XmlTreeBuilder < XmlNodeBuilder
1✔
27
  attr_reader :children, :root_builder_options
1✔
28

29
  def null_builder
1✔
30
    @null_builder ||= XmlNullBuilder.new(**root_builder_options)
600✔
31
  end
32

33
  def root_builder
1✔
34
    @root_builder ||= begin
7,415✔
35
                        default_builder = XmlElementBuilder.new(**root_builder_options)
1,483✔
36
                        null_builder if default_builder.blank?
1,483✔
37
                        default_builder
1,483✔
38
                      end
39
  end
40

41
  delegate :node, :document, to: :root_builder
1✔
42

43
  # @return [Nokogiri::XML::Element]
44
  def build
1✔
45
    nodes = children.map(&:build)
1,483✔
46
    nodes.each do |child|
1,483✔
47
      root_builder.add_child(child)
1,443✔
48
    end
49

50
    node
1,483✔
51
  end
52

53
  # rubocop:disable Metrics/AbcSize
54
  # rubocop:disable Metrics/MethodLength
55
  #
56
  # @param [Array<Hash>] entries options for constructing each child node
57
  # @return [Array<Nokogiri::XML::Node>] an array of XML child nodes
58
  def parse_child_entries(entries)
1✔
59
    instances = [:default]
1,483✔
60
    builders = entries.map do |child_entry|
1,483✔
61
      child_entry.values.map do |child_args|
760✔
62
        multiple_children = child_args[:multiple] || false
1,440✔
63

64
        if multiple_children
1,440✔
65
          message = child_args[:object_method]
120✔
66

67
          method_args = child_args[:args] || []
120✔
68
          instances = root_builder.presenter.send(message, *method_args)
120✔
69
        end
70

71
        instances.each_with_index.map do |_instance, i|
1,440✔
72
          builder_args = child_args.dup
1,443✔
73
          builder_args[:presenter] = root_builder.presenter
1,443✔
74
          builder_args[:document] = document
1,443✔
75

76
          if multiple_children
1,443✔
77
            builder_args[:index] = i
123✔
78
            builder_args.delete(:multiple)
123✔
79
          end
80
          builder_args.delete(:object_method)
1,443✔
81
          builder_args.delete(:args)
1,443✔
82
          self.class.new(**builder_args)
1,443✔
83
        end
84
      end
85
    end
86
    builders.flatten
1,483✔
87
  end
88
  # rubocop:enable Metrics/MethodLength
89
  # rubocop:enable Metrics/AbcSize
90

91
  # @param children [Array<XmlNodeBuilder>] XmlNodeBuilder objects for the child nodes in the XML tree
92
  # @param options [Hash] arguments for the root XmlElementBuilder
93
  def initialize(children: [], **options)
1✔
94
    @root_builder_options = options.dup
1,483✔
95
    @children = parse_child_entries(children)
1,483✔
96

97
    super(document: document)
1,483✔
98
  end
99
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc