Class: T1000::Lock

Inherits:
Struct
  • Object
show all
Defined in:
lib/t-1000/lock.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ipObject

Returns the value of attribute ip

Returns:

  • (Object)

    the current value of ip



2
3
4
# File 'lib/t-1000/lock.rb', line 2

def ip
  @ip
end

Instance Method Details

#keyObject



4
5
6
# File 'lib/t-1000/lock.rb', line 4

def key
  @key ||= ActiveSupport::Cache.expand_cache_key [ip], :ip_lock
end

#lock!(time = 1.minute) ⇒ Object



8
9
10
# File 'lib/t-1000/lock.rb', line 8

def lock!(time = 1.minute)
  T1000.cache.store.write(key, true, expires_in: time)
end

#locked?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/t-1000/lock.rb', line 12

def locked?
  !!T1000.cache.store.read(key)
end