Class: DTK::Shell::MessageQueue
- Inherits:
-
Object
- Object
- DTK::Shell::MessageQueue
- 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
- #init_or_clear ⇒ Object
-
#initialize ⇒ MessageQueue
constructor
A new instance of MessageQueue.
- #print_messages ⇒ Object
- #process_response(response_obj) ⇒ Object
Constructor Details
#initialize ⇒ MessageQueue
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
.print_messages ⇒ Object
38 39 40 |
# File 'lib/shell/message_queue.rb', line 38 def self.() self.instance.() 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_clear ⇒ Object
42 43 44 |
# File 'lib/shell/message_queue.rb', line 42 def init_or_clear() MESSAGE_TYPES.each { |msg_type| @queue[msg_type] = [] } end |
#print_messages ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/shell/message_queue.rb', line 46 def () @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 |