Sha256: b7ee69260bfbb8a5aa10d41ede2341cdcc10b8608971604e4fe290adf1948213

Contents?: true

Size: 845 Bytes

Versions: 6

Compression:

Stored size: 845 Bytes

Contents

# encoding: UTF-8

module CASServer::Model
  module Consumable
    def consume!
      self.consumed = Time.now
      self.save!
    end

    def self.included(mod)
      mod.extend(ClassMethods)
    end

    module ClassMethods
      def cleanup(max_lifetime, max_unconsumed_lifetime)
        transaction do
          conditions = ["created_on < ? OR (consumed IS NULL AND created_on < ?)",
                          Time.now - max_lifetime,
                          Time.now - max_unconsumed_lifetime]
                        
          expired_tickets_count = count(:conditions => conditions)

          $LOG.debug("Destroying #{expired_tickets_count} expired #{self.name.demodulize}"+
            "#{'s' if expired_tickets_count > 1}.") if expired_tickets_count > 0

          destroy_all(conditions)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
synapse-rubycas-server-1.1.6 lib/casserver/model/consumable.rb
synapse-rubycas-server-1.1.5.pre lib/casserver/model/consumable.rb
synapse-rubycas-server-1.1.4.pre lib/casserver/model/consumable.rb
synapse-rubycas-server-1.1.4 lib/casserver/model/consumable.rb
synapse-rubycas-server-1.1.3alpha lib/casserver/model/consumable.rb
synapse-rubycas-server-1.1.3.pre lib/casserver/model/consumable.rb