Module: MongoidAbility::Owner

Defined in:
lib/mongoid_ability/owner.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
7
8
9
# File 'lib/mongoid_ability/owner.rb', line 3

def self.included base
  base.extend ClassMethods
  base.class_eval do
    delegate :can?, :cannot?, to: :ability
    before_save :cleanup_locks
  end
end

Instance Method Details

#ability ⇒ Object



37
38
39
# File 'lib/mongoid_ability/owner.rb', line 37

def ability
  @ability ||= MongoidAbility::Ability.new(self)
end

#has_lock?(lock) ⇒ Boolean


Returns:

  • (Boolean)


43
44
45
# File 'lib/mongoid_ability/owner.rb', line 43

def has_lock? lock
  locks_relation.where(action: lock.action, subject_type: lock.subject_type, subject_id: lock.subject_id.presence).exists?
end

#inherit_from_relation ⇒ Object



33
34
35
# File 'lib/mongoid_ability/owner.rb', line 33

def inherit_from_relation
  self.send(self.class.inherit_from_relation_name)
end

#locks_relation ⇒ Object




25
26
27
# File 'lib/mongoid_ability/owner.rb', line 25

def locks_relation
  self.send(self.class.locks_relation_name)
end

#locks_relation=(val) ⇒ Object



29
30
31
# File 'lib/mongoid_ability/owner.rb', line 29

def locks_relation= val
  self.send "#{self.class.locks_relation_name}=", val
end