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