Module: MongoidAbility::Owner
- Defined in:
- lib/mongoid_ability/owner.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #ability ⇒ Object
- #has_lock?(lock) ⇒ Boolean
- #inherit_from_relation ⇒ Object
- #locks_relation ⇒ Object
- #locks_relation=(val) ⇒ Object
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mongoid_ability/owner.rb', line 5 def self.included(base) base.extend ClassMethods base.class_eval do include Mongoid::Touchable::InstanceMethods delegate :can?, :cannot?, to: :ability before_save :cleanup_locks end end |
Instance Method Details
#ability ⇒ Object
42 43 44 |
# File 'lib/mongoid_ability/owner.rb', line 42 def ability @ability ||= MongoidAbility::Ability.new(self) end |
#has_lock?(lock) ⇒ Boolean
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mongoid_ability/owner.rb', line 46 def has_lock?(lock) @has_lock ||= {} return @has_lock[lock.id.to_s] if @has_lock.key?(lock.id.to_s) @has_lock[lock.id.to_s] ||= begin locks_relation.where( subject_type: lock.subject_type, subject_id: lock.subject_id.presence, action: lock.action, options: lock. ).exists? end end |
#inherit_from_relation ⇒ Object
37 38 39 40 |
# File 'lib/mongoid_ability/owner.rb', line 37 def inherit_from_relation return unless respond_to?(self.class.inherit_from_relation_name) send(self.class.inherit_from_relation_name) end |
#locks_relation ⇒ Object
27 28 29 30 |
# File 'lib/mongoid_ability/owner.rb', line 27 def locks_relation return unless respond_to?(self.class.locks_relation_name) send(self.class.locks_relation_name) end |
#locks_relation=(val) ⇒ Object
32 33 34 35 |
# File 'lib/mongoid_ability/owner.rb', line 32 def locks_relation=(val) return unless respond_to?("#{self.class.locks_relation_name}=") send "#{self.class.locks_relation_name}=", val end |