Sha256: ce98a0a80dc50c8d77a553171bf368842b1bc9064063854da4b291fe7c3071fe

Contents?: true

Size: 761 Bytes

Versions: 6

Compression:

Stored size: 761 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 G;

# = Expirable
#
# Generic expiring functionality mixin. 
#
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

6 entries across 6 versions & 2 rubygems

Version Path
nitro-0.7.0 lib/glue/mixins.rb
nitro-0.6.0 lib/glue/mixins.rb
nitro-0.5.0 lib/glue/mixins.rb
og-0.5.0 lib/glue/mixins.rb
og-0.6.0 lib/glue/mixins.rb
og-0.7.0 lib/glue/mixins.rb