Class: CanCan::ModelAdapters::AbstractAdapter
- Inherits:
-
Object
- Object
- CanCan::ModelAdapters::AbstractAdapter
- Defined in:
- lib/cancan/model_adapters/abstract_adapter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
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.
-
.nested_subject_matches_conditions?(_parent, _child, _all_conditions) ⇒ Boolean
Override if override_nested_subject_conditions_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.
-
.override_nested_subject_conditions_matching?(_parent, _child, _all_conditions) ⇒ Boolean
Used above override_conditions_hash_matching to determine if this model adapter will override the matching behavior for nested subject.
-
.parent_condition_name(parent, _child) ⇒ Object
Override if parent condition could be under a different key in 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.
66 67 68 69 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 66 def initialize(model_class, rules) @model_class = model_class @rules = rules end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
6 7 8 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 6 def model_class @model_class end |
Class Method Details
.adapter_class(model_class) ⇒ Object
13 14 15 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 13 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
23 24 25 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 23 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.
18 19 20 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 18 def self.for_class?(_member_class) false # override in subclass end |
.inherited(subclass) ⇒ Object
8 9 10 11 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 8 def self.inherited(subclass) @subclasses ||= [] @subclasses.insert(0, subclass) end |
.matches_condition?(_subject, _name, _value) ⇒ Boolean
Override if override_condition_matching? returns true
62 63 64 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 62 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
34 35 36 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 34 def self.matches_conditions_hash?(_subject, _conditions) raise NotImplemented, 'This model adapter does not support matching on a conditions hash.' end |
.nested_subject_matches_conditions?(_parent, _child, _all_conditions) ⇒ Boolean
Override if override_nested_subject_conditions_matching? returns true
51 52 53 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 51 def self.nested_subject_matches_conditions?(_parent, _child, _all_conditions) raise NotImplemented, 'This model adapter does not support matching on a nested subject.' 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
57 58 59 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 57 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
29 30 31 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 29 def self.override_conditions_hash_matching?(_subject, _conditions) false end |
.override_nested_subject_conditions_matching?(_parent, _child, _all_conditions) ⇒ Boolean
Used above override_conditions_hash_matching to determine if this model adapter will override the matching behavior for nested subject. If this returns true then nested_subject_matches_conditions? will be called.
46 47 48 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 46 def self.override_nested_subject_conditions_matching?(_parent, _child, _all_conditions) false end |
.parent_condition_name(parent, _child) ⇒ Object
Override if parent condition could be under a different key in conditions
39 40 41 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 39 def self.parent_condition_name(parent, _child) parent.class.name.downcase.to_sym end |
Instance Method Details
#database_records ⇒ Object
71 72 73 74 |
# File 'lib/cancan/model_adapters/abstract_adapter.rb', line 71 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 |