Class: Jazzy::SymbolGraph::Relationship
- Inherits:
-
Object
- Object
- Jazzy::SymbolGraph::Relationship
- Includes:
- Comparable
- Defined in:
- lib/jazzy/symbol_graph/relationship.rb
Overview
A Relationship is a tidied-up SymbolGraph JSON object
Constant Summary collapse
- KINDS =
Order matters: defaultImplementationOf after the protocols have been defined; extensionTo after all the extensions have been discovered.
%w[memberOf conformsTo overrides inheritsFrom requirementOf optionalRequirementOf defaultImplementationOf extensionTo].freeze
- KINDS_INDEX =
KINDS.to_h { |i| [i.to_sym, KINDS.index(i)] }.freeze
Instance Attribute Summary collapse
-
#constraints ⇒ Object
array, can be empty.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#source_usr ⇒ Object
Returns the value of attribute source_usr.
-
#target_fallback ⇒ Object
can be nil.
-
#target_usr ⇒ Object
Returns the value of attribute target_usr.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#actor_protocol? ⇒ Boolean
Protocol conformances added by compiler to actor decls that users aren’t interested in.
- #default_implementation? ⇒ Boolean
- #extension_to? ⇒ Boolean
-
#initialize(hash) ⇒ Relationship
constructor
A new instance of Relationship.
- #protocol_requirement? ⇒ Boolean
Constructor Details
#initialize(hash) ⇒ Relationship
Returns a new instance of Relationship.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/jazzy/symbol_graph/relationship.rb', line 40 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
#constraints ⇒ Object
array, can be empty
11 12 13 |
# File 'lib/jazzy/symbol_graph/relationship.rb', line 11 def constraints @constraints end |
#kind ⇒ Object
Returns the value of attribute kind.
7 8 9 |
# File 'lib/jazzy/symbol_graph/relationship.rb', line 7 def kind @kind end |
#source_usr ⇒ Object
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_fallback ⇒ Object
can be nil
10 11 12 |
# File 'lib/jazzy/symbol_graph/relationship.rb', line 10 def target_fallback @target_fallback end |
#target_usr ⇒ Object
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
#<=>(other) ⇒ Object
59 60 61 62 63 |
# File 'lib/jazzy/symbol_graph/relationship.rb', line 59 def <=>(other) return 0 if kind == other.kind KINDS_INDEX[kind] <=> KINDS_INDEX[other.kind] end |
#actor_protocol? ⇒ Boolean
Protocol conformances added by compiler to actor decls that users aren’t interested in.
36 37 38 |
# File 'lib/jazzy/symbol_graph/relationship.rb', line 36 def actor_protocol? %w[Actor Sendable].include?(target_fallback) end |
#default_implementation? ⇒ Boolean
26 27 28 |
# File 'lib/jazzy/symbol_graph/relationship.rb', line 26 def default_implementation? kind == :defaultImplementationOf end |
#extension_to? ⇒ Boolean
30 31 32 |
# File 'lib/jazzy/symbol_graph/relationship.rb', line 30 def extension_to? kind == :extensionTo end |
#protocol_requirement? ⇒ Boolean
22 23 24 |
# File 'lib/jazzy/symbol_graph/relationship.rb', line 22 def protocol_requirement? %i[requirementOf optionalRequirementOf].include? kind end |