Method: ChefApply::UI::PlainTextElement#update

Defined in:
lib/chef_apply/ui/plain_text_element.rb

#update(params) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/chef_apply/ui/plain_text_element.rb', line 31

def update(params)
  # Some of this is particular to our usage -
  # prefix does not cause a text update, but does
  # change the prefix for future messages.
  if params.key?(:prefix)
    @format = @orig_format.gsub(":prefix", params[:prefix])
    return
  end

  if @succ
    ind = "OK"
    @succ = false
    log_method = :info
  elsif @err
    ind = "ERR"
    @err = false
    log_method = :error
  else
    log_method = :debug
    ind = " - "
  end

  # Since this is a generic type, we can replace any component
  # name in this regex - but for now :spinner is the only component
  # we're standing in for.
  msg = @format.gsub(/:spinner/, ind)
  params.each_pair do |k, v|
    msg.gsub!(/:#{k}/, v)
  end
  ChefApply::Log.send(log_method, msg)
  @output.puts(msg)
end