Module: Neo4j::Cypher::Clause

Overview

Responsible for order of the clauses Does expect a #clause method when included

Constant Summary collapse

ORDER =
[:start, :match, :create, :where, :with, :foreach, :set, :delete, :remove, :return, :order_by, :skip, :limit]
NAME =
{:start => 'START', :create => 'CREATE', :match => 'MATCH', :where => "WHERE", :with => 'WITH',
:return => 'RETURN', :order_by => 'ORDER BY', :skip => 'SKIP', :limit => 'LIMIT', :set => 'SET',
:remove => 'REMOVE', :delete => 'DELETE', :foreach => 'FOREACH'}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clause_listObject

Returns the value of attribute clause_list.



13
14
15
# File 'lib/neo4j-cypher/clause.rb', line 13

def clause_list
  @clause_list
end

#clause_typeObject

Returns the value of attribute clause_type.



13
14
15
# File 'lib/neo4j-cypher/clause.rb', line 13

def clause_type
  @clause_type
end

#eval_contextObject

Returns the value of attribute eval_context.



13
14
15
# File 'lib/neo4j-cypher/clause.rb', line 13

def eval_context
  @eval_context
end

#exprObject

Returns the value of attribute expr.



13
14
15
# File 'lib/neo4j-cypher/clause.rb', line 13

def expr
  @expr
end

#insert_orderObject

Returns the value of attribute insert_order.



13
14
15
# File 'lib/neo4j-cypher/clause.rb', line 13

def insert_order
  @insert_order
end

Instance Method Details

#<=>(other) ⇒ Object



27
28
29
# File 'lib/neo4j-cypher/clause.rb', line 27

def <=>(other)
  clause_position == other.clause_position ? insert_order <=> other.insert_order : clause_position <=> other.clause_position
end

#alias_nameObject



82
83
84
# File 'lib/neo4j-cypher/clause.rb', line 82

def alias_name
  @alias
end

#as_alias(new_name) ⇒ Object



77
78
79
80
# File 'lib/neo4j-cypher/clause.rb', line 77

def as_alias(new_name)
  @alias = new_name
  self.var_name = new_name
end

#as_alias?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/neo4j-cypher/clause.rb', line 86

def as_alias?
  !!@alias && var_name != return_value
end

#clause_positionObject



31
32
33
34
# File 'lib/neo4j-cypher/clause.rb', line 31

def clause_position
  valid_clause?
  ORDER.find_index(clause_type)
end

#create_clause_args_for(args) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/neo4j-cypher/clause.rb', line 100

def create_clause_args_for(args)
  args.map do |arg|
    case arg
      when Neo4j::Cypher::ReturnItem::EvalContext, Neo4j::Cypher::Property::EvalContext
        Argument.new_arg_from_clause(arg.clause)
      when String, Symbol
        Argument.new_arg_from_string(arg, clause_list)
      else
        arg.clause
    end
  end
end

#initialize(clause_list, clause_type, eval_context = Context::Empty) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/neo4j-cypher/clause.rb', line 15

def initialize(clause_list, clause_type, eval_context = Context::Empty)
  @clause_type = clause_type
  @clause_list = clause_list
  if eval_context.is_a?(Class)
    @eval_context = eval_context.new(self)
  else
    @eval_context = eval_context
  end
  self.insert_order = 0
  clause_list.insert(self)
end

#match_valueObject



48
49
50
# File 'lib/neo4j-cypher/clause.rb', line 48

def match_value
  @match_value || expr || var_name
end

#match_value=(mv) ⇒ Object



44
45
46
# File 'lib/neo4j-cypher/clause.rb', line 44

def match_value=(mv)
  @match_value = mv
end

#prefixObject



57
58
59
# File 'lib/neo4j-cypher/clause.rb', line 57

def prefix
  NAME[clause_type]
end

#referenced!Object



73
74
75
# File 'lib/neo4j-cypher/clause.rb', line 73

def referenced!
  @referenced = true
end

#referenced?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/neo4j-cypher/clause.rb', line 69

def referenced?
  !!@referenced
end

#return_valueObject

Used in return clause to generate the last part of the return cypher clause string



53
54
55
# File 'lib/neo4j-cypher/clause.rb', line 53

def return_value
  var_name
end

#separatorObject



40
41
42
# File 'lib/neo4j-cypher/clause.rb', line 40

def separator
  clause_type == :where ? ' and ' : ','
end

#to_prop_string(props) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/neo4j-cypher/clause.rb', line 90

def to_prop_string(props)
  key_values = props.keys.map do |key|
    raw = key.to_s[0, 1] == '_'
    escaped_string = props[key].gsub(/['"]/) { |s| "\\#{s}" } if props[key].is_a?(String) && !raw
    val = props[key].is_a?(String) && !raw ? "'#{escaped_string}'" : props[key]
    "#{raw ? key.to_s[1..-1] : key} : #{val}"
  end
  "{#{key_values.join(', ')}}"
end

#valid_clause?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/neo4j-cypher/clause.rb', line 36

def valid_clause?
  raise "Unknown clause_type '#{clause_type}' on #{self}" unless ORDER.include?(clause_type)
end

#var_nameObject



61
62
63
# File 'lib/neo4j-cypher/clause.rb', line 61

def var_name
  @var_name ||= @clause_list.create_variable(self)
end

#var_name=(new_name) ⇒ Object



65
66
67
# File 'lib/neo4j-cypher/clause.rb', line 65

def var_name=(new_name)
  @var_name = new_name.to_sym if new_name
end