class ForeverAlone::Validator

Attributes

message[R]
timeout[R]

Public Class Methods

new(message, timeout=nil) click to toggle source
# File lib/forever-alone/validator.rb, line 6
def initialize message, timeout=nil
  @message = message
  @timeout = timeout || ForeverAlone.configuration.timeout
end

Public Instance Methods

ensure() click to toggle source
# File lib/forever-alone/validator.rb, line 24
def ensure
  raise ForeverAlone::MessageIsNotUnique, self.inspect unless unique?
  remember
end
flush_locks() click to toggle source
# File lib/forever-alone/validator.rb, line 15
def flush_locks
  keys = ForeverAlone.redis.keys "#{ ForeverAlone.configuration.namespace }:*"
  ForeverAlone.redis.del keys if keys.any?
end
key() click to toggle source
# File lib/forever-alone/validator.rb, line 29
def key
  @key ||= generate_key
end
remember() click to toggle source
# File lib/forever-alone/validator.rb, line 20
def remember
  ForeverAlone.redis.setex key, timeout, 'foo'
end
unique?() click to toggle source
# File lib/forever-alone/validator.rb, line 11
def unique?
  ForeverAlone.redis.get(key).nil?
end

Private Instance Methods

generate_key() click to toggle source
# File lib/forever-alone/validator.rb, line 35
def generate_key
  digest = ForeverAlone.configuration.digest.hexdigest message

  [
    ForeverAlone.configuration.namespace,
    digest
  ].join(':')
end