Class: CanCanCan::ActiveGraph::RuleCypher

Inherits:
Object
  • Object
show all
Defined in:
lib/cancancan/active_graph/rule_cypher.rb

Overview

Constructs cypher conditions for rule and cypher match classes

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ RuleCypher

Returns a new instance of RuleCypher.



9
10
11
12
13
14
# File 'lib/cancancan/active_graph/rule_cypher.rb', line 9

def initialize(options)
  @options = options
  @rule_conditions = {}
  initialize_path
  construct_cypher_conditions
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/cancancan/active_graph/rule_cypher.rb', line 7

def options
  @options
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/cancancan/active_graph/rule_cypher.rb', line 7

def path
  @path
end

#rule_conditionsObject (readonly)

Returns the value of attribute rule_conditions.



7
8
9
# File 'lib/cancancan/active_graph/rule_cypher.rb', line 7

def rule_conditions
  @rule_conditions
end

Instance Method Details

#construct_cypher_conditionsObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cancancan/active_graph/rule_cypher.rb', line 24

def construct_cypher_conditions
  conditions = @options[:rule].conditions
  if conditions.is_a?(::ActiveGraph::Node::Query::QueryProxy)
    return @options[:scope] = conditions
  end
  if conditions.blank?
    condition_for_rule_without_conditions
  else
    construct_cypher_options
  end
end

#initialize_pathObject



16
17
18
19
20
21
22
# File 'lib/cancancan/active_graph/rule_cypher.rb', line 16

def initialize_path
  model_class = @options[:model_class]
  var_label = CypherConstructorHelper.var_name(model_class)
  var_label += index_sub_str
  @options[:var_label] = var_label
  @path = CypherConstructorHelper.path_node(model_class, var_label)
end