Class: CanCan::ModelAdapters::ActiveRecord4Adapter
- Inherits:
-
ActiveRecordAdapter
- Object
- AbstractAdapter
- ActiveRecordAdapter
- CanCan::ModelAdapters::ActiveRecord4Adapter
- Defined in:
- lib/cancan/model_adapters/active_record_4_adapter.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from ActiveRecordAdapter
Attributes inherited from AbstractAdapter
Class Method Summary collapse
- .for_class?(model_class) ⇒ Boolean
- .matches_condition?(subject, name, value) ⇒ Boolean
- .override_condition_matching?(subject, name, _value) ⇒ Boolean
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_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
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
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
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 |