Skip to content

Commit

Permalink
Unsort extensions, restore old sort order.
Browse files Browse the repository at this point in the history
Resolves #71.
  • Loading branch information
halostatue committed Oct 6, 2014
1 parent 2f90c71 commit d97a692
Show file tree
Hide file tree
Showing 10 changed files with 154 additions and 122 deletions.
6 changes: 6 additions & 0 deletions History-Types.rdoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
= MIME Types Changes by Version

== 2.4 / 2014-10-DD

* Changed the sort order of many of the extensions to restore behaviour
from mime-types 1.25.1.
* Updated the IANA media registry entries as of release date.

== 2.3 / 2014-05-23

* Updated the IANA media registry entries as of release date.
Expand Down
13 changes: 13 additions & 0 deletions History.rdoc
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
== 2.4 / 2014-10-DD

* Bugs:
* Restored the extension sort order from mime-types 1.25.1 and modified
MIME::Type#extensions= to no longer sort extensions when set. This resolves
{#71}[https://github.com/halostatue/mime-types/issues/71] and should fix
Paperclip.
* API Changes:
* Added MIME::Type#preferred_extension to return the preferred extension for
the MIME type. This should be used in preference to the current mechanism
used by many clients, <tt>type.extensions.first</tt>. This will allow the
implementation to change over time.

== 2.3 / 2014-05-23

* Bugs:
Expand Down
2 changes: 1 addition & 1 deletion data/mime-types.json

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions lib/mime/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,13 @@ def eql?(other)
# text/plain => text/plain
# x-chemical/x-pdb => chemical/pdb
attr_reader :simplified

# The list of extensions which are known to be used for this MIME::Type.
# Non-array values will be coerced into an array with #to_a. Array values
# will be flattened, +nil+ values removed, sorted, and made unique.
# will be flattened, +nil+ values removed, and made unique.
attr_reader :extensions
def extensions=(ext) # :nodoc:
@extensions = Array(ext).flatten.compact.sort.uniq
@extensions = Array(ext).flatten.compact.uniq
end

# Merge the extensions provided into this MIME::Type. The extensions added
Expand All @@ -233,6 +234,16 @@ def add_extensions(*ext)
self.extensions = self.extensions + ext
end

##
# The preferred extension for this MIME type, if one is set.
#
# :attr_reader: preferred_extension

##
def preferred_extension
extensions.first
end

# The encoding (7bit, 8bit, quoted-printable, or base64) required to
# transport the data of this content type safely across a network, which
# roughly corresponds to Content-Transfer-Encoding. A value of +nil+ or
Expand Down
Loading

0 comments on commit d97a692

Please # to comment.