Module: MongoidAbility::Lock
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/mongoid_ability/lock.rb
Class Method Summary collapse
Instance Method Summary collapse
- #class_lock? ⇒ Boolean
- #closed? ⇒ Boolean
- #group_key_for_calc ⇒ Object
- #id_lock? ⇒ Boolean
-
#inherited_outcome(options = {}) ⇒ Object
calculates outcome as if this lock is not present.
- #open? ⇒ Boolean
- #subject_class ⇒ Object
Class Method Details
.sort ⇒ Object
41 42 43 44 45 46 |
# File 'lib/mongoid_ability/lock.rb', line 41 def self.sort -> (a, b) { [a.subject_type, a.subject_id.to_s, a.action, (a.outcome ? -1 : 1)] <=> [b.subject_type, b.subject_id.to_s, b.action, (b.outcome ? -1 : 1)] } end |
Instance Method Details
#class_lock? ⇒ Boolean
48 49 50 |
# File 'lib/mongoid_ability/lock.rb', line 48 def class_lock? !id_lock? end |
#closed? ⇒ Boolean
60 61 62 |
# File 'lib/mongoid_ability/lock.rb', line 60 def closed? !open? end |
#group_key_for_calc ⇒ Object
78 79 80 |
# File 'lib/mongoid_ability/lock.rb', line 78 def group_key_for_calc [subject_type, subject_id, action, ] end |
#id_lock? ⇒ Boolean
52 53 54 |
# File 'lib/mongoid_ability/lock.rb', line 52 def id_lock? subject_id.present? end |
#inherited_outcome(options = {}) ⇒ Object
calculates outcome as if this lock is not present
65 66 67 68 69 70 71 72 |
# File 'lib/mongoid_ability/lock.rb', line 65 def inherited_outcome( = {}) return outcome unless owner.present? cloned_owner = owner.clone cloned_owner.locks_relation = cloned_owner.locks_relation - [self] cloned_ability = MongoidAbility::Ability.new(cloned_owner) cloned_ability.can?(action, (subject.present? ? subject : subject_class), ) end |
#open? ⇒ Boolean
56 57 58 |
# File 'lib/mongoid_ability/lock.rb', line 56 def open? outcome end |
#subject_class ⇒ Object
74 75 76 |
# File 'lib/mongoid_ability/lock.rb', line 74 def subject_class subject_type.constantize end |