Class: Chef::Util::Powershell::Cmdlet::CmdletStream

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/util/powershell/cmdlet.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ CmdletStream

Returns a new instance of CmdletStream


149
150
151
152
# File 'lib/chef/util/powershell/cmdlet.rb', line 149

def initialize(name)
  @filename = Dir::Tmpname.create(name) {}
  ObjectSpace.define_finalizer(self, self.class.destroy(@filename))
end

Class Method Details

.destroy(name) ⇒ Object


166
167
168
# File 'lib/chef/util/powershell/cmdlet.rb', line 166

def self.destroy(name)
  proc { File.delete(name) if File.exists? name }
end

Instance Method Details

#pathObject


154
155
156
# File 'lib/chef/util/powershell/cmdlet.rb', line 154

def path
  @filename
end

#readObject


158
159
160
161
162
163
164
# File 'lib/chef/util/powershell/cmdlet.rb', line 158

def read
  if File.exist? @filename
    File.open(@filename, "rb:bom|UTF-16LE") do |f|
      f.read.encode("UTF-8")
    end
  end
end