Sha256: 9c5e14bd1d0afc9904d663eb175e17e84b76dc26accc7e364543e5cb1b2ac02b

Contents?: true

Size: 1018 Bytes

Versions: 6

Compression:

Stored size: 1018 Bytes

Contents

module QueueBus
  class SubscriptionList

    class << self
      def from_redis(redis_hash)
        out = SubscriptionList.new
        
        redis_hash.each do |key, value|
          sub = Subscription.from_redis(value)
          out.add(sub) if sub
        end

        out
      end
    end

    def to_redis
      out = {}
      @subscriptions.values.each do |sub|
        out[sub.key] = sub.to_redis
      end
      out
    end
    
    def initialize
      @subscriptions = {}
    end
    
    def add(sub)
      raise "Duplicate key: #{sub.key} already exists " \
            "in the #{sub.queue_name} queue!" if @subscriptions.key?(sub.key)
      @subscriptions[sub.key] = sub
    end
    
    def size
      @subscriptions.size
    end
    
    def key(key)
      @subscriptions[key.to_s]
    end
    
    def all
      @subscriptions.values
    end
    
    def matches(attributes)
      out = []
      all.each do |sub|
        out << sub if sub.matches?(attributes)
      end
      out
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
queue-bus-0.9.0 lib/queue_bus/subscription_list.rb
queue-bus-0.8.1 lib/queue_bus/subscription_list.rb
queue-bus-0.8.0 lib/queue_bus/subscription_list.rb
queue-bus-0.7.0 lib/queue_bus/subscription_list.rb
queue-bus-0.6.0 lib/queue_bus/subscription_list.rb
queue-bus-0.5.9 lib/queue_bus/subscription_list.rb