Class: Neo4j::Core::Cypher::Predicate

Inherits:
Expression
  • Object
show all
Defined in:
lib/neo4j-core/cypher/cypher.rb

Instance Attribute Summary collapse

Attributes inherited from Expression

#clause, #expressions, #separator

Instance Method Summary collapse

Methods inherited from Expression

#insert_last, #prefix, #prefixes, #valid?

Constructor Details

#initialize(expressions, params) ⇒ Predicate

Returns a new instance of Predicate.



861
862
863
864
865
866
# File 'lib/neo4j-core/cypher/cypher.rb', line 861

def initialize(expressions, params)
  @params = params
  @identifier = :x
  params[:input].referenced! if params[:input].respond_to?(:referenced!)
  super(expressions, params[:clause])
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



859
860
861
# File 'lib/neo4j-core/cypher/cypher.rb', line 859

def params
  @params
end

Instance Method Details

#identifier(i) ⇒ Object



868
869
870
871
# File 'lib/neo4j-core/cypher/cypher.rb', line 868

def identifier(i)
  @identifier = i
  self
end

#to_sObject



873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'lib/neo4j-core/cypher/cypher.rb', line 873

def to_s
  input = params[:input]
  if input.kind_of?(Property)
    yield_param = Property.new([], @identifier, nil)
    args = ""
  else
    yield_param = NodeVar.new([], []).as(@identifier.to_sym)
    args = "(#{input.var_name})"
  end
  context = Neo4j::Cypher.new(yield_param, &params[:predicate_block])
  context.expressions.each { |e| e.clause = nil }
  if params[:clause] == :return
    where_or_colon = ':'
  else
    where_or_colon = 'WHERE'
  end
  predicate_value = context.to_s[1..-1] # skip separator ,
  "#{params[:op]}(#@identifier in #{params[:iterable]}#{args} #{where_or_colon} #{predicate_value})"
end