Sha256: c68a408fa56acc84873e87302830af05c997beed1270d2508d70a477d230f755

Contents?: true

Size: 729 Bytes

Versions: 6

Compression:

Stored size: 729 Bytes

Contents

module Bubbles
  class CommandQueue
    extend Forwardable

    def_delegators :queue, :size

    def initialize(config:)
      @config = config
    end

    def queue
      @queue ||= []
    end

    def <<(command_object)
      queue << command_object
    end

    def call_next
      if command = queue.shift
        log command
        command.call
      else
        log "Nothing in the command queue"
      end
    end

    def reschedule(command_object)
      queue.unshift(command_object)
    end

    def inspect
      "<##{self.class.name} queue:#{queue.inspect} >"
    end

    private
      attr_reader :config

      def log(command)
        config.logger.debug("Processing: #{command.inspect}")
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
bubbles-0.0.5 lib/bubbles/command_queue.rb
bubbles-0.0.4.1 lib/bubbles/command_queue.rb
bubbles-0.0.4 lib/bubbles/command_queue.rb
bubbles-0.0.3 lib/bubbles/command_queue.rb
bubbles-0.0.2 lib/bubbles/command_queue.rb
bubbles-0.0.1 lib/bubbles/command_queue.rb