class CanCanCan::ActiveGraph::SingleRuleCypher

Return records for single cancan rule

Attributes

model_class[R]
rule[R]

Public Class Methods

new(rule, model_class) click to toggle source
# File lib/cancancan/active_graph/single_rule_cypher.rb, line 8
def initialize(rule, model_class)
  @rule = rule
  @model_class = model_class
end

Public Instance Methods

records() click to toggle source
# File lib/cancancan/active_graph/single_rule_cypher.rb, line 13
def records
  conds = rule.conditions
  return conds if conds.is_a?(::ActiveGraph::Node::Query::QueryProxy) || conds.is_a?(::ActiveGraph::Node::HasN::AssociationProxy)
  return records_for_no_conditions if conds.blank?
  records_for_hash_conditions
end

Private Instance Methods

records_for_hash_conditions() click to toggle source
# File lib/cancancan/active_graph/single_rule_cypher.rb, line 30
def records_for_hash_conditions
  cypher = CanCanCan::ActiveGraph::RuleCypher.new(rule: rule,
                                            model_class: model_class,
                                            index: nil)
  model_class.new_query
             .match(cypher.path)
             .where(cypher.rule_conditions)
             .proxy_as(model_class, var_lable)
             .distinct
end
records_for_no_conditions() click to toggle source
# File lib/cancancan/active_graph/single_rule_cypher.rb, line 22
def records_for_no_conditions
  if rule.base_behavior
    model_class.all
  else
    model_class.where('false')
  end
end
var_lable() click to toggle source
# File lib/cancancan/active_graph/single_rule_cypher.rb, line 41
def var_lable
  CypherConstructorHelper.var_name(model_class)
end