Class: RailsGraph::Graph::Relationship

Inherits:
Entity
  • Object
show all
Defined in:
lib/rails_graph/graph/relationship.rb

Instance Attribute Summary collapse

Attributes inherited from Entity

#id, #name, #properties

Instance Method Summary collapse

Constructor Details

#initialize(source:, target:, label:, **opts) ⇒ Relationship

Returns a new instance of Relationship.



10
11
12
13
14
15
16
# File 'lib/rails_graph/graph/relationship.rb', line 10

def initialize(source:, target:, label:, **opts)
  @source = source
  @target = target
  @label  = label

  super(**opts)
end

Instance Attribute Details

#labelObject (readonly)

Returns the value of attribute label.



8
9
10
# File 'lib/rails_graph/graph/relationship.rb', line 8

def label
  @label
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/rails_graph/graph/relationship.rb', line 8

def source
  @source
end

#targetObject (readonly)

Returns the value of attribute target.



8
9
10
# File 'lib/rails_graph/graph/relationship.rb', line 8

def target
  @target
end

Instance Method Details

#as_json(_options = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/rails_graph/graph/relationship.rb', line 22

def as_json(_options = nil)
  {
    id: id,
    label: label,
    name: name,
    source: source.id,
    target: target.id,
    properties: properties
  }
end

#identifierObject



18
19
20
# File 'lib/rails_graph/graph/relationship.rb', line 18

def identifier
  "#{label}##{source.identifier}##{target.identifier}##{name}"
end