Class: Neo4j::Cypher::RelVar
- Inherits:
-
Object
- Object
- Neo4j::Cypher::RelVar
show all
- Includes:
- Clause
- Defined in:
- lib/neo4j-cypher/rel_var.rb
Defined Under Namespace
Classes: EvalContext
Constant Summary
Constants included
from Clause
Clause::NAME, Clause::ORDER
Instance Attribute Summary
Attributes included from Clause
#clause_list, #clause_type, #eval_context, #expr, #insert_order
Instance Method Summary
collapse
Methods included from Clause
#<=>, #alias_name, #as_alias, #as_alias?, #clause_position, #create_clause_args_for, #match_value, #match_value=, #prefix, #referenced?, #separator, #to_prop_string, #valid_clause?, #var_name, #var_name=
Constructor Details
#initialize(clause_list, expr, props = nil) ⇒ RelVar
Returns a new instance of RelVar.
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/neo4j-cypher/rel_var.rb', line 7
def initialize(clause_list, expr, props = nil)
super(clause_list, :rel_var, EvalContext)
self.var_name = guess_var_name_from_string(expr.first) if expr.first.is_a?(String)
if props
@match_value = "#{match_value_from_args(expr)} #{to_prop_string(props)}"
else
@match_value = match_value_from_args(expr)
end
end
|
Instance Method Details
#guess_var_name_from_string(expr) ⇒ Object
32
33
34
35
|
# File 'lib/neo4j-cypher/rel_var.rb', line 32
def guess_var_name_from_string(expr)
guess = /([[:alpha:]_]*)/.match(expr)[1]
guess && !guess.empty? && guess
end
|
#match_value_from_args(expr) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/neo4j-cypher/rel_var.rb', line 19
def match_value_from_args(expr)
if expr.first.is_a?(String)
expr.first
elsif expr.first.is_a?(Symbol)
":#{expr.map { |e| match_value_from_symbol(e) }.join('|')}"
elsif expr.empty?
'?'
else
":#{expr.map { |e| e.clause.rel_type }.join('|')}"
end
end
|
#match_value_from_symbol(expr) ⇒ Object
37
38
39
|
# File 'lib/neo4j-cypher/rel_var.rb', line 37
def match_value_from_symbol(expr)
"`#{expr}`"
end
|
#optionally! ⇒ Object
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/neo4j-cypher/rel_var.rb', line 54
def optionally!
if @match_value.include?('?')
elsif @match_value.include?(':')
@match_value.sub!(/:/, "?:")
else
@match_value += '?'
end
self
end
|
#referenced! ⇒ Object
45
46
47
48
|
# File 'lib/neo4j-cypher/rel_var.rb', line 45
def referenced!
eval_context.as(var_name) unless referenced?
super
end
|
#rel_type ⇒ Object
41
42
43
|
# File 'lib/neo4j-cypher/rel_var.rb', line 41
def rel_type
@match_value.include?(':') ? @match_value.split(':').last : @match_value.sub('?', '')
end
|
#return_value ⇒ Object
50
51
52
|
# File 'lib/neo4j-cypher/rel_var.rb', line 50
def return_value
var_name
end
|