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

notEthan / scorpio / 13123791726

03 Feb 2025 09:01PM UTC coverage: 85.795% (+1.5%) from 84.292%
13123791726

push

github

notEthan
🔴LICENSE

1057 of 1232 relevant lines covered (85.8%)

321.21 hits per line

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

83.33
/lib/scorpio/openapi/reference.rb
1
# frozen_string_literal: true
2

3
module Scorpio
14✔
4
  module OpenAPI
14✔
5
    module Reference
14✔
6
      # overrides JSI::Base#[] to implicitly dereference this Reference, except when
7
      # the given token is present in this Reference's instance (this should usually
8
      # only apply to the token '$ref')
9
      def [](token, **kw)
14✔
10
        if respond_to?(:to_hash) && !key?(token)
4,998✔
11
          deref do |deref_jsi|
4,998✔
12
            return(deref_jsi[token, **kw])
4,998✔
13
          end
14
        end
15
        return super
×
16
      end
17

18
      # yields or returns the target of this reference
19
      # @yield [JSI::Base] if a block is given
20
      # @return [JSI::Base]
21
      def deref
14✔
22
        return unless respond_to?(:to_hash) && key?('$ref') && jsi_node_content['$ref'].respond_to?(:to_str)
4,998✔
23

24
        ref_uri = Addressable::URI.parse(jsi_node_content['$ref'])
4,998✔
25
        ref_uri_nofrag = ref_uri.merge(fragment: nil)
4,998✔
26

27
        if !ref_uri_nofrag.empty? || ref_uri.fragment.nil?
4,998✔
28
          raise(NotImplementedError,
×
29
            "Scorpio currently only supports fragment URIs as OpenAPI references. cannot find reference by uri: #{self['$ref']}"
30
          )
31
        end
32

33
        ptr = JSI::Ptr.from_fragment(ref_uri.fragment)
4,998✔
34
        deref_jsi = ptr.evaluate(jsi_root_node)
4,998✔
35

36
        # TODO type check deref_jsi
37

38
        yield deref_jsi if block_given?
4,998✔
39

40
        deref_jsi
×
41
      end
42
    end
43
  end
44
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