Class: CanCan::ModelAdapters::AbstractAdapter
- Inherits:
-
Object
- Object
- CanCan::ModelAdapters::AbstractAdapter
- Defined in:
- lib/cancan/model_adapters/abstract_adapter.rb
Direct Known Subclasses
ActiveRecordAdapter, DataMapperAdapter, DefaultAdapter, MongoidAdapter
Class Method Summary (collapse)
- + (Object) adapter_class(model_class)
-
+ (Object) find(model_class, id)
Override if you need custom find behavior.
-
+ (Boolean) for_class?(member_class)
Used to determine if the given adapter should be used for the passed in class.
- + (Object) inherited(subclass)
-
+ (Boolean) matches_condition?(subject, name, value)
Override if override_condition_matching? returns true.
-
+ (Boolean) matches_conditions_hash?(subject, conditions)
Override if override_conditions_hash_matching? returns true.
-
+ (Boolean) override_condition_matching?(subject, name, value)
Used to determine if this model adapter will override the matching behavior for a specific condition.
-
+ (Boolean) override_conditions_hash_matching?(subject, conditions)
Used to determine if this model adapter will override the matching behavior for a hash of conditions.
Instance Method Summary (collapse)
- - (Object) database_records
-
- (AbstractAdapter) initialize(model_class, rules)
constructor
A new instance of AbstractAdapter.
Constructor Details
- (AbstractAdapter) initialize(model_class, rules)
A new instance of AbstractAdapter
45 46 47 48 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 45 def initialize(model_class, rules) @model_class = model_class @rules = rules end |
Class Method Details
+ (Object) adapter_class(model_class)
9 10 11 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 9 def self.adapter_class(model_class) @subclasses.detect { |subclass| subclass.for_class?(model_class) } || DefaultAdapter end |
+ (Object) find(model_class, id)
Override if you need custom find behavior
19 20 21 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 19 def self.find(model_class, id) model_class.find(id) end |
+ (Boolean) for_class?(member_class)
Used to determine if the given adapter should be used for the passed in class.
14 15 16 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 14 def self.for_class?(member_class) false # override in subclass end |
+ (Object) inherited(subclass)
4 5 6 7 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 4 def self.inherited(subclass) @subclasses ||= [] @subclasses << subclass end |
+ (Boolean) matches_condition?(subject, name, value)
Override if override_condition_matching? returns true
41 42 43 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 41 def self.matches_condition?(subject, name, value) raise NotImplemented, "This model adapter does not support matching on a specific condition." end |
+ (Boolean) matches_conditions_hash?(subject, conditions)
Override if override_conditions_hash_matching? returns true
30 31 32 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 30 def self.matches_conditions_hash?(subject, conditions) raise NotImplemented, "This model adapter does not support matching on a conditions hash." end |
+ (Boolean) override_condition_matching?(subject, name, value)
Used to determine if this model adapter will override the matching behavior for a specific condition. If this returns true then matches_condition? will be called. See Rule#matches_conditions_hash
36 37 38 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 36 def self.override_condition_matching?(subject, name, value) false end |
+ (Boolean) override_conditions_hash_matching?(subject, conditions)
Used to determine if this model adapter will override the matching behavior for a hash of conditions. If this returns true then matches_conditions_hash? will be called. See Rule#matches_conditions_hash
25 26 27 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 25 def self.override_conditions_hash_matching?(subject, conditions) false end |
Instance Method Details
- (Object) database_records
50 51 52 53 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 50 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 |