Class: MongoidAbility::FindLock

Inherits:
Struct
  • Object
show all
Defined in:
lib/mongoid_ability/find_lock.rb

Overview

finds first lock that controls specified params

Direct Known Subclasses

FindDefaultLock, FindInheritedLock, FindOwnedLock

Defined Under Namespace

Classes: FindDefaultLock, FindInheritedLock, FindOwnedLock

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, action, subject_type, subject_id = nil, options = {}) ⇒ FindLock

Returns a new instance of FindLock.



11
12
13
# File 'lib/mongoid_ability/find_lock.rb', line 11

def initialize(owner, action, subject_type, subject_id = nil, options = {})
  super(owner, action, subject_type.to_s, subject_id, options)
end

Instance Attribute Details

#actionObject

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



6
7
8
# File 'lib/mongoid_ability/find_lock.rb', line 6

def action
  @action
end

#optionsObject

Returns the value of attribute options

Returns:

  • (Object)

    the current value of options



6
7
8
# File 'lib/mongoid_ability/find_lock.rb', line 6

def options
  @options
end

#ownerObject

Returns the value of attribute owner

Returns:

  • (Object)

    the current value of owner



6
7
8
# File 'lib/mongoid_ability/find_lock.rb', line 6

def owner
  @owner
end

#subject_idObject

Returns the value of attribute subject_id

Returns:

  • (Object)

    the current value of subject_id



6
7
8
# File 'lib/mongoid_ability/find_lock.rb', line 6

def subject_id
  @subject_id
end

#subject_typeObject

Returns the value of attribute subject_type

Returns:

  • (Object)

    the current value of subject_type



6
7
8
# File 'lib/mongoid_ability/find_lock.rb', line 6

def subject_type
  @subject_type
end

Class Method Details

.call(*args) ⇒ Object



7
8
9
# File 'lib/mongoid_ability/find_lock.rb', line 7

def self.call(*args)
  new(*args).call
end

Instance Method Details

#callObject



15
16
17
18
19
20
21
22
23
# File 'lib/mongoid_ability/find_lock.rb', line 15

def call
  lock = nil
  subject_class.self_and_ancestors_with_default_locks.each do |cls|
    break if lock = FindOwnedLock.call(owner, action, cls, subject_id, options)
    break if lock = FindInheritedLock.call(owner, action, cls, subject_id, options)
    break if lock = FindDefaultLock.call(owner, action, cls, subject_id, options)
  end
  lock
end