Sha256: 7124800e67f6f131a2cbca89c9db3018a4dd4724c610a44c3b255ecd1dd4e802

Contents?: true

Size: 797 Bytes

Versions: 3

Compression:

Stored size: 797 Bytes

Contents

# = Mixins 
#
# A collection of useful mixins. Use these to synthesize your 
# entities.
#
# code: 
# George Moschovitis  <gm@navel.gr>
#
# (c) 2004 Navel, all rights reserved.
# $Id$

module N;

# = Expirable
#
# Generic expiring functionality mixin. This is not exclusive
# for entities.
#
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
	
end # module

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nitro-0.1.2 lib/n/mixins.rb
nitro-0.2.0 lib/n/mixins.rb
nitro-0.3.0 lib/n/mixins.rb