Sha256: 7db635765b30ab7b3f0ce911313c0fde898c2b01cba772165d1fe7e303acbbf3

Contents?: true

Size: 760 Bytes

Versions: 6

Compression:

Stored size: 760 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. 
#
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.8.0 lib/glue/mixins.rb
nitro-0.9.3 lib/glue/mixins.rb
nitro-0.9.5 lib/glue/mixins.rb
og-0.8.0 lib/glue/mixins.rb
og-0.9.3 lib/glue/mixins.rb
og-0.9.5 lib/glue/mixins.rb