Module: MongoidAbility::Subject::ClassMethods
- Defined in:
- lib/mongoid_ability/subject.rb
Instance Method Summary collapse
-
#accessible_by(ability, action = :read, options = {}) ⇒ Object
———————————————————————.
- #ancestors_with_default_locks ⇒ Object
- #default_lock(lock_cls, action, outcome, options = {}) ⇒ Object
-
#default_lock_for_action(action) ⇒ Object
———————————————————————.
- #default_locks ⇒ Object
- #default_locks=(locks) ⇒ Object
- #has_default_lock_for_action?(action) ⇒ Boolean
- #is_root_class? ⇒ Boolean
- #root_class ⇒ Object
-
#self_and_ancestors_with_default_locks ⇒ Object
———————————————————————.
Instance Method Details
#accessible_by(ability, action = :read, options = {}) ⇒ Object
60 61 62 |
# File 'lib/mongoid_ability/subject.rb', line 60 def accessible_by(ability, action = :read, = {}) AccessibleQueryBuilder.call(self, ability, action, ) end |
#ancestors_with_default_locks ⇒ Object
36 37 38 |
# File 'lib/mongoid_ability/subject.rb', line 36 def ancestors_with_default_locks self_and_ancestors_with_default_locks - [self] end |
#default_lock(lock_cls, action, outcome, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/mongoid_ability/subject.rb', line 18 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 } default_locks.delete(existing_lock) end # add new lock default_locks.push lock end |
#default_lock_for_action(action) ⇒ Object
50 51 52 |
# File 'lib/mongoid_ability/subject.rb', line 50 def default_lock_for_action(action) default_locks.detect { |lock| lock.action == action.to_sym } end |
#default_locks ⇒ Object
10 11 12 |
# File 'lib/mongoid_ability/subject.rb', line 10 def default_locks @default_locks ||= [] end |
#default_locks=(locks) ⇒ Object
14 15 16 |
# File 'lib/mongoid_ability/subject.rb', line 14 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_lock_for_action(action).present? end |
#is_root_class? ⇒ Boolean
40 41 42 |
# File 'lib/mongoid_ability/subject.rb', line 40 def is_root_class? root_class == self end |
#root_class ⇒ Object
44 45 46 |
# File 'lib/mongoid_ability/subject.rb', line 44 def root_class self_and_ancestors_with_default_locks.last end |
#self_and_ancestors_with_default_locks ⇒ Object
32 33 34 |
# File 'lib/mongoid_ability/subject.rb', line 32 def self_and_ancestors_with_default_locks ancestors.select { |a| a.is_a?(Class) && a.respond_to?(:default_locks) } end |