Class: ActiveGraph::Core::QueryClauses::WhereClause

Inherits:
Clause
  • Object
show all
Defined in:
lib/active_graph/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, final_keyword, 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 ActiveGraph::Core::QueryClauses::Clause

Class Method Details

.clause_joinObject



309
310
311
# File 'lib/active_graph/core/query_clauses.rb', line 309

def clause_join
  Clause::AND
end

.clause_strings(clauses) ⇒ Object



301
302
303
304
305
306
307
# File 'lib/active_graph/core/query_clauses.rb', line 301

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



341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
# File 'lib/active_graph/core/query_clauses.rb', line 341

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



290
291
292
293
294
295
296
297
298
# File 'lib/active_graph/core/query_clauses.rb', line 290

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