Module: LockMethod

Defined in:
lib/lock_method.rb,
lib/lock_method/lock.rb,
lib/lock_method/config.rb,
lib/lock_method/version.rb,
lib/lock_method/default_storage_client.rb

Overview

See the README.rdoc for more info!

Defined Under Namespace

Modules: ClassMethods, InstanceMethods Classes: Config, DefaultStorageClient, Lock, Locked

Constant Summary collapse

VERSION =
"0.5.5"

Class Method Summary collapse

Class Method Details

.configObject

:nodoc:



19
20
21
22
23
# File 'lib/lock_method.rb', line 19

def LockMethod.config #:nodoc:
  @config || ::Thread.exclusive do
    @config ||= Config.new
  end
end

.digest(obj) ⇒ Object



59
60
61
# File 'lib/lock_method.rb', line 59

def LockMethod.digest(obj)
  ::Digest::SHA1.hexdigest ::Marshal.dump(resolve_lock(obj))
end

.klass_name(obj) ⇒ Object



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

def LockMethod.klass_name(obj)
  (obj.is_a?(::Class) or obj.is_a?(::Module)) ? obj.to_s : obj.class.to_s
end

.method_delimiter(obj) ⇒ Object



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

def LockMethod.method_delimiter(obj)
  (obj.is_a?(::Class) or obj.is_a?(::Module)) ? '.' : '#'
end

.method_signature(obj, method_id) ⇒ Object



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

def LockMethod.method_signature(obj, method_id)
  [ klass_name(obj), method_id ].join method_delimiter(obj)
end

.original_method_id(method_id) ⇒ Object



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

def LockMethod.original_method_id(method_id)
  "_unlocked_#{method_id}"
end

.resolve_lock(obj) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/lock_method.rb', line 41

def LockMethod.resolve_lock(obj)
  case obj
  when ::Array
    obj.map do |v|
      resolve_lock v
    end
  when ::Hash
    obj.inject({}) do |memo, (k, v)|
      kk = resolve_lock k
      vv = resolve_lock v
      memo[kk] = vv
      memo
    end
  else
    obj.respond_to?(:as_lock) ? [obj.class.name, obj.as_lock] : obj
  end
end