Class: Pathname

Inherits:
Object
  • Object
show all
Defined in:
lib/ver/vendor/pathname.rb

Overview

annoying fixes

Constant Summary collapse

GUESS_ENCODING_ORDER =
[
  Encoding::US_ASCII,
  Encoding::UTF_8,
  Encoding::Shift_JIS,
  Encoding::EUC_JP,
  Encoding::EucJP_ms,
  Encoding::Big5,
  Encoding::UTF_16BE,
  Encoding::UTF_16LE,
  Encoding::UTF_32BE,
  Encoding::UTF_32LE,
  Encoding::CP949,
  Encoding::Emacs_Mule,
  Encoding::EUC_KR,
  Encoding::EUC_TW,
  Encoding::GB18030,
  Encoding::GBK,
  Encoding::Stateless_ISO_2022_JP,
  Encoding::CP51932,
  Encoding::EUC_CN,
  Encoding::GB12345,
  Encoding::Windows_31J,
  Encoding::MacJapanese,
  Encoding::UTF8_MAC,
  Encoding::BINARY,
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.tmpdirObject



62
63
64
# File 'lib/ver/vendor/pathname.rb', line 62

def self.tmpdir
  new(Dir.tmpdir)
end

Instance Method Details

#=~(regexp) ⇒ Object



46
47
48
# File 'lib/ver/vendor/pathname.rb', line 46

def =~(regexp)
  to_s =~ regexp
end

#cp(dest) ⇒ Object



42
43
44
# File 'lib/ver/vendor/pathname.rb', line 42

def cp(dest)
  FileUtils.copy_file(expand_path.to_s, dest.to_s, preserve = true)
end

#glob(&block) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/ver/vendor/pathname.rb', line 50

def glob(&block)
  if block
    Dir.glob(to_s){|match| yield(self.class.new(match)) }
  else
    Dir.glob(to_s)
  end
end

#read_encoded_fileObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ver/vendor/pathname.rb', line 78

def read_encoded_file
  content = read
  content.force_encoding('BINARY')

  require 'ver/vendor/open3'
  encoding, status = Open3.capture2('rchardet', to_s)
  content.force_encoding(encoding.strip)

  return content, content.encoding
rescue ArgumentError, Errno::ENOENT # file or rchardet missing?
  if content
    GUESS_ENCODING_ORDER.find{|enc|
      content.force_encoding(enc)
      content.valid_encoding?
    }

    return content, content.encoding
  else
    return '', Encoding::UTF_8
  end
end

#readonly?Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ver/vendor/pathname.rb', line 66

def readonly?
  if file?
    if writable?
      false
    else
      true
    end
  else
    false
  end
end

#rm_fObject



35
36
37
38
39
40
# File 'lib/ver/vendor/pathname.rb', line 35

def rm_f
  rm
rescue Errno::ENOENT
rescue => ex
  VER.error(ex)
end

#shellescapeObject



58
59
60
# File 'lib/ver/vendor/pathname.rb', line 58

def shellescape
  to_s.shellescape
end