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
39 40 41 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 39 def class_locks compact.select(&:class_lock?) end |
#for_action(action) ⇒ Object
7 8 9 10 11 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 7 def for_action(action) compact.select do |lock| lock.action == action.to_sym end end |
#for_subject(subject) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 32 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
26 27 28 29 30 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 26 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
13 14 15 16 17 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 13 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
19 20 21 22 23 24 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 19 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
43 44 45 |
# File 'lib/mongoid_ability/locks_decorator.rb', line 43 def id_locks compact.select(&:id_lock?) end |