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

notEthan / jsi / 14411889940

11 Apr 2025 08:54PM UTC coverage: 98.802%. First build
14411889940

push

github

notEthan
Merge branches 'child_node_as_jsi', 'child_node_mv_compute', 'each_immediate_inplace_applicator_schema', 'bootstrap_schema_memoize', 'validation_result_instance_memoize', 'dialect_actions_without_element', 'schema_set_by_identity', 'pretty.registry', 'struct', 'application_tests', 'misc818' and 'doc' into HEAD

503 of 520 new or added lines in 35 files covered. (96.73%)

7256 of 7344 relevant lines covered (98.8%)

138066.53 hits per line

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

78.26
/lib/jsi/struct.rb
1
# frozen_string_literal: true
2

3
module JSI
56✔
4
  # JSI::Struct adds to Struct:
5
  #
6
  # - always initialized by keywords
7
  # - .subclass enables hierarchical class inheritance with added members
8
  # - better pretty/inspect
9
  # @private
10
  class Struct < ::Struct
56✔
11
    include(Util::Pretty)
56✔
12

13
    STRUCT_NEW = Struct.singleton_class.instance_method(:new)
56✔
14
    private_constant(:STRUCT_NEW)
56✔
15

16
    HAS_KEYWORD_INIT = Struct.new(:_, keyword_init: true) && true rescue false
56✔
17
    private_constant(:HAS_KEYWORD_INIT)
56✔
18

19
    class << self
56✔
20
      # @return [Class]
21
      def subclass(*members)
56✔
22
        self_members = self.members rescue [] # NoMethodError on mri, NameError on truffle
336✔
23
        # Struct does not enable adding members to subclasses of its generated classes,
24
        # but that is still possible by binding Struct.new to the class and calling
25
        # that with both existing and new members.
26
        if HAS_KEYWORD_INIT
336✔
27
          STRUCT_NEW.bind(self).call(*self_members, *members, keyword_init: true)
288✔
28
        else
29
          STRUCT_NEW.bind(self).call(*self_members, *members)
48✔
30
        end
31
      end
32
    end
33

34
    if !HAS_KEYWORD_INIT
56✔
35
      def initialize(h = {})
8✔
36
        super(*members.map { |m| h.key?(m) ? h.delete(m) : nil })
4,118,012✔
37
        raise(ArgumentError, "#{self.class} given non-members: #{h}") if !h.empty?
613,360✔
38
      end
39
    end
40

41
    def pretty_print(q)
56✔
NEW
42
      jsi_pp_object_group(q) do
×
NEW
43
        q.seplist(each_pair) do |k, v|
×
NEW
44
          q.text(k.to_s)
×
NEW
45
          q.text(': ')
×
NEW
46
          q.pp(v)
×
47
        end
48
      end
49
    end
50
  end
51
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

© 2026 Coveralls, Inc