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.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/jazzy/symbol_graph/relationship.rb', line 23

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



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

def constraints
  @constraints
end

#kindObject

Returns the value of attribute kind.



5
6
7
# File 'lib/jazzy/symbol_graph/relationship.rb', line 5

def kind
  @kind
end

#source_usrObject

Returns the value of attribute source_usr.



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

def source_usr
  @source_usr
end

#target_fallbackObject

can be nil



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

def target_fallback
  @target_fallback
end

#target_usrObject

Returns the value of attribute target_usr.



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

def target_usr
  @target_usr
end

Instance Method Details

#default_implementation?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/jazzy/symbol_graph/relationship.rb', line 19

def default_implementation?
  kind == :defaultImplementationOf
end

#protocol_requirement?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/jazzy/symbol_graph/relationship.rb', line 15

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