class CanCan::ModelAdapters::AbstractAdapter
def self.adapter_class(model_class)
def self.adapter_class(model_class) @subclasses.detect { |subclass| subclass.for_class?(model_class) } || DefaultAdapter end
def self.find(model_class, id)
def self.find(model_class, id) model_class.find(id) end
def self.for_class?(_member_class)
def self.for_class?(_member_class) false # override in subclass end
def self.inherited(subclass)
def self.inherited(subclass) @subclasses ||= [] @subclasses.insert(0, subclass) end
def self.matches_condition?(_subject, _name, _value)
def self.matches_condition?(_subject, _name, _value) raise NotImplemented, 'This model adapter does not support matching on a specific condition.' end
def self.matches_conditions_hash?(_subject, _conditions)
def self.matches_conditions_hash?(_subject, _conditions) raise NotImplemented, 'This model adapter does not support matching on a conditions hash.' end
def self.nested_subject_matches_conditions?(_parent, _child, _all_conditions)
def self.nested_subject_matches_conditions?(_parent, _child, _all_conditions) raise NotImplemented, 'This model adapter does not support matching on a nested subject.' end
def self.override_condition_matching?(_subject, _name, _value)
Used to determine if this model adapter will override the matching behavior for a specific condition.
def self.override_condition_matching?(_subject, _name, _value) false end
def self.override_conditions_hash_matching?(_subject, _conditions)
Used to determine if this model adapter will override the matching behavior for a hash of conditions.
def self.override_conditions_hash_matching?(_subject, _conditions) false end
def self.override_nested_subject_conditions_matching?(_parent, _child, _all_conditions)
matching behavior for nested subject.
Used above override_conditions_hash_matching to determine if this model adapter will override the
def self.override_nested_subject_conditions_matching?(_parent, _child, _all_conditions) false end
def self.parent_condition_name(parent, _child)
def self.parent_condition_name(parent, _child) parent.class.name.downcase.to_sym end
def database_records
def database_records # This should be overridden in a subclass to return records which match @rules raise NotImplemented, 'This model adapter does not support fetching records from the database.' end
def initialize(model_class, rules)
def initialize(model_class, rules) @model_class = model_class @rules = rules end