Module: FileType
- Defined in:
- lib/file_type.rb
Defined Under Namespace
Modules: Extractable, ExtractableDir
Classes: Bz2, CorruptedTarballError, Directory, ExtractError, Gem, Generic, Gz, Ruby, Tar, TarBz2, TarGz, Unknown, Yaml, Zip
Constant Summary
collapse
- GZIP =
'gzip'.to_cmd
- BZIP2 =
'bzip2'.to_cmd
- UNZIP =
'unzip'.to_cmd
- TAR =
'tar'.to_cmd
- GEM =
'gem'.to_cmd
- @@subclasses =
[]
Class Method Summary
collapse
Class Method Details
.guess(path) ⇒ Object
323
324
325
|
# File 'lib/file_type.rb', line 323
def self.guess ( path )
guess_class(path).new(path)
end
|
.guess_class(path) ⇒ Object
312
313
314
315
316
317
318
319
320
321
|
# File 'lib/file_type.rb', line 312
def self.guess_class ( path )
lazy_init
max = -1
best = Unknown
path = path.to_path
@@subclasses.each do |klass|
max, best = klass.match_type(path, max, best)
end
return best
end
|
.lazy_init ⇒ Object
327
328
329
330
331
332
333
334
335
336
337
|
# File 'lib/file_type.rb', line 327
def self.lazy_init
return if defined? @@init
@@init = true
@@subclasses.delete_if do |klass|
klass.abstract? or not (klass.is_a? Class)
end
@@subclasses.each do |klass|
ext = klass.extension
raise ArgumentError, "Bad extension #{ext}" unless ext.is_a? Regexp
end
end
|
.register(klass) ⇒ Object
12
13
14
|
# File 'lib/file_type.rb', line 12
def self.register ( klass )
@@subclasses << klass
end
|