Class: Jazzy::SymbolGraph::Relationship

Inherits:
Object
  • Object
show all
Defined in:
lib/jazzy/symbol_graph/relationship.rb

Overview

A Relationship is a tidied-up SymbolGraph JSON object

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Relationship

Returns a new instance of Relationship.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jazzy/symbol_graph/relationship.rb', line 31

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

Instance Attribute Details

#constraintsObject

array, can be empty



11
12
13
# File 'lib/jazzy/symbol_graph/relationship.rb', line 11

def constraints
  @constraints
end

#kindObject

Returns the value of attribute kind.



7
8
9
# File 'lib/jazzy/symbol_graph/relationship.rb', line 7

def kind
  @kind
end

#source_usrObject

Returns the value of attribute source_usr.



8
9
10
# File 'lib/jazzy/symbol_graph/relationship.rb', line 8

def source_usr
  @source_usr
end

#target_fallbackObject

can be nil



10
11
12
# File 'lib/jazzy/symbol_graph/relationship.rb', line 10

def target_fallback
  @target_fallback
end

#target_usrObject

Returns the value of attribute target_usr.



9
10
11
# File 'lib/jazzy/symbol_graph/relationship.rb', line 9

def target_usr
  @target_usr
end

Instance Method Details

#actor_protocol?Boolean

Protocol conformances added by compiler to actor decls that users aren’t interested in.

Returns:

  • (Boolean)


27
28
29
# File 'lib/jazzy/symbol_graph/relationship.rb', line 27

def actor_protocol?
  %w[Actor Sendable].include?(target_fallback)
end

#default_implementation?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/jazzy/symbol_graph/relationship.rb', line 21

def default_implementation?
  kind == :defaultImplementationOf
end

#protocol_requirement?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/jazzy/symbol_graph/relationship.rb', line 17

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