Class: CanCanCan::Neo4j::CypherConstructorHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/cancancan/neo4j/cypher_constructor_helper.rb

Overview

Cypher query constructs

Class Method Summary collapse

Class Method Details

.path_end_var(relationship, conditions) ⇒ Object



25
26
27
28
29
# File 'lib/cancancan/neo4j/cypher_constructor_helper.rb', line 25

def path_end_var(relationship, conditions)
  with_var = variable_in_path?(relationship, conditions)
  target_class = relationship.target_class
  with_var ? var_name(target_class) : ''
end

.path_node(target_class, var_label) ⇒ Object



10
11
12
13
14
15
# File 'lib/cancancan/neo4j/cypher_constructor_helper.rb', line 10

def path_node(target_class, var_label)
  label = target_class.mapped_label_names
                      .map { |label_name| ":`#{label_name}`" }
                      .join
  "(#{var_label}#{label})"
end

.var_name(class_constant) ⇒ Object



6
7
8
# File 'lib/cancancan/neo4j/cypher_constructor_helper.rb', line 6

def var_name(class_constant)
  class_constant.name.downcase.split('::').join('_')
end

.variable_in_path?(relationship, conditions) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
# File 'lib/cancancan/neo4j/cypher_constructor_helper.rb', line 17

def variable_in_path?(relationship, conditions)
  boolean = [TrueClass, FalseClass].include?(conditions.class)
  return false if conditions.blank? || boolean
  !relationship.target_class
               .associations[conditions.keys.first]
               .present?
end