Sha256: a33851715f6c9cbb40847c4a579c159548242f8fd6cf6f9b29ceb3969ad06b6a

Contents?: true

Size: 778 Bytes

Versions: 4

Compression:

Stored size: 778 Bytes

Contents

module Adrian
  class Queue
    class ItemTooOldError < RuntimeError
      attr_reader :item, :queue

      def initialize(item, queue)
        super()
        @item  = item
        @queue = queue
      end
    end

    def initialize(options = {})
      @options = options
    end

    def pop
      verify_age!(pop_item)
    end

    def push(item)
      push_item(item)
    end

    def verify_age!(item)
      if item && max_age && item.age > max_age
        raise ItemTooOldError.new(item, self)
      end

      item
    end

    def max_age
      @max_age ||= @options[:max_age]
    end

    def pop_item
      raise "#{self.class.name}#pop_item is not defined"
    end

    def push_item(item)
      raise "#{self.class.name}#push_item is not defined"
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
adrian-1.3.3 lib/adrian/queue.rb
adrian-1.3.2 lib/adrian/queue.rb
adrian-1.3.1 lib/adrian/queue.rb
adrian-1.3.0 lib/adrian/queue.rb