Module: MongoidAbility::Subject::ClassMethods
- Defined in:
- lib/mongoid_ability/subject.rb
Instance Method Summary collapse
- #ancestors_with_default_locks ⇒ Object
- #default_lock(lock_cls, action, outcome, options = {}) ⇒ Object
- #default_locks ⇒ Object
- #default_locks=(locks) ⇒ Object
- #has_default_lock_for_action?(action) ⇒ Boolean
- #is_root_class? ⇒ Boolean
- #reset_default_locks! ⇒ Object
- #root_class ⇒ Object
- #self_and_ancestors_with_default_locks ⇒ Object
Instance Method Details
#ancestors_with_default_locks ⇒ Object
52 53 54 |
# File 'lib/mongoid_ability/subject.rb', line 52 def ancestors_with_default_locks self_and_ancestors_with_default_locks - [self] end |
#default_lock(lock_cls, action, outcome, options = {}) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/mongoid_ability/subject.rb', line 36 def default_lock(lock_cls, action, outcome, = {}) lock = lock_cls.new(subject_type: to_s, action: action, outcome: outcome, options: ) # remove any existing locks if existing_lock = default_locks.detect { |l| l.action == lock.action && l. == lock. } default_locks.delete(existing_lock) end # add new lock default_locks.push(lock) end |
#default_locks ⇒ Object
24 25 26 |
# File 'lib/mongoid_ability/subject.rb', line 24 def default_locks @default_locks ||= LocksDecorator.new([]) end |
#default_locks=(locks) ⇒ Object
32 33 34 |
# File 'lib/mongoid_ability/subject.rb', line 32 def default_locks=(locks) @default_locks = locks end |
#has_default_lock_for_action?(action) ⇒ Boolean
64 65 66 |
# File 'lib/mongoid_ability/subject.rb', line 64 def has_default_lock_for_action?(action) default_locks.for_action(action).present? end |
#is_root_class? ⇒ Boolean
56 57 58 |
# File 'lib/mongoid_ability/subject.rb', line 56 def is_root_class? root_class == self end |
#reset_default_locks! ⇒ Object
28 29 30 |
# File 'lib/mongoid_ability/subject.rb', line 28 def reset_default_locks! @default_locks = LocksDecorator.new([]) end |
#root_class ⇒ Object
60 61 62 |
# File 'lib/mongoid_ability/subject.rb', line 60 def root_class self_and_ancestors_with_default_locks.last end |
#self_and_ancestors_with_default_locks ⇒ Object
48 49 50 |
# File 'lib/mongoid_ability/subject.rb', line 48 def self_and_ancestors_with_default_locks ancestors.select { |a| a.is_a?(Class) && a.respond_to?(:default_locks) } end |