Module: Marloss::InstanceMethods

Defined in:
lib/marloss.rb

Instance Method Summary collapse

Instance Method Details

#marloss_locker(name) ⇒ Object



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

def marloss_locker(name)
  Locker.new(marloss_store, name)
end

#marloss_storeObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/marloss.rb', line 36

def marloss_store
  @marloss_store ||= begin
    table = marloss_options_hash[:table]
    hash_key = marloss_options_hash[:hash_key]
    options = marloss_options_hash.reject do |k, _|
      %i[table hash_key].include?(k)
    end

    Store.new(table, hash_key, options)
  end
end

#with_marloss_locker(name, opts = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/marloss.rb', line 52

def with_marloss_locker(name, opts = {})
  has_lock = false
  locker = marloss_locker(name)

  locker.wait_until_lock_obtained(opts)
  has_lock = true

  yield(locker)
ensure
  locker.release_lock if has_lock
end