Class: Neo4j::Cypher::RootClause::EvalContext

Inherits:
Object
  • Object
show all
Includes:
MathFunctions, Context, Returnable
Defined in:
lib/neo4j-cypher/root.rb

Instance Attribute Summary

Attributes included from Context

#clause

Instance Method Summary collapse

Methods included from Context

#clause_list, #initialize

Instance Method Details

#_entities(arg_list, entity_type) ⇒ Object



176
177
178
179
# File 'lib/neo4j-cypher/root.rb', line 176

def _entities(arg_list, entity_type)
  s = arg_list.map { |x| x.clause.referenced!; x.clause.var_name }.join(", ")
  ReturnItem.new(clause_list, "#{entity_type}(#{s})").eval_context
end

#coalesce(*args) ⇒ Object



163
164
165
166
# File 'lib/neo4j-cypher/root.rb', line 163

def coalesce(*args)
  s = args.map { |x| x.clause.return_value }.join(", ")
  ReturnItem.new(clause_list, "coalesce(#{s})").eval_context
end

#count(variable = '*') ⇒ ReturnItem

Returns a counter return clause.

Parameters:

  • variable (Symbol, nil) (defaults to: '*')

    the entity we want to count or wildcard (*)

Returns:



158
159
160
161
# File 'lib/neo4j-cypher/root.rb', line 158

def count(variable='*')
  operand = variable.respond_to?(:clause) ? variable.clause.var_name : variable
  ReturnItem.new(clause_list, "count(#{operand})").eval_context
end

#create_path(*args, &block) ⇒ Object



181
182
183
# File 'lib/neo4j-cypher/root.rb', line 181

def create_path(*args, &block)
  CreatePath.new(clause_list, *args, &block).eval_context
end

#create_unique_path(*args, &block) ⇒ Object



185
186
187
# File 'lib/neo4j-cypher/root.rb', line 185

def create_unique_path(*args, &block)
  CreatePath.new(clause_list, *args, &block).unique!.eval_context
end

#distinct(node_or_name) ⇒ Object



197
198
199
200
# File 'lib/neo4j-cypher/root.rb', line 197

def distinct(node_or_name)
  operand = node_or_name.respond_to?(:clause) ? node_or_name.clause.var_name : node_or_name
  ReturnItem.new(clause_list, "distinct(#{operand})").eval_context
end

#lookup(index_class, key, value) ⇒ LuceneQuery

Specifies a start node by performing a lucene query.

Parameters:

  • index_class (Class, String)

    a class responsible for an index or the string value of the index

  • key (String, Symbol)

    the key we ask for

  • value (String, Symbol)

    the value of the key we ask for

Returns:



97
98
99
# File 'lib/neo4j-cypher/root.rb', line 97

def lookup(index_class, key, value)
  LuceneQuery.lookup_node_by_class(clause_list, index_class, key, value).eval_context
end

#lookup_rel(index_class, key, value) ⇒ LuceneQuery

Specifies a start relationship by performing a lucene query.

Parameters:

  • index_class (Class, String)

    a class responsible for an index or the string value of the index

  • key (String, Symbol)

    the key we ask for

  • value (String, Symbol)

    the value of the key we ask for

Returns:



107
108
109
# File 'lib/neo4j-cypher/root.rb', line 107

def lookup_rel(index_class, key, value)
  LuceneQuery.lookup_rel_by_class(clause_list, index_class, key, value).eval_context
end

#match(&match_dsl) ⇒ Object

Does nothing, just for making the DSL easier to read (maybe).

Returns:

  • self



49
50
51
# File 'lib/neo4j-cypher/root.rb', line 49

def match(*, &match_dsl)
  instance_eval(&match_dsl) if match_dsl
end

#match_not(&match_dsl) ⇒ Object



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

def match_not(&match_dsl)
  instance_eval(&match_dsl).not
end

#node(*nodes) ⇒ StartNode, NodeVar

