class Dynflow::Director::QueueHash
Public Class Methods
new(key_type = Object, value_type = Object)
click to toggle source
# File lib/dynflow/director/queue_hash.rb, line 7 def initialize(key_type = Object, value_type = Object) @key_type = key_type @value_type = value_type @stash = Hash.new { |hash, key| hash[key] = [] } end
Public Instance Methods
clear()
click to toggle source
# File lib/dynflow/director/queue_hash.rb, line 32 def clear ret = @stash.dup @stash.clear ret end
empty?(key)
click to toggle source
# File lib/dynflow/director/queue_hash.rb, line 28 def empty?(key) !present?(key) end
first(key)
click to toggle source
# File lib/dynflow/director/queue_hash.rb, line 43 def first(key) return nil if empty?(key) @stash[key].first end
present?(key)
click to toggle source
# File lib/dynflow/director/queue_hash.rb, line 24 def present?(key) @stash.key?(key) end
push(key, value)
click to toggle source
# File lib/dynflow/director/queue_hash.rb, line 13 def push(key, value) Type! key, @key_type Type! value, @value_type @stash[key].push value end
shift(key)
click to toggle source
# File lib/dynflow/director/queue_hash.rb, line 19 def shift(key) return nil unless present? key @stash[key].shift.tap { @stash.delete(key) if @stash[key].empty? } end
size(key)
click to toggle source
# File lib/dynflow/director/queue_hash.rb, line 38 def size(key) return 0 if empty?(key) @stash[key].size end