Class: Ckeditor::Utils::ContentTypeDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/ckeditor/utils/content_type_detector.rb

Constant Summary collapse

EMPTY_CONTENT_TYPE =
'inode/x-empty'.freeze
DEFAULT_CONTENT_TYPE =
'application/octet-stream'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(file_path) ⇒ ContentTypeDetector

Returns a new instance of ContentTypeDetector.



10
11
12
# File 'lib/ckeditor/utils/content_type_detector.rb', line 10

def initialize(file_path)
  @file_path = file_path
end

Instance Method Details

#detectObject

content type detection strategy:

  1. empty file: returns ‘inode/x-empty’

  2. nonempty file: if the file is not empty then returns the content type using file command

  3. invalid file: file command raises error and returns ‘application/octet-stream’



20
21
22
# File 'lib/ckeditor/utils/content_type_detector.rb', line 20

def detect
  empty_file? ? EMPTY_CONTENT_TYPE : content_type_from_file_command
end