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?, inherited, #initialize_copy, #rewriting, #to_proto
Constructor Details
#initialize ⇒ MachineReadable
Returns a new instance of MachineReadable.
109 110 111 112 113 |
# File 'lib/vagrant/ui.rb', line 109 def initialize super @lock = Mutex.new end |
Instance Method Details
#ask(*args, **opts) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/vagrant/ui.rb', line 115 def ask(*args, **opts) super # Machine-readable can't ask for input raise Errors::UIExpectsTTY end |
#machine(type, *data) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/vagrant/ui.rb', line 128 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 |