Class: Neo4j::Core::QueryClauses::WhereClause

Inherits:
Clause
  • Object
show all
Defined in:
lib/neo4j/core/query_clauses.rb

Constant Summary collapse

KEYWORD =
'WHERE'
PAREN_SURROUND_REGEX =
/^\s*\(.+\)\s*$/
ARG_HAS_QUESTION_MARK_REGEX =
/(^|\(|\s)\?(\s|\)|$)/

Constants inherited from Clause

Clause::AND, Clause::COMMA_SPACE, Clause::PRETTY_NEW_LINE, Clause::UNDERSCORE

Instance Attribute Summary

Attributes inherited from Clause

#arg, #options, #param_vars_added, #params

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Clause

#_nested_value_hash?, #_use_key_for_var?, #add_param, #add_params, #attributes_from_key_and_value, clause_color, clause_string, from_arg, #from_hash, from_key_and_single_value, #from_string, #initialize, keyword, keyword_downcase, #label_from_key_and_value, #node_from_key_and_value, paramaterize_key!, to_cypher, #value, #var_from_key_and_value

Constructor Details

This class inherits a constructor from Neo4j::Core::QueryClauses::Clause

Class Method Details

.clause_joinObject


285
286
287
# File 'lib/neo4j/core/query_clauses.rb', line 285

def clause_join
  Clause::AND
end

.clause_strings(clauses) ⇒ Object


277
278
279
280
281
282
283
# File 'lib/neo4j/core/query_clauses.rb', line 277

def clause_strings(clauses)
  clauses.flat_map do |clause|
    Array(clause.value).map do |v|
      (clause.options[:not] ? 'NOT' : '') + (v.to_s.match(PAREN_SURROUND_REGEX) ? v.to_s : "(#{v})")
    end
  end
end

.from_args(args, params, options = {}) ⇒ Object


317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/neo4j/core/query_clauses.rb', line 317

def from_args(args, params, options = {})
  query_string, params_arg = args

  if query_string.is_a?(String) && (query_string.match(ARG_HAS_QUESTION_MARK_REGEX) || params_arg.is_a?(Hash))
    if params_arg.is_a?(Hash)
      params.add_params(params_arg)
    else
      param_var = params.add_params(question_mark_param: params_arg)[0]
      query_string = query_string.gsub(ARG_HAS_QUESTION_MARK_REGEX, "\\1{#{param_var}}\\2")
    end

    [from_arg(query_string, params, options)]
  else
    super
  end
end

Instance Method Details

#from_key_and_value(key, value, previous_keys = []) ⇒ Object


266
267
268
269
270
271
272
273
274
# File 'lib/neo4j/core/query_clauses.rb', line 266

def from_key_and_value(key, value, previous_keys = [])
  case value
  when Hash then hash_key_value_string(key, value, previous_keys)
  when NilClass then "#{key} IS NULL"
  when Regexp then regexp_key_value_string(key, value, previous_keys)
  else
    key_value_string(key, value, previous_keys)
  end
end