Class: CanCan::ModelAdapters::AbstractAdapter
- Inherits:
-
Object
- Object
- CanCan::ModelAdapters::AbstractAdapter
- Defined in:
- lib/cancan/model_adapters/abstract_adapter.rb
Direct Known Subclasses
Class Method Summary collapse
- .adapter_class(model_class) ⇒ Object
-
.find(model_class, id) ⇒ Object
Override if you need custom find behavior.
-
.for_class?(_member_class) ⇒ Boolean
Used to determine if the given adapter should be used for the passed in class.
- .inherited(subclass) ⇒ Object
-
.matches_condition?(_subject, _name, _value) ⇒ Boolean
Override if override_condition_matching? returns true.
-
.matches_conditions_hash?(_subject, _conditions) ⇒ Boolean
Override if override_conditions_hash_matching? returns true.
-
.override_condition_matching?(_subject, _name, _value) ⇒ Boolean
Used to determine if this model adapter will override the matching behavior for a specific condition.
-
.override_conditions_hash_matching?(_subject, _conditions) ⇒ Boolean
Used to determine if this model adapter will override the matching behavior for a hash of conditions.
Instance Method Summary collapse
- #database_records ⇒ Object
-
#initialize(model_class, rules) ⇒ AbstractAdapter
constructor
A new instance of AbstractAdapter.
Constructor Details
#initialize(model_class, rules) ⇒ AbstractAdapter
Returns a new instance of AbstractAdapter.
47 48 49 50 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 47 def initialize(model_class, rules) @model_class = model_class @rules = rules end |
Class Method Details
.adapter_class(model_class) ⇒ Object
11 12 13 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 11 def self.adapter_class(model_class) @subclasses.detect { |subclass| subclass.for_class?(model_class) } || DefaultAdapter end |
.find(model_class, id) ⇒ Object
Override if you need custom find behavior
21 22 23 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 21 def self.find(model_class, id) model_class.find(id) end |
.for_class?(_member_class) ⇒ Boolean
Used to determine if the given adapter should be used for the passed in class.
16 17 18 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 16 def self.for_class?(_member_class) false # override in subclass end |
.inherited(subclass) ⇒ Object
6 7 8 9 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 6 def self.inherited(subclass) @subclasses ||= [] @subclasses.insert(0, subclass) end |
.matches_condition?(_subject, _name, _value) ⇒ Boolean
Override if override_condition_matching? returns true
43 44 45 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 43 def self.matches_condition?(_subject, _name, _value) raise NotImplemented, 'This model adapter does not support matching on a specific condition.' end |
.matches_conditions_hash?(_subject, _conditions) ⇒ Boolean
Override if override_conditions_hash_matching? returns true
32 33 34 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 32 def self.matches_conditions_hash?(_subject, _conditions) raise NotImplemented, 'This model adapter does not support matching on a conditions hash.' end |
.override_condition_matching?(_subject, _name, _value) ⇒ Boolean
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
38 39 40 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 38 def self.override_condition_matching?(_subject, _name, _value) false end |
.override_conditions_hash_matching?(_subject, _conditions) ⇒ Boolean
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
27 28 29 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 27 def self.override_conditions_hash_matching?(_subject, _conditions) false end |
Instance Method Details
#database_records ⇒ Object
52 53 54 55 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 52 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 |