Class: MongoidAbility::LocksDecorator
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- MongoidAbility::LocksDecorator
- Defined in:
- lib/mongoid_ability/locks_decorator.rb
Overview
adds scope-like methods on top of an Array containing locks
Instance Method Summary collapse
- #class_locks ⇒ Object
- #for_action(action) ⇒ Object
- #for_subject(subject) ⇒ Object
- #for_subject_id(subject_id) ⇒ Object
- #for_subject_type(subject_type) ⇒ Object
- #for_subject_types(subject_types) ⇒ Object
- #id_locks ⇒ Object
Instance Method Details
#class_locks ⇒ Object
37 38 39 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 37 def class_locks compact.select(&:class_lock?) end |
#for_action(action) ⇒ Object
5 6 7 8 9 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 5 def for_action(action) compact.select do |lock| lock.action == action.to_sym end end |
#for_subject(subject) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 30 def for_subject(subject) compact.select do |lock| lock.subject_type == subject.class.model_name && lock.subject_id == subject.id end end |
#for_subject_id(subject_id) ⇒ Object
24 25 26 27 28 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 24 def for_subject_id(subject_id) compact.select do |lock| lock.subject_id == BSON::ObjectId.from_string(subject_id) end end |
#for_subject_type(subject_type) ⇒ Object
11 12 13 14 15 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 11 def for_subject_type(subject_type) compact.select do |lock| lock.subject_type == subject_type.to_s end end |
#for_subject_types(subject_types) ⇒ Object
17 18 19 20 21 22 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 17 def for_subject_types(subject_types) subject_types = Array(subject_types).map(&:to_s) compact.select do |lock| subject_types.include?(lock.subject_type) end end |
#id_locks ⇒ Object
41 42 43 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 41 def id_locks compact.select(&:id_lock?) end |