Class: CanCan::ModelAdapters::ActiveRecord5Adapter

Inherits:
ActiveRecord4Adapter show all
Defined in:
lib/cancan/model_adapters/active_record_5_adapter.rb

Instance Attribute Summary

Attributes inherited from ActiveRecordAdapter

#compressed_rules

Attributes inherited from AbstractAdapter

#model_class

Class Method Summary collapse

Methods inherited from ActiveRecord4Adapter

override_condition_matching?

Methods inherited from ActiveRecordAdapter

#build_relation, child_association_to_parent, #conditions, #database_records, #extract_multiple_conditions, #initialize, #joins, matching_parent_child_polymorphic_association, nested_subject_matches_conditions?, override_nested_subject_conditions_matching?, parent_child_conditions, parent_condition_name, 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_condition_matching?, override_conditions_hash_matching?, override_nested_subject_conditions_matching?, parent_condition_name

Constructor Details

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

Class Method Details

.for_class?(model_class) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/cancan/model_adapters/active_record_5_adapter.rb', line 8

def self.for_class?(model_class)
  version_greater_or_equal?('5.0.0') && model_class <= ActiveRecord::Base
end

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

rails 5 is capable of using strings in enum but often people use symbols in rules

Returns:

  • (Boolean)


14
15
16
17
18
19
20
# File 'lib/cancan/model_adapters/active_record_5_adapter.rb', line 14

def self.matches_condition?(subject, name, value)
  return super if Array.wrap(value).all? { |x| x.is_a? Integer }

  attribute = subject.send(name)
  raw_attribute = subject.class.send(name.to_s.pluralize)[attribute]
  !(Array(value).map(&:to_s) & [attribute, raw_attribute]).empty?
end