Class: Mudguard::Infrastructure::Cli::NotificationAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/mudguard/infrastructure/cli/notification_adapter.rb

Overview

Forwards Notification to the view for printing

Instance Method Summary collapse

Constructor Details

#initialize(view:, compressed: false) ⇒ NotificationAdapter

Returns a new instance of NotificationAdapter.



8
9
10
11
12
# File 'lib/mudguard/infrastructure/cli/notification_adapter.rb', line 8

def initialize(view:, compressed: false)
  @view = view
  @compressed = compressed
  @printed_texts = Set.new
end

Instance Method Details

#add(location, text) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/mudguard/infrastructure/cli/notification_adapter.rb', line 14

def add(location, text)
  text = if location.nil? || @compressed
           text
         else
           "#{location} #{text}"
         end
  @view.print(text) unless @printed_texts.include?(text)
  @printed_texts << text
end