Class: PuppetfileEditor::Logging

Inherits:
Object
  • Object
show all
Defined in:
lib/puppetfile_editor/cli.rb

Instance Method Summary collapse

Constructor Details

#initializeLogging

Returns a new instance of Logging.



99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/puppetfile_editor/cli.rb', line 99

def initialize
  @statuses = {
    updated:         "[ \e[32;1m+\e[0m ]",
    matched:         "[ \e[0;1m=\e[0m ]",
    skipped:         "[ \e[33;1m~\e[0m ]",
    not_found:       "[ \e[31;1mx\e[0m ]",
    type_mismatched: "[ \e[31;1mx\e[0m ]",
    wont_upgrade:    "[ \e[33;1m!\e[0m ]",
    warn:            "[ \e[31;1m!!\e[0m ]",
    undef:           '',
  }
end

Instance Method Details

#log(message, message_type = :undef) ⇒ Object



112
113
114
115
116
117
118
119
# File 'lib/puppetfile_editor/cli.rb', line 112

def log(message, message_type = :undef)
  status = if @statuses.key? message_type
             @statuses[message_type]
           else
             @statuses[:undef]
           end
  puts "#{status} #{message}"
end

#log_and_exit(message) ⇒ Object



121
122
123
124
# File 'lib/puppetfile_editor/cli.rb', line 121

def log_and_exit(message)
  log(message, :warn)
  exit 1
end

#mod_message(mod, indent) ⇒ Object



126
127
128
# File 'lib/puppetfile_editor/cli.rb', line 126

def mod_message(mod, indent)
  log("#{mod.name.ljust(indent)} => #{mod.message}", mod.status)
end