Class: CypherBuilder::Rel
- Inherits:
-
BasicObject
- Defined in:
- lib/cypher_builder/rel.rb
Instance Method Summary
collapse
Constructor Details
#initialize(prefix, labels: [], from: nil, to: nil) ⇒ Rel
Returns a new instance of Rel.
7
8
9
10
|
# File 'lib/cypher_builder/rel.rb', line 7
def initialize(prefix, labels: [], from: nil, to: nil)
@prefix, @labels = prefix, ::Kernel.Array(labels)
@from, @to = from, to
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *_) ⇒ Object
33
34
35
|
# File 'lib/cypher_builder/rel.rb', line 33
def method_missing(name, *_)
Field.new(@prefix, name)
end
|
Instance Method Details
#as_cypher(payload:, context:) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/cypher_builder/rel.rb', line 12
def as_cypher(payload:, context:)
::Kernel.sprintf('%s-[%s]->%s',
(@from ? @from.as_cypher(payload: payload, context: context.add(self)) : '()'),
[@prefix, *@labels].compact.join(':'),
(@to ? @to.as_cypher(payload: payload, context: context.add(self)) : '()'))
end
|
#from(node = nil) ⇒ Object
19
20
21
22
|
# File 'lib/cypher_builder/rel.rb', line 19
def from(node = nil)
return Field.new(@prefix, 'from') if node == nil
Rel.new(@prefix, labels: @labels, from: node, to: @to)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
29
30
31
|
# File 'lib/cypher_builder/rel.rb', line 29
def respond_to_missing?(name, include_private = false)
true
end
|
#to(node = nil) ⇒ Object
24
25
26
27
|
# File 'lib/cypher_builder/rel.rb', line 24
def to(node = nil)
return Field.new(@prefix, 'to') if node == nil
Rel.new(@prefix, labels: @labels, from: @from, to: node)
end
|