Class: AssLauncher::Support::Shell::AssOutFile Private

Inherits:
Object
  • Object
show all
Includes:
Platforms
Defined in:
lib/ass_launcher/support/shell.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

Fucking 1C not work with stdout and stderr For out 1C use /OUT“file” parameter and write message into. Message encoding ‘cp1251’ for windows and ‘utf-8’ for Linux

Hold, read and encode 1C output

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Platforms

cygwin?, env, glob, linux?, path, path_class, windows?

Constructor Details

#initialize(encoding = nil) ⇒ AssOutFile

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of AssOutFile.



390
391
392
393
394
395
# File 'lib/ass_launcher/support/shell.rb', line 390

def initialize(encoding = nil)
  @file = Tempfile.new('ass_out')
  @file.close
  @path = platform.path(@file.path)
  @encoding = encoding || detect_ass_encoding
end

Instance Attribute Details

#encodingObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



389
390
391
# File 'lib/ass_launcher/support/shell.rb', line 389

def encoding
  @encoding
end

#fileObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



389
390
391
# File 'lib/ass_launcher/support/shell.rb', line 389

def file
  @file
end

#pathObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



389
390
391
# File 'lib/ass_launcher/support/shell.rb', line 389

def path
  @path
end

Instance Method Details

#detect_ass_encodingObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

TODO:

It’s stub returns the CP1251 encoding but requires to detect 1C out encoding automatically



399
400
401
# File 'lib/ass_launcher/support/shell.rb', line 399

def detect_ass_encoding
  Encoding::CP1251
end

#readObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



407
408
409
410
411
412
413
414
415
416
417
# File 'lib/ass_launcher/support/shell.rb', line 407

def read
  begin
    @file.open
    s = @file.read
    s.encode! Encoding::UTF_8, encoding unless linux?
  ensure
    @file.close
    try_unlink
  end
  s.to_s
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



403
404
405
# File 'lib/ass_launcher/support/shell.rb', line 403

def to_s
  @path.to_s
end

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

File can be busy



420
421
422
423
424
# File 'lib/ass_launcher/support/shell.rb', line 420

def try_unlink
  @file.unlink if @file
rescue Errno::EBUSY
  # NOP
end