Class: Bubbles::CommandQueue

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/bubbles/command_queue.rb

Instance Method Summary collapse

Constructor Details

#initialize(config:) ⇒ CommandQueue

Returns a new instance of CommandQueue.



7
8
9
# File 'lib/bubbles/command_queue.rb', line 7

def initialize(config:)
  @config = config
end

Instance Method Details

#<<(command_object) ⇒ Object



15
16
17
# File 'lib/bubbles/command_queue.rb', line 15

def <<(command_object)
  queue << command_object
end

#call_nextObject



19
20
21
22
23
24
25
26
# File 'lib/bubbles/command_queue.rb', line 19

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

#inspectObject



32
33
34
# File 'lib/bubbles/command_queue.rb', line 32

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

#queueObject



11
12
13
# File 'lib/bubbles/command_queue.rb', line 11

def queue
  @queue ||= []
end

#reschedule(command_object) ⇒ Object



28
29
30
# File 'lib/bubbles/command_queue.rb', line 28

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