Skip to content

Commit

Permalink
add the remove function
Browse files Browse the repository at this point in the history
It's possible for vague magic to cause the wrong filetype to be
detected.  For instance, application/x-gmc-link is seriously
vague (tons of files have "URL:" in the first 32 bytes!).  This
allows you to remove the conflicting filetypes that you're sure
you'll never see.
  • Loading branch information
bronson authored and minad committed Aug 27, 2010
1 parent 4ce4b99 commit 84720bb
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/mimemagic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ def self.add(type, options)
MAGIC.unshift [type, options[:magic]] if options[:magic]
end

# Removes a mime type from the dictionary. You might want to do this if
# you're seeing impossible conflicts (for instance, application/x-gmc-link).
# * <i>type</i>: The mime type to remove. All associated extensions and magic are removed too.
def self.remove(type)
EXTENSIONS.delete_if {|ext, t| t == type }
MAGIC.delete_if { |t, m| t == type }
TYPES.delete(type)
end

# Returns true if type is a text format
def text?
child_of? 'text/plain'
Expand Down

0 comments on commit 84720bb

Please sign in to comment.