Sha256: c42f3e5bbd3ef3a8a828b77ae923c7739960718424a63c9307acc368bbde78cb

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module Jazzy
  module SymbolGraph
    # A Relationship is a tidied-up SymbolGraph JSON object
    class Relationship
      attr_accessor :kind
      attr_accessor :source_usr
      attr_accessor :target_usr
      attr_accessor :target_fallback # can be nil
      attr_accessor :constraints # array, can be empty

      KINDS = %w[memberOf conformsTo defaultImplementationOf
                 overrides inheritsFrom requirementOf
                 optionalRequirementOf].freeze

      def protocol_requirement?
        %i[requirementOf optionalRequirementOf].include? kind
      end

      def default_implementation?
        kind == :defaultImplementationOf
      end

      # Protocol conformances added by compiler to actor decls that
      # users aren't interested in.
      def actor_protocol?
        %w[Actor Sendable].include?(target_fallback)
      end

      def initialize(hash)
        kind = hash[:kind]
        unless KINDS.include?(kind)
          raise "Unknown relationship kind '#{kind}'"
        end

        self.kind = kind.to_sym
        self.source_usr = hash[:source]
        self.target_usr = hash[:target]
        if fallback = hash[:targetFallback]
          # Strip the leading module name
          self.target_fallback = fallback.sub(/^.*?\./, '')
        end
        self.constraints = Constraint.new_list(hash[:swiftConstraints] || [])
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
jazzy-0.14.4 lib/jazzy/symbol_graph/relationship.rb
jazzy-0.14.3 lib/jazzy/symbol_graph/relationship.rb
jazzy-0.14.2 lib/jazzy/symbol_graph/relationship.rb
jazzy-0.14.1 lib/jazzy/symbol_graph/relationship.rb