class MongoidAbility::FindLock::FindInheritedLock

Public Instance Methods

call() click to toggle source
# File lib/mongoid_ability/find_lock.rb, line 39
def call
  return unless owner.respond_to?(owner.class.inherit_from_relation_name)
  locks = LocksDecorator.new(
    owner.inherit_from_relation
          .flat_map { |inherited_owner| FindOwnedLock.call(inherited_owner, action, subject_type, subject_id, options) }
  )

  if subject_id.present?
    lock = locks.for_subject_id(subject_id).detect(&:closed?) ||
           locks.for_subject_id(subject_id).detect(&:open?)
    return lock unless lock.nil?
  end

  locks.class_locks.detect(&:open?) || locks.class_locks.detect(&:closed?)
end