Class: CanCan::ModelAdapters::ActiveRecord5Adapter
- Inherits:
-
ActiveRecord4Adapter
- Object
- AbstractAdapter
- ActiveRecord4Adapter
- CanCan::ModelAdapters::ActiveRecord5Adapter
- Defined in:
- lib/cancan/model_adapters/active_record_5_adapter.rb
Class Method Summary collapse
- .for_class?(model_class) ⇒ Boolean
-
.matches_condition?(subject, name, value) ⇒ Boolean
rails 5 is capable of using strings in enum but often people use symbols in rules.
Methods inherited from ActiveRecord4Adapter
Methods included from ActiveRecordAdapter
#conditions, #database_records, #extract_multiple_conditions
Methods included from CanCan::ModelAdapters::ActiveRecordAdapter::Joins
Methods inherited from AbstractAdapter
adapter_class, #database_records, find, inherited, #initialize, matches_conditions_hash?, override_condition_matching?, override_conditions_hash_matching?
Constructor Details
This class inherits a constructor from CanCan::ModelAdapters::AbstractAdapter
Class Method Details
.for_class?(model_class) ⇒ Boolean
6 7 8 |
# File 'lib/cancan/model_adapters/active_record_5_adapter.rb', line 6 def self.for_class?(model_class) ActiveRecord::VERSION::MAJOR == 5 && model_class <= ActiveRecord::Base end |
.matches_condition?(subject, name, value) ⇒ Boolean
rails 5 is capable of using strings in enum but often people use symbols in rules
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cancan/model_adapters/active_record_5_adapter.rb', line 12 def self.matches_condition?(subject, name, value) return super if Array.wrap(value).all? { |x| x.is_a? Integer } attribute = subject.send(name) if value.is_a?(Enumerable) value.map(&:to_s).include? attribute else attribute == value.to_s end end |