Module: Mongo::Locking::ModelMethods::ClassMethods

Defined in:
lib/mongo/locking/model_methods.rb

Instance Method Summary collapse

Instance Method Details

#lockable!(opts = {}) ⇒ Object

Options:

:key   => Symbol (sent to self), Proc (passed self) -> result.to_s
:scope => String, Symbol (default self.name)

:max_retries          => default 5
:first_retry_interval => default 0.2.seconds
:max_retry_interval   => default 5.seconds
:max_lifetime         => default 1.minute

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mongo/locking/model_methods.rb', line 23

def lockable!(opts = {})
    key   = opts[:key]   ||= :id
    scope = opts[:scope] ||= self.name

    raise ArgumentError, "locker key must be a Proc or Symbol" unless [Proc, Symbol].include?(key.class)
    raise ArgumentError, "locker scope must be a Proc, Symbol or String" unless [Proc, Symbol, String].include?(scope.class)

    opts[:class_name] = self.name
    @locker = Locker.new(opts)

    return self
end

#locked_by!(*args, &parent) ⇒ Object

Options:

:parent => instance of lockable parent

Raises:



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mongo/locking/model_methods.rb', line 40

def locked_by!(*args, &parent)
    opts   = args.extract_options!
    parent = opts[:parent] ||= parent || args.first

    raise ArgumentError, "parent reference must be a Proc or Symbol" unless [Proc, Symbol].include?(parent.class)

    opts[:class_name] = self.name

    @locker = Locker.new(opts)

    return self
end

#lockerObject

No-frills class-inheritable locker reference



54
55
56
# File 'lib/mongo/locking/model_methods.rb', line 54

def locker
    @locker ||= (superclass.locker if superclass.respond_to?(:locker))
end