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

@@subclasses =
[]

Class Method Summary collapse

Class Method Details

.guess(path) ⇒ Object



308
309
310
# File 'lib/file_type.rb', line 308

def self.guess ( path )
  guess_class(path).new(path)
end

.guess_class(path) ⇒ Object



297
298
299
300
301
302
303
304
305
306
# File 'lib/file_type.rb', line 297

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_initObject



312
313
314
315
316
317
318
319
320
321
322
# File 'lib/file_type.rb', line 312

def self.lazy_init
  return if defined? @@init
  @@init = true
  @@subclasses.delete_if do |klass|
    klass.abstract? or not (klass.is_a? Class) # and constants.include? klass)
  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