Module: Neo4j::Cypher::Context::Returnable
- Defined in:
- lib/neo4j-cypher/context.rb
Instance Method Summary collapse
-
#extract(&block) ⇒ Object
To return a single property, or the value of a function from a collection of nodes or relationships, you can use EXTRACT.
-
#filter(&block) ⇒ Object
Returns all the elements in a collection that comply to a predicate.
- #foreach(&block) ⇒ Object
-
#ret(*returns, &block) ⇒ ReturnItem
Specifies a return statement.
Instance Method Details
#extract(&block) ⇒ Object
To return a single property, or the value of a function from a collection of nodes or relationships, you can use EXTRACT. It will go through a collection, run an expression on every element, and return the results in an collection with these values. It works like the map method in functional languages such as Lisp and Scala. Will generate:
EXTRACT( identifier in collection : expression )
137 138 139 |
# File 'lib/neo4j-cypher/context.rb', line 137 def extract(&block) Collection.new(clause_list, 'extract', self, &block).eval_context end |
#filter(&block) ⇒ Object
Returns all the elements in a collection that comply to a predicate. Will generate
FILTER(identifier in collection : predicate)
144 145 146 |
# File 'lib/neo4j-cypher/context.rb', line 144 def filter(&block) Collection.new(clause_list, 'filter', self, &block).eval_context end |
#foreach(&block) ⇒ Object
148 149 150 |
# File 'lib/neo4j-cypher/context.rb', line 148 def foreach(&block) Foreach.new(clause_list, self, &block).eval_context end |
#ret(*returns, &block) ⇒ ReturnItem
Specifies a return statement. Notice that this is not needed, since the last value of the DSL block will be converted into one or more return statements.
124 125 126 127 128 129 130 |
# File 'lib/neo4j-cypher/context.rb', line 124 def ret(*returns, &block) = returns.last.is_a?(Hash) ? returns.pop : {} returns = [self] if returns.empty? # return self unless not specified what to return returns = [RootClause::EvalContext.new(self).instance_exec(self, &block)].flatten if block r = Return.new(clause_list, returns, , &block).eval_context (self.is_a?(RootClause::EvalContext)) ? r : self end |