summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Ziegler <austin@zieglers.ca>2018-08-12 14:25:18 -0400
committerAustin Ziegler <austin@zieglers.ca>2018-08-12 14:25:18 -0400
commit76d03a5317e595c6a4491236dd0b1ea797ec8d0c (patch)
treefcac1434d0c9451eb57ce7c99213fb9c50cf6fa2
parent5a653a3d7820087577b1b266d00bb05ae8ed7f08 (diff)
downloadmime-types-76d03a5317e595c6a4491236dd0b1ea797ec8d0c.tar.gz
v3.2.1: An encoding bugfix releasev3.2.1
-rw-r--r--Gemfile3
-rw-r--r--History.md6
-rw-r--r--lib/mime/type.rb12
-rw-r--r--lib/mime/types/container.rb47
-rw-r--r--mime-types.gemspec6
-rw-r--r--test/test_mime_type.rb4
-rw-r--r--test/test_mime_types_class.rb10
7 files changed, 65 insertions, 23 deletions
diff --git a/Gemfile b/Gemfile
index ac48174..d6692be 100644
--- a/Gemfile
+++ b/Gemfile
@@ -4,6 +4,9 @@
# be accepted.
source 'https://rubygems.org/'
+
+gem 'mime-types-data', path: '../mime-types-data' if ENV['DEV']
+
gemspec
# vim: syntax=ruby
diff --git a/History.md b/History.md
index e597e05..58db6fd 100644
--- a/History.md
+++ b/History.md
@@ -1,3 +1,9 @@
+## 3.2.1 / 2018-08-12
+
+* A few bugs related to MIME::Types::Container and its use in the
+ mime-types-data helper tools reared their head because I released 3.2
+ before verifying against mime-types-data.
+
## 3.2 / 2018-08-12
* 2 minor enhancements
diff --git a/lib/mime/type.rb b/lib/mime/type.rb
index 49a4217..49cf129 100644
--- a/lib/mime/type.rb
+++ b/lib/mime/type.rb
@@ -57,7 +57,7 @@ class MIME::Type
end
# The released version of the mime-types library.
- VERSION = '3.2'
+ VERSION = '3.2.1'
include Comparable
@@ -368,13 +368,7 @@ class MIME::Type
##
def xrefs=(x) # :nodoc:
- MIME::Types::Container.new.merge(x).tap do |xr|
- xr.each do |k, v|
- xr[k] = Set[*v] unless v.kind_of? Set
- end
-
- @xrefs = xr
- end
+ @xrefs = MIME::Types::Container.new(x)
end
# The decoded cross-reference URL list for this MIME::Type.
@@ -459,7 +453,7 @@ class MIME::Type
unless xrefs.empty?
{}.tap do |hash|
xrefs.each do |k, v|
- hash[k] = v.sort.to_a
+ hash[k] = v.to_a.sort
end
coder['xrefs'] = hash
end
diff --git a/lib/mime/types/container.rb b/lib/mime/types/container.rb
index 22f2242..43a81fe 100644
--- a/lib/mime/types/container.rb
+++ b/lib/mime/types/container.rb
@@ -12,20 +12,48 @@ require 'forwardable'
class MIME::Types::Container #:nodoc:
extend Forwardable
- def initialize
+ def initialize(hash = {})
@container = {}
+ merge!(hash)
end
def [](key)
container[key] || EMPTY_SET
end
+ def []=(key, value)
+ case value
+ when Set
+ container[key] = value
+ else
+ container[key] = Set[*value]
+ end
+ end
+
+ def merge(other)
+ self.class.new(other)
+ end
+
+ def merge!(other)
+ tap {
+ other = other.kind_of?(MIME::Types::Container) ? other.container : other
+ self.container.merge!(other)
+ normalize
+ }
+ end
+
+ def to_hash
+ container
+ end
+
def_delegators :@container,
+ :==,
:count,
+ :each,
:each_value,
+ :empty?,
+ :flat_map,
:keys,
- :merge,
- :merge!,
:select,
:values
@@ -42,16 +70,25 @@ class MIME::Types::Container #:nodoc:
end
def encode_with(coder)
+ debugger
container.each { |k, v| coder[k] = v.to_a }
end
def init_with(coder)
+ @container = {}
coder.map.each { |k, v| container[k] = Set[*v] }
end
- private
+ protected
- attr_reader :container
+ attr_accessor :container
+
+ def normalize
+ container.each do |k, v|
+ next if v.kind_of?(Set)
+ container[k] = Set[*v]
+ end
+ end
EMPTY_SET = Set.new.freeze
private_constant :EMPTY_SET
diff --git a/mime-types.gemspec b/mime-types.gemspec
index bdd909d..aca1631 100644
--- a/mime-types.gemspec
+++ b/mime-types.gemspec
@@ -1,9 +1,9 @@
# -*- encoding: utf-8 -*-
-# stub: mime-types 3.2 ruby lib
+# stub: mime-types 3.2.1 ruby lib
Gem::Specification.new do |s|
s.name = "mime-types".freeze
- s.version = "3.2"
+ s.version = "3.2.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.licenses = ["MIT".freeze]
s.rdoc_options = ["--main".freeze, "README.rdoc".freeze]
s.required_ruby_version = Gem::Requirement.new(">= 2.0".freeze)
- s.rubygems_version = "2.7.6".freeze
+ s.rubygems_version = "2.7.7".freeze
s.summary = "The mime-types library provides a library and registry for information about MIME content type definitions".freeze
if s.respond_to? :specification_version then
diff --git a/test/test_mime_type.rb b/test/test_mime_type.rb
index 65a23b0..70690c7 100644
--- a/test/test_mime_type.rb
+++ b/test/test_mime_type.rb
@@ -490,9 +490,7 @@ describe MIME::Type do
describe '#xrefs, #xrefs=' do
let(:expected) {
- {
- 'rfc' => Set[*%w(rfc1234 rfc5678)]
- }
+ MIME::Types::Container.new({ 'rfc' => Set[*%w(rfc1234 rfc5678)] })
}
it 'returns the expected results' do
diff --git a/test/test_mime_types_class.rb b/test/test_mime_types_class.rb
index 63c310d..578341e 100644
--- a/test/test_mime_types_class.rb
+++ b/test/test_mime_types_class.rb
@@ -44,9 +44,13 @@ describe MIME::Types, 'registry' do
end
it 'sorts by priority with multiple matches' do
- assert_equal %w(application/gzip application/x-gzip multipart/x-gzip),
- MIME::Types[/gzip$/]
- assert_equal 3, MIME::Types[/gzip$/].size
+ types = MIME::Types[/gzip$/].select { |t|
+ t == 'application/gzip' || t == 'application/x-gzip' || t == 'multipart/x-gzip'
+ }
+ # This is this way because of a new type ending with gzip that only
+ # appears in some data files.
+ assert_equal %w(application/gzip application/x-gzip multipart/x-gzip), types
+ assert_equal 3, types.size
end
it 'can be searched with a string' do