Class: ChefCore::CLIUX::UI::PlainTextElement
- Inherits:
-
Object
- Object
- ChefCore::CLIUX::UI::PlainTextElement
- Defined in:
- lib/chef_core/cliux/ui/plain_text_element.rb
Instance Method Summary collapse
- #auto_spin ⇒ Object
- #error ⇒ Object
-
#initialize(format, opts) ⇒ PlainTextElement
constructor
A new instance of PlainTextElement.
- #run(&block) ⇒ Object
- #success ⇒ Object
- #update(params) ⇒ Object
Constructor Details
#initialize(format, opts) ⇒ PlainTextElement
Returns a new instance of PlainTextElement.
22 23 24 25 26 |
# File 'lib/chef_core/cliux/ui/plain_text_element.rb', line 22 def initialize(format, opts) @orig_format = format @format = format @output = opts[:output] end |
Instance Method Details
#auto_spin ⇒ Object
75 |
# File 'lib/chef_core/cliux/ui/plain_text_element.rb', line 75 def auto_spin; end |
#error ⇒ Object
65 66 67 68 |
# File 'lib/chef_core/cliux/ui/plain_text_element.rb', line 65 def error @err = true @succ = false end |
#run(&block) ⇒ Object
28 29 30 |
# File 'lib/chef_core/cliux/ui/plain_text_element.rb', line 28 def run(&block) yield end |
#success ⇒ Object
70 71 72 73 |
# File 'lib/chef_core/cliux/ui/plain_text_element.rb', line 70 def success @succ = true @err = false end |
#update(params) ⇒ Object
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 63 |
# File 'lib/chef_core/cliux/ui/plain_text_element.rb', line 32 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 ChefCore::Log.send(log_method, msg) @output.puts(msg) end |