Class: Vagrant::UI::MachineReadable
- Includes:
- Vagrant::Util::SafePuts
- Defined in:
- lib/vagrant/ui.rb
Instance Attribute Summary
Attributes inherited from Interface
#opts, #stderr, #stdin, #stdout
Instance Method Summary collapse
- #ask(*args, **opts) ⇒ Object
-
#initialize ⇒ MachineReadable
constructor
A new instance of MachineReadable.
- #machine(type, *data) ⇒ Object
Methods included from Vagrant::Util::SafePuts
Methods inherited from Interface
#color?, #initialize_copy, #rewriting
Constructor Details
#initialize ⇒ MachineReadable
Returns a new instance of MachineReadable.
100 101 102 103 104 |
# File 'lib/vagrant/ui.rb', line 100 def initialize super @lock = Mutex.new end |
Instance Method Details
#ask(*args, **opts) ⇒ Object
106 107 108 109 110 111 |
# File 'lib/vagrant/ui.rb', line 106 def ask(*args, **opts) super # Machine-readable can't ask for input raise Errors::UIExpectsTTY end |
#machine(type, *data) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/vagrant/ui.rb', line 119 def machine(type, *data) opts = {} opts = data.pop if data.last.kind_of?(Hash) target = opts[:target] || "" # Prepare the data by replacing characters that aren't outputted data.each_index do |i| data[i] = data[i].to_s.dup data[i].gsub!(",", "%!(VAGRANT_COMMA)") data[i].gsub!("\n", "\\n") data[i].gsub!("\r", "\\r") end # Avoid locks in a trap context introduced from Ruby 2.0 Thread.new do @lock.synchronize do safe_puts("#{Time.now.utc.to_i},#{target},#{type},#{data.join(",")}") end end.join(THREAD_MAX_JOIN_TIMEOUT) end |