Sha256: 52e49d80e184c84d47d20788a85d80172b1009771023493bb9eca2cadcdf1653
Contents?: true
Size: 1.09 KB
Versions: 36
Compression:
Stored size: 1.09 KB
Contents
require "open3" class Terraspace::Compiler::Strategy::Mod class TextFile include Terraspace::Util::Logging def initialize(filename) @filename = filename end def check return true if Gem.win_platform? # assume text file if on windows return true unless file_installed? # Thanks: https://stackoverflow.com/questions/2355866/ruby-how-to-determine-if-file-being-read-is-binary-or-text file_type, status = Open3.capture2e("file", @filename) status.success? && file_type.include?("text") end private @@has_file = nil def file_installed? return @@has_file unless @@has_file.nil? @@has_file = system("type file > /dev/null 2>&1") unless @@has_file logger.warn <<~EOL.color(:yellow) WARN: The command 'file' is not installed. Unable to check if files are text or binary files as a part of the Terraspace compile processing. Assuming all files are not binary file. Please install the file command to remove this warning message. EOL end @@has_file end end end
Version data entries
36 entries across 36 versions & 1 rubygems