Module: MongoidAbility::Lock

Extended by:
ActiveSupport::Concern
Defined in:
lib/mongoid_ability/lock.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.sortObject



41
42
43
44
45
46
# File 'lib/mongoid_ability/lock.rb', line 41

def self.sort
  -> (a, b) {
    [a.subject_type, a.subject_id.to_s, a.action, (a.outcome ? -1 : 1)] <=>
      [b.subject_type, b.subject_id.to_s, b.action, (b.outcome ? -1 : 1)]
  }
end

Instance Method Details

#class_lock?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/mongoid_ability/lock.rb', line 48

def class_lock?
  !id_lock?
end

#closed?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/mongoid_ability/lock.rb', line 60

def closed?
  !open?
end

#group_key_for_calcObject



78
79
80
# File 'lib/mongoid_ability/lock.rb', line 78

def group_key_for_calc
  [subject_type, subject_id, action, options]
end

#id_lock?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/mongoid_ability/lock.rb', line 52

def id_lock?
  subject_id.present?
end

#inherited_outcome(options = {}) ⇒ Object

calculates outcome as if this lock is not present



65
66
67
68
69
70
71
72
# File 'lib/mongoid_ability/lock.rb', line 65

def inherited_outcome(options = {})
  return outcome unless owner.present?
  cloned_owner = owner.clone
  cloned_owner.locks_relation = cloned_owner.locks_relation - [self]
  cloned_ability = MongoidAbility::Ability.new(cloned_owner)

  cloned_ability.can?(action, (subject.present? ? subject : subject_class), options)
end

#open?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/mongoid_ability/lock.rb', line 56

def open?
  outcome
end

#subject_classObject



74
75
76
# File 'lib/mongoid_ability/lock.rb', line 74

def subject_class
  subject_type.constantize
end