Class: DTK::Shell::MessageQueue

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/shell/message_queue.rb

Constant Summary collapse

MESSAGE_TYPES =
[:info, :warn, :error]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMessageQueue

Returns a new instance of MessageQueue.



29
30
31
32
# File 'lib/shell/message_queue.rb', line 29

def initialize
  @queue = {}
  init_or_clear()
end

Class Method Details



38
39
40
# File 'lib/shell/message_queue.rb', line 38

def self.print_messages()
  self.instance.print_messages()
end

.process_response(response_obj) ⇒ Object



34
35
36
# File 'lib/shell/message_queue.rb', line 34

def self.process_response(response_obj)
  self.instance.process_response(response_obj)
end

Instance Method Details

#init_or_clearObject



42
43
44
# File 'lib/shell/message_queue.rb', line 42

def init_or_clear()
  MESSAGE_TYPES.each { |msg_type| @queue[msg_type] = [] }
end


46
47
48
49
50
51
52
# File 'lib/shell/message_queue.rb', line 46

def print_messages()
  @queue[:info].each  { |msg| DTK::Client::OsUtil.print(msg, :white) }
  @queue[:warn].each  { |msg| DTK::Client::OsUtil.print(msg, :yellow) }
  @queue[:error].each { |msg| DTK::Client::OsUtil.print(msg, :red) }

  init_or_clear()
end

#process_response(response_obj) ⇒ Object



54
55
56
57
58
59
# File 'lib/shell/message_queue.rb', line 54

def process_response(response_obj)
  MESSAGE_TYPES.each do |msg_type|
    msg = response_obj[msg_type.to_s] || response_obj[msg_type]
    @queue[msg_type] << msg if msg
  end
end