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
40 41 42 |
# File 'lib/mongoid_ability/subject.rb', line 40 def ancestors_with_default_locks self_and_ancestors_with_default_locks - [self] end |
#default_lock(lock_cls, action, outcome, options = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mongoid_ability/subject.rb', line 24 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
12 13 14 |
# File 'lib/mongoid_ability/subject.rb', line 12 def default_locks @default_locks ||= LocksDecorator.new([]) end |
#default_locks=(locks) ⇒ Object
20 21 22 |
# File 'lib/mongoid_ability/subject.rb', line 20 def default_locks=(locks) @default_locks = locks end |
#has_default_lock_for_action?(action) ⇒ Boolean
52 53 54 |
# File 'lib/mongoid_ability/subject.rb', line 52 def has_default_lock_for_action?(action) default_locks.for_action(action).present? end |
#is_root_class? ⇒ Boolean
44 45 46 |
# File 'lib/mongoid_ability/subject.rb', line 44 def is_root_class? root_class == self end |
#reset_default_locks! ⇒ Object
16 17 18 |
# File 'lib/mongoid_ability/subject.rb', line 16 def reset_default_locks! @default_locks = LocksDecorator.new([]) end |
#root_class ⇒ Object
48 49 50 |
# File 'lib/mongoid_ability/subject.rb', line 48 def root_class self_and_ancestors_with_default_locks.last end |
#self_and_ancestors_with_default_locks ⇒ Object
36 37 38 |
# File 'lib/mongoid_ability/subject.rb', line 36 def self_and_ancestors_with_default_locks ancestors.select { |a| a.is_a?(Class) && a.respond_to?(:default_locks) } end |