summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAustin Ziegler <austin@zieglers.ca>2014-10-08 16:23:15 -0400
committerAustin Ziegler <austin@zieglers.ca>2014-10-08 16:23:15 -0400
commitaa0902a0b01eab2f926473d173fc4e33544b8177 (patch)
tree9e4cbe26682dd5b55ad901a2f40273d19a1651ff
parent9fe1aca5ee33a635a6aca35707f69119451f0e41 (diff)
downloadgit-aa0902a0b01eab2f926473d173fc4e33544b8177.tar.gz
Making a lot of comments private.
- Also improving documentation. - Improved a test to use a better assertion.
-rw-r--r--lib/mime/type.rb14
-rw-r--r--lib/mime/types/loader.rb24
-rw-r--r--test/test_mime_type.rb6
3 files changed, 24 insertions, 20 deletions
diff --git a/lib/mime/type.rb b/lib/mime/type.rb
index 01d5d6e263..e1bd972e14 100644
--- a/lib/mime/type.rb
+++ b/lib/mime/type.rb
@@ -50,8 +50,7 @@ class MIME::Type
end
def to_s
- "Invalid Encoding #{@encoding.inspect} (valid values are " +
- "#{MIME::Type::VALID_ENCODINGS.inspect})."
+ "Invalid Encoding #{@encoding.inspect} (valid values: #{VALID_ENCODINGS.inspect})."
end
# :startdoc:
end
@@ -61,7 +60,6 @@ class MIME::Type
include Comparable
- # :stopdoc:
MEDIA_TYPE_RE = %r{([-\w.+]+)/([-\w.+]*)}o
UNREGISTERED_RE = %r{[Xx]-}o
I18N_RE = %r{[^[:alnum:]]}o
@@ -76,7 +74,9 @@ class MIME::Type
RFC_URL = "http://rfc-editor.org/rfc/rfc%s.txt"
DRAFT_URL = "http://datatracker.ietf.org/public/idindex.cgi?command=id_details&filename=%s"
CONTACT_URL = "http://www.iana.org/assignments/contact-people.htm#%s"
- # :startdoc:
+ private_constant :MEDIA_TYPE_RE, :UNREGISTERED_RE, :I18N_RE, :PLATFORM_RE,
+ :DEFAULT_ENCODINGS, :BINARY_ENCODINGS, :TEXT_ENCODINGS, :VALID_ENCODINGS,
+ :IANA_URL, :RFC_URL, :DRAFT_URL, :CONTACT_URL
# Builds a MIME::Type object from the provided MIME Content Type value
# (e.g., 'text/plain' or 'applicaton/x-eruby'). The constructed object is
@@ -552,7 +552,9 @@ class MIME::Type
encode_with({})
end
- # :stopdoc:
+ # Populates the +coder+ with attributes about this record for
+ # serialization. The structure of +coder+ should match the structure used
+ # with #init_with.
def encode_with(coder)
coder['content-type'] = @content_type
coder['docs'] = @docs unless @docs.nil? or @docs.empty?
@@ -571,6 +573,8 @@ class MIME::Type
coder
end
+ # Initialize an empty object from +coder+, which must contain the
+ # attributes necessary for initializing an empty object.
def init_with(coder)
self.content_type = coder['content-type']
self.docs = coder['docs'] || []
diff --git a/lib/mime/types/loader.rb b/lib/mime/types/loader.rb
index 664e29ba3c..32b43ac6e0 100644
--- a/lib/mime/types/loader.rb
+++ b/lib/mime/types/loader.rb
@@ -79,6 +79,7 @@ class MIME::Types::Loader
container
end
+ # Raised when a V1 format file is discovered.
BadV1Format = Class.new(Exception)
class << self
@@ -131,7 +132,7 @@ class MIME::Types::Loader
item = line.chomp.strip
next if item.empty?
- m = MIME::Types::Loader::V1_FORMAT.match(item)
+ m = V1_FORMAT.match(item)
unless m
warn <<-EOS
@@ -222,18 +223,19 @@ class MIME::Types::Loader
# The regular expression used to match a v1-format file-based MIME type
# definition.
- MIME::Types::Loader::V1_FORMAT = # :nodoc:
+ V1_FORMAT = # :nodoc:
%r{\A\s*
- ([*])? # 0: Unregistered?
- (!)? # 1: Obsolete?
- (?:(\w+):)? # 2: Platform marker
- #{MIME::Type::MEDIA_TYPE_RE}? # 3,4: Media type
- (?:\s+@(\S+))? # 5: Extensions
- (?:\s+:(base64|7bit|8bit|quoted\-printable))? # 6: Encoding
- (?:\s+'(\S+))? # 7: URL list
- (?:\s+=(.+))? # 8: Documentation
- (?:\s*([#].*)?)?
+ ([*])? # 0: Unregistered?
+ (!)? # 1: Obsolete?
+ (?:(\w+):)? # 2: Platform marker
+ ([-\w.+]+)/([-\w.+]*) # 3, 4: Media Type
+ (?:\s+@(\S+))? # 5: Extensions
+ (?:\s+:(base64|7bit|8bit|quoted\-printable))? # 6: Encoding
+ (?:\s+'(\S+))? # 7: URL list
+ (?:\s+=(.+))? # 8: Documentation
+ (?:\s*([#].*)?)? # Comments
\s*
\z
}x
+ private_constant :V1_FORMAT
end
diff --git a/test/test_mime_type.rb b/test/test_mime_type.rb
index a584eae7f5..5608d73cb9 100644
--- a/test/test_mime_type.rb
+++ b/test/test_mime_type.rb
@@ -167,11 +167,9 @@ class TestMIMEType < Minitest::Test
assert_equal('base64', yaml.encoding)
yaml.encoding = :default
assert_equal('quoted-printable', yaml.encoding)
- begin
+ assert_raises(MIME::Type::InvalidEncoding) {
yaml.encoding = 'binary'
- rescue MIME::Type::InvalidEncoding => ex
- assert_equal('Invalid Encoding "binary" (valid values are [nil, :default, "base64", "8bit", "7bit", "quoted-printable"]).', ex.message)
- end
+ }
end
def test_default_encoding