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
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/mongoid_ability/owner.rb', line 3 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
40 41 42 |
# File 'lib/mongoid_ability/owner.rb', line 40 def ability @ability ||= MongoidAbility::Ability.new(self) end |
#has_lock?(lock) ⇒ Boolean
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/mongoid_ability/owner.rb', line 44 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
35 36 37 38 |
# File 'lib/mongoid_ability/owner.rb', line 35 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
25 26 27 28 |
# File 'lib/mongoid_ability/owner.rb', line 25 def locks_relation return unless respond_to?(self.class.locks_relation_name) send(self.class.locks_relation_name) end |
#locks_relation=(val) ⇒ Object
30 31 32 33 |
# File 'lib/mongoid_ability/owner.rb', line 30 def locks_relation=(val) return unless respond_to?("#{self.class.locks_relation_name}=") send "#{self.class.locks_relation_name}=", val end |