Class: CanCan::ModelAdapters::ActiveRecord4Adapter
- Inherits:
-
AbstractAdapter
- Object
- AbstractAdapter
- CanCan::ModelAdapters::ActiveRecord4Adapter
- Includes:
- ActiveRecordAdapter
- Defined in:
- lib/cancan/model_adapters/active_record_4_adapter.rb
Class Method Summary collapse
- .for_class?(model_class) ⇒ Boolean
-
.matches_condition?(subject, name, value) ⇒ Boolean
TODO: this should be private.
-
.override_condition_matching?(subject, name, _value) ⇒ Boolean
TODO: this should be private.
Methods included from ActiveRecordAdapter
#calculate_nested, #calculate_result_hash, #conditions, #database_records, #extract_multiple_conditions, #tableized_conditions
Methods included from CanCan::ModelAdapters::ActiveRecordAdapter::Joins
Methods inherited from AbstractAdapter
adapter_class, #database_records, find, inherited, #initialize, matches_conditions_hash?, override_conditions_hash_matching?
Constructor Details
This class inherits a constructor from CanCan::ModelAdapters::AbstractAdapter
Class Method Details
.for_class?(model_class) ⇒ Boolean
5 6 7 |
# File 'lib/cancan/model_adapters/active_record_4_adapter.rb', line 5 def self.for_class?(model_class) model_class <= ActiveRecord::Base end |
.matches_condition?(subject, name, value) ⇒ Boolean
TODO: this should be private
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/cancan/model_adapters/active_record_4_adapter.rb', line 15 def self.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
TODO: this should be private
10 11 12 |
# File 'lib/cancan/model_adapters/active_record_4_adapter.rb', line 10 def self.override_condition_matching?(subject, name, _value) subject.class.defined_enums.include?(name.to_s) end |