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, 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



283
284
285
# File 'lib/active_graph/core/query_clauses.rb', line 283

def clause_join
  Clause::AND
end

.clause_strings(clauses) ⇒ Object



275
276
277
278
279
280
281
# File 'lib/active_graph/core/query_clauses.rb', line 275

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



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

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



264
265
266
267
268
269
270
271
272
# File 'lib/active_graph/core/query_clauses.rb', line 264

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