Class: Redgraph::Edge

Inherits:
Object
  • Object
show all
Includes:
Util
Defined in:
lib/redgraph/edge.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util

#escape_value, #properties_to_string

Constructor Details

#initialize(src: nil, dest: nil, type: nil, properties: {}) ⇒ Edge

Returns a new instance of Edge.



9
10
11
12
13
14
15
16
# File 'lib/redgraph/edge.rb', line 9

def initialize(src: nil, dest: nil, type: nil, properties: {})
  @src = src
  @src_id = @src.id if @src
  @dest = dest
  @dest_id = @dest.id if @dest
  @type = type
  @properties = (properties || {}).with_indifferent_access
end

Instance Attribute Details

#destObject

Returns the value of attribute dest.



7
8
9
# File 'lib/redgraph/edge.rb', line 7

def dest
  @dest
end

#dest_idObject

Returns the value of attribute dest_id.



7
8
9
# File 'lib/redgraph/edge.rb', line 7

def dest_id
  @dest_id
end

#idObject

Returns the value of attribute id.



7
8
9
# File 'lib/redgraph/edge.rb', line 7

def id
  @id
end

#propertiesObject

Returns the value of attribute properties.



7
8
9
# File 'lib/redgraph/edge.rb', line 7

def properties
  @properties
end

#srcObject

Returns the value of attribute src.



7
8
9
# File 'lib/redgraph/edge.rb', line 7

def src
  @src
end

#src_idObject

Returns the value of attribute src_id.



7
8
9
# File 'lib/redgraph/edge.rb', line 7

def src_id
  @src_id
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/redgraph/edge.rb', line 7

def type
  @type
end

Instance Method Details

#==(other) ⇒ Object



22
23
24
# File 'lib/redgraph/edge.rb', line 22

def ==(other)
  super || other.instance_of?(self.class) && !id.nil? && other.id == id
end

#persisted?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/redgraph/edge.rb', line 18

def persisted?
  id.present?
end

#to_query_string(item_alias: 'edge', src_alias: 'src', dest_alias: 'dest') ⇒ Object



26
27
28
29
# File 'lib/redgraph/edge.rb', line 26

def to_query_string(item_alias: 'edge', src_alias: 'src', dest_alias: 'dest')
  _type = ":#{type}" if type
  "(#{src_alias})-[#{item_alias}#{_type} #{properties_to_string(properties)}]->(#{dest_alias})"
end