Creates a node variable. It will create different variables depending on the type of the first element in the nodes argument.

  • Fixnum - it will be be used as neo_id for start node(s) (StartNode)

  • Symbol - it will create an unbound node variable with the same name as the symbol (NodeVar#as)

  • empty array - it will create an unbound node variable (NodeVar)

Parameters:

  • nodes (Fixnum, Symbol, String)

    the id of the nodes we want to start from

Returns:



120
121
122
123
124
125
126
127
128
# File 'lib/neo4j-cypher/root.rb', line 120

def node(*nodes)
  if nodes.first.is_a?(Symbol)
    NodeVar.new(clause_list).eval_context.as(nodes.first)
  elsif !nodes.empty?
    StartNode.new(clause_list, nodes).eval_context
  else
    NodeVar.new(clause_list).eval_context
  end
end

#nodes(*args) ⇒ Object



168
169
170
# File 'lib/neo4j-cypher/root.rb', line 168

def nodes(*args)
  _entities(args, 'nodes')
end

#query(index_class, q, index_type = :exact) ⇒ LuceneQuery

Specifies a start node by performing a lucene query.

Parameters:

  • index_class (Class, String)

    a class responsible for an index or the string value of the index

  • q (String)

    the lucene query

  • index_type (Symbol) (defaults to: :exact)

    the type of index

Returns:



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

def query(index_class, q, index_type = :exact)
  LuceneQuery.query_node_by_class(clause_list, index_class, q, index_type).eval_context
end

#query_rel(index_class, q, index_type = :exact) ⇒ LuceneQuery

Specifies a start relationship by performing a lucene query.

Parameters:

  • index_class (Class, String)

    a class responsible for an index or the string value of the index

  • q (String)

    the lucene query

  • index_type (Symbol) (defaults to: :exact)

    the type of index

Returns:



87
88
89
# File 'lib/neo4j-cypher/root.rb', line 87

def query_rel(index_class, q, index_type = :exact)
  LuceneQuery.query_rel_by_class(clause_list, index_class, q, index_type).eval_context
end

#rel(*rels) ⇒ StartRel, RelVar

Similar to #node

Returns:



132
133
134
135
136
137
138
139
# File 'lib/neo4j-cypher/root.rb', line 132

def rel(*rels)
  if rels.first.is_a?(Fixnum) || rels.first.respond_to?(:neo_id)
    StartRel.new(clause_list, rels).eval_context
  else
    props = rels.pop if rels.last.is_a?(Hash)
    RelVar.new(clause_list, rels, props).eval_context
  end
end

#rel?(*rels) ⇒ Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/neo4j-cypher/root.rb', line 141

def rel?(*rels)
  rel(*rels).clause.optionally!.eval_context
end

#rels(*args) ⇒ Object



172
173
174
# File 'lib/neo4j-cypher/root.rb', line 172

def rels(*args)
  _entities(args, 'relationships')
end

#shortest_path(&block) ⇒ Object



146
147
148
149
# File 'lib/neo4j-cypher/root.rb', line 146

def shortest_path(&block)
  match = instance_eval(&block)
  match.shortest_path
end

#shortest_paths(&block) ⇒ Object



151
152
153
154
# File 'lib/neo4j-cypher/root.rb', line 151

def shortest_paths(&block)
  match = instance_eval(&block)
  match.shortest_paths
end

#startObject

Does nothing, just for making the DSL easier to read (maybe)

Returns:

  • self



59
60
61
# File 'lib/neo4j-cypher/root.rb', line 59

def start(*)
  self
end

#where(w = nil, &block) ⇒ Object



63
64
65
66
# File 'lib/neo4j-cypher/root.rb', line 63

def where(w=nil, &block)
  Where.new(clause_list, self, w, &block)
  self
end

#where_not(w = nil, &block) ⇒ Object



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

def where_not(w=nil, &block)
  Where.new(clause_list, self, w, &block).neg!
  self
end

#with(*args, &block) ⇒ Object



189
190
191
# File 'lib/neo4j-cypher/root.rb', line 189

def with(*args, &block)
  With.new(clause_list, :where, *args, &block).eval_context
end

#with_match(*args, &block) ⇒ Object



193
194
195
# File 'lib/neo4j-cypher/root.rb', line 193

def with_match(*args, &block)
  With.new(clause_list, :match, *args, &block).eval_context
end