Sha256: 6fd849a2933a9130d383e6c675a8ea88132c5a6269bb4f2e7cd4742cdafb2130

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

#--
# Expirable
#
# George Moschovitis
# Copyright (c) 2004-2005 Navel, all rights reserved.
#
# Ruby License
#
# This module is free software. You may use, modify, and/or redistribute this
# software under the same terms as Ruby.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
#
# ==========================================================================
# Revision History ::
# --------------------------------------------------------------------------
#  5.8.7  trans     Ported to Mega Modules
# ==========================================================================
#++

#:title: Expirable
#
# Generic expiring functionality mixin.
#
# == Usage
#
#   TODO: If anyone has an example of using this please submit. -T
#
# == Author(s)
#
# * George Moschovitis
#

module Expirable

  attr_accessor :expires

  # Set the expires timeout for this entry.

  def expires_after(timeout = (60*60*24))
    @expires = Time.now + timeout
  end

  # Set the expire timeout for this entry. The timeout happens
  # after (base + rand(spread)) seconds.

  def expires_spread(base, spread)
    @expires = Time.now + base + rand(spread)
  end

  # Is this entry expired?

  def expired?
    if @expires.nil? or (Time.now > @expires)
      return true
    else
      return false
    end
  end

end #Expirable

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mega-0.3.1 lib/mega/expirable.rb