class UnifiedQueues::Single

Universal single queue interface.

Universal single queue interface.

Universal single queue interface.

Universal single queue interface.

Universal single queue interface.

Universal single queue interface.

Universal single queue interface.

Universal single queue interface.

Constants

DRIVERS

Contains assignment of classnames to drivers. @return [Hash]

Attributes

driver[RW]

Contains driver for specific class instance. @return [UnifiedQueues::Single::Driver] driver instance

Public Class Methods

new(cls, *args, &block) click to toggle source

Constructor.

@param [Class|UnifiedQueues::Single::Driver] cls required class object or driver instance @param [Array] *args array of arguments for the queue constructor @param [Proc] &block block for the queue constructor

# File lib/unified-queues/single.rb, line 51
def initialize(cls, *args, &block)
    if cls.kind_of? UnifiedQueues::Single::Driver
        @driver = cls
    else
        self.assign_driver(cls, args, block)
    end
end

Public Instance Methods

<<(value, key = value, &block)
Alias for: push
assign_driver(cls, args, block) click to toggle source

Assigns driver to interface according to given class name.

@param [Class] cls required class @param [Array] args array of arguments for the queue constructor @param [Proc] block block for the queue constructor @return [UnifiedQueues::Single::Driver] new driver instance

# File lib/unified-queues/single.rb, line 68
def assign_driver(cls, args, block)
    _cls = cls
    if not _cls.kind_of? Class
        _cls = cls.class
    end
    
    driver = nil
    name = nil
    
    self.class::DRIVERS.each_pair do |_name, _driver|
        begin
            _module = Module::get_module(_name.to_s)
        rescue NameError
            next
        end
        
        if _cls <= _module
            driver = _driver
            name = _name
            break
        end
    end
    
    ###
    
    require "unified-queues/single/driver/" << driver
    
    path = name.to_s.split("::")
    classname = path.shift << 'Driver::' << path.join('::')
    _module = Module::get_module("UnifiedQueues::Single::Driver::" << classname)
    
    args = [cls] + args
    @driver = _module::new(*args, &block)
    return @driver
end
clear(&block)
Alias for: clear!
clear!(&block) click to toggle source

Clears the queue.

# File lib/unified-queues/single.rb, line 143
def clear!(&block)
    @driver.clear!(&block)
end
Also aliased as: clear
empty?(&block) click to toggle source

Indicates queue is empty. @param [Boolean] true if it's, false otherwise

# File lib/unified-queues/single.rb, line 135
def empty?(&block)
    @driver.empty?(&block)
end
length(&block) click to toggle source

Returns length of the queue. @return [Integer]

# File lib/unified-queues/single.rb, line 154
def length(&block)
    @driver.length(&block)
end
Also aliased as: size
pop(blocking = false, &block) click to toggle source

Pops value out of the queue.

@param [Boolean|Integer] blocking true or timeout if it should block, false otherwise @param [Object] queue value

# File lib/unified-queues/single.rb, line 124
def pop(blocking = false, &block)
    @driver.pop(blocking, &block)
end
Also aliased as: pop!
pop!(blocking = false, &block)
Alias for: pop
push(value, key = value, &block) click to toggle source

Pushes the value into the queue.

@param [Object] value value for push @param [Object] key key for priority queues

# File lib/unified-queues/single.rb, line 111
def push(value, key = value, &block)
    @driver.push(value, key, &block)
end
Also aliased as: <<
size(&block)
Alias for: length