Class: CanCan::ModelAdapters::ActiveGraphAdapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/cancancan/model_adapters/active_graph_adapter.rb

Overview

neo4j adapter for cancan

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all_conditions_match?(subject, conditions, base_class) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
41
# File 'lib/cancancan/model_adapters/active_graph_adapter.rb', line 32

def self.all_conditions_match?(subject, conditions, base_class)
  return false unless subject
  conditions.all? do |key, value|
    if (relation = base_class.associations[key])
      match_relation_conditions(value, subject, relation)
    else
      property_matches?(subject, key, value)
    end
  end
end

.for_class?(model_class) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/cancancan/model_adapters/active_graph_adapter.rb', line 19

def self.for_class?(model_class)
  model_class <= ActiveGraph::Node
end

.match_relation_conditions(conditions, subject, association) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/cancancan/model_adapters/active_graph_adapter.rb', line 51

def self.match_relation_conditions(conditions, subject, association)
  rel_length = conditions.delete(:rel_length) if conditions.is_a?(Hash)
  subject = subject.send(association.name, rel_length: rel_length)
  return !subject.exists? if conditions.blank?
  return subject.exists? if conditions == true
  all_conditions_match?(subject, conditions, association.target_class)
end

.matches_conditions_hash?(subject, conditions) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/cancancan/model_adapters/active_graph_adapter.rb', line 27

def self.matches_conditions_hash?(subject, conditions)
  base_class = subject.class
  all_conditions_match?(subject, conditions, base_class)
end

.override_conditions_hash_matching?(_subject, _conditions) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/cancancan/model_adapters/active_graph_adapter.rb', line 23

def self.override_conditions_hash_matching?(_subject, _conditions)
  true
end

.property_matches?(subject, property, value) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
# File 'lib/cancancan/model_adapters/active_graph_adapter.rb', line 43

def self.property_matches?(subject, property, value)
  if subject.is_a?(ActiveGraph::Node::HasN::AssociationProxy)
    subject.where(property => value).exists?
  else
    subject.send(property) == value
  end
end

Instance Method Details

#database_recordsObject



10
11
12
13
14
15
16
17
# File 'lib/cancancan/model_adapters/active_graph_adapter.rb', line 10

def database_records
  return @model_class.where('false') if @rules.empty?
  override_scope
  if (rule = logical_single_can_rule)
    return records_for_single_rule(rule)
  end
  records_for_multiple_rules.distinct
end