Class: CanCan::ModelAdapters::ActiveRecord4Adapter

Inherits:
ActiveRecordAdapter show all
Defined in:
lib/cancan/model_adapters/active_record_4_adapter.rb

Direct Known Subclasses

ActiveRecord5Adapter

Instance Attribute Summary

Attributes inherited from ActiveRecordAdapter

#compressed_rules

Attributes inherited from AbstractAdapter

#model_class

Class Method Summary collapse

Methods inherited from ActiveRecordAdapter

#build_relation, #conditions, #database_records, #extract_multiple_conditions, #initialize, #joins, nested_subject_matches_conditions?, override_nested_subject_conditions_matching?, parent_child_conditions, version_greater_or_equal?, version_lower?

Methods inherited from AbstractAdapter

adapter_class, #database_records, find, inherited, #initialize, matches_conditions_hash?, nested_subject_matches_conditions?, override_conditions_hash_matching?, override_nested_subject_conditions_matching?

Constructor Details

This class inherits a constructor from CanCan::ModelAdapters::ActiveRecordAdapter

Class Method Details

.for_class?(model_class) ⇒ Boolean

Returns:

  • (Boolean)

9
10
11
# File 'lib/cancan/model_adapters/active_record_4_adapter.rb', line 9

def for_class?(model_class)
  version_lower?('5.0.0') && model_class <= ActiveRecord::Base
end

.matches_condition?(subject, name, value) ⇒ Boolean

Returns:

  • (Boolean)

17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cancan/model_adapters/active_record_4_adapter.rb', line 17

def matches_condition?(subject, name, value)
  # Get the mapping from enum strings to values.
  enum = subject.class.send(name.to_s.pluralize)
  # Get the value of the attribute as an integer.
  attribute = enum[subject.send(name)]
  # Check to see if the value matches the condition.
  if value.is_a?(Enumerable)
    value.include? attribute
  else
    attribute == value
  end
end

.override_condition_matching?(subject, name, _value) ⇒ Boolean

Returns:

  • (Boolean)

13
14
15
# File 'lib/cancan/model_adapters/active_record_4_adapter.rb', line 13

def override_condition_matching?(subject, name, _value)
  subject.class.defined_enums.include?(name.to_s)
end