From c7ca8b2e92ad20d7f8faa0c83dcf9b4ac0b35c8d Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Sun, 6 Aug 2023 23:13:42 -0400 Subject: [PATCH 1/3] Prepare for 3.5.0 - 1 bug fix: - Added a definition of `MIME::Type#hash`. Contributed by Alex Vondrak in [#167][], fixing [#166][]. - Dependency and CI updates: - Update the .github/workflows/ci.yml workflow to test Ruby 3.2 and more reliably test certain combinations rather than depending on exclusions. - Change `.standard.yml` configuration to format for Ruby 2.3 as certain files are not properly detected with Ruby 2.0. - Change from `hoe-git` to `hoe-git2` to support Hoe version 4. - Apply `standardrb --fix`. - The above changes have resulted in the soft deprecation of Ruby versions below 2.6. Any errors reported for Ruby versions 2.0, 2.1, 2.2, 2.3, 2.4, and 2.5 will be resolved, but maintaining CI for these versions is unsustainable. [#166]: https://github.com/mime-types/ruby-mime-types/issues/166 [#167]: https://github.com/mime-types/ruby-mime-types/pull/167 --- .github/workflows/ci.yml | 9 ++----- .gitignore | 19 +++++++-------- Gemfile | 2 -- History.md | 52 +++++++++++++++++++++------------------- Rakefile | 52 ++++++---------------------------------- lib/mime/type.rb | 2 +- mime-types.gemspec | 14 +++++------ 7 files changed, 52 insertions(+), 98 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 35174e3..71746d5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,10 +1,3 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake -# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby - name: CI on: @@ -63,3 +56,5 @@ jobs: bundler: 2 bundler-cache: true - run: bundle exec ruby -S rake test --trace + - if: matrix.os == 'ubuntu-22.04' && matrix.ruby == '3.2' + run: bundle exec standardrb diff --git a/.gitignore b/.gitignore index 2333f03..0083532 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,13 @@ -*.swp -*~ +*.gem +.byebug_history .rake_tasks~ .source_index -.vagrant Gemfile.lock -Vagrantfile -coverage -doc -html -pkg -publish +coverage.info +coverage/ +doc/ +html/ +pkg/ +publish/ test/cache.tst tmp/ -.byebug_history -tags diff --git a/Gemfile b/Gemfile index 3f7bcc2..5983aa7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,3 @@ -# frozen_string_literal: true - # NOTE: This file is not the canonical source of dependencies. Edit the # Rakefile, instead. diff --git a/History.md b/History.md index 832d987..b45679b 100644 --- a/History.md +++ b/History.md @@ -1,8 +1,8 @@ # Changelog -## NEXT / 2022-MM-DD +## 3.4.2 / 2023-08-07 -- 1 bugfix: +- 1 bug fix: - Added a definition of `MIME::Type#hash`. Contributed by Alex Vondrak in [#167][], fixing [#166][]. @@ -26,7 +26,7 @@ ## 3.4.1 / 2021-11-16 -- 1 bugfix: +- 1 bug fix: - Fixed a Ruby < 2.3 incompatibility introduced by the use of standardrb, where `<<-` heredocs were converted to `<<~` heredocs. These have been @@ -50,7 +50,7 @@ - Added Ruby 3.0 to the CI test matrix. Added `windows/jruby` to the CI exclusion list; it refuses to run successfully. - Removed the Travis CI configuration and changed it to Github Workflows - [#150]. Removed Coveralls configuration. + [#150][]. Removed Coveralls configuration. - Igor Victor added TruffleRuby to the Travis CI configuration. [#149] - Koichi ITO loosened an excessively tight dependency. [#147] - Started using `standardrb` for Ruby formatting and validation. @@ -58,7 +58,7 @@ ## 3.3.1 / 2019-12-26 -- 1 minor bugfix: +- 1 minor bug fix: - Al Snow fixed a warning with MIME::Types::Logger producing a warning because Ruby 2.7 introduces numbered block parameters. Because of the way @@ -68,7 +68,7 @@ - Administrivia: - - Olle Jonsson removed an outdated Travis configuration option (`sudo: false`). [#142] + - Olle Jonsson removed an outdated Travis configuration option. [#142][] ## 3.3 / 2019-09-04 @@ -103,8 +103,9 @@ to be in the same family even if strict sorting would cause an unregistered type to be sorted first. [#132] - - Dillon Welch contributed a change that added `frozen_string_literal: true` to files so that modern Rubies can automatically reduce duplicate - string allocations. [#135] + - Dillon Welch contributed a change that added `frozen_string_literal: true` + to files so that modern Rubies can automatically reduce duplicate string + allocations. [#135] - 2 bug fixes @@ -115,7 +116,7 @@ because when Enumerable#inject isn't provided a starting value, the first value is used as the default value. In every case where this error was happening, the result was supposed to be an array containing Set objects - so they can be reduced to a single Set. [#117], [#127], [#134] + so they can be reduced to a single Set. [#117][], [#127][], [#134][] - Fixed an uncontrolled growth bug in MIME::Types::Container where a key miss would create a new entry with an empty Set in the container. This @@ -137,12 +138,12 @@ - The history file has been modified to remove all history prior to 3.0. This history can be found in previous commits. - - A spelling error was corrected by Edward Betts ([#129]). + - A spelling error was corrected by Edward Betts ([#129][]). - Administrivia: - CI configuration for more modern versions of Ruby were added by Nicolas - Leger ([#130]), Jun Aruga ([#125]), and Austin Ziegler. Removed + Leger ([#130][]), Jun Aruga ([#125][]), and Austin Ziegler. Removed ruby-head-clang and rbx (Rubinius) from CI. - Fixed tests which were asserting equality against nil, which will become @@ -153,18 +154,18 @@ - 1 documentation change: - Tim Smith (@tas50) updated the build badges to be SVGs to improve - readability on high-density (retina) screens with pull request [#112]. + readability on high-density (retina) screens with pull request [#112][]. - 3 bug fixes - A test for `MIME::Types::Cache` fails under Ruby 2.3 because of frozen - strings, [#118]. This has been fixed. + strings, [#118][]. This has been fixed. - The JSON data has been incorrectly encoded since the release of mime-types 3 on the `xrefs` field, because of the switch to using a Set to store cross-reference information. This has been fixed. - - A tentative fix for [#117] has been applied, removing the only circular + - A tentative fix for [#117][] has been applied, removing the only circular require dependencies that exist (and for which there was code to prevent, but the current fix is simpler). I have no way to verify this fix and depending on how things are loaded by `delayed_job`, this fix may not be @@ -179,22 +180,22 @@ - 2 governance changes - This project and the related mime-types-data project are now exclusively - MIT licensed. Resolves [#95]. + MIT licensed. Resolves [#95][]. - All projects under the mime-types organization now have a standard code - of conduct adapted from the [Contributor Covenant]. This text can be - found in the [Code-of-Conduct.md] file. + of conduct adapted from the [Contributor Covenant][]. This text can be + found in the [Code-of-Conduct.md][] file. - 3 major changes - All methods deprecated in mime-types 2.x have been removed. - mime-types now requires Ruby 2.0 compatibility or later. Resolves - [#97]. + [#97][]. - The registry data has been removed from mime-types and put into mime-types-data, maintained and released separately. It can be found at - [mime-types-data]. + [mime-types-data][]. - 17 minor changes: @@ -207,8 +208,9 @@ `x-` prefixes. - Improved initialization with an Array works so that extensions do not - need to be wrapped in another array. This means that `%w(text/yaml yaml yml)` works in the same way that `['text/yaml', %w(yaml yml)]` did (and - still does). + need to be wrapped in another array. This means that + `%w(text/yaml yaml yml)` works in the same way that + `['text/yaml', %w(yaml yml)]` did (and still does). - Changed `priority_compare` to conform with attributes that no longer exist. @@ -216,8 +218,8 @@ - Changed the internal implementation of extensions to use a frozen Set. - When extensions are set or modified with `add_extensions`, the primary - registry will be informed of a need to reindex extensions. Resolves - [#84]. + registry will be informed of a need to re-index extensions. Resolves + [#84][]. - The preferred extension can be set explicitly. If not set, it will be the first extension. If the preferred extension is not in the extension @@ -240,7 +242,7 @@ - Extracted the class methods to a separate file. - Changed the container implementation to use a Set instead of an Array - to prevent data duplication. Resolves [#79]. + to prevent data duplication. Resolves [#79][]. - `MIME::Types::Cache` changes: @@ -259,7 +261,7 @@ - The registry is default loaded from the columnar store by default. The internal format of the columnar store has changed; many of the boolean - flags are now loaded from a single file. Resolves [#85]. + flags are now loaded from a single file. Resolves [#85][]. [#79]: https://github.com/mime-types/ruby-mime-types/pull/79 [#84]: https://github.com/mime-types/ruby-mime-types/pull/84 diff --git a/Rakefile b/Rakefile index 8ff4654..51254e5 100644 --- a/Rakefile +++ b/Rakefile @@ -1,60 +1,26 @@ -# frozen_string_literal: true - require "rubygems" require "hoe" require "rake/clean" -# This is required until https://github.com/seattlerb/hoe/issues/112 is fixed -class Hoe - def with_config - config = Hoe::DEFAULT_CONFIG - - rc = File.expand_path("~/.hoerc") - homeconfig = load_config(rc) - config = config.merge(homeconfig) - - localconfig = load_config(File.expand_path(File.join(Dir.pwd, ".hoerc"))) - config = config.merge(localconfig) - - yield config, rc - end - - def load_config(name) - File.exist?(name) ? safe_load_yaml(name) : {} - end - - def safe_load_yaml(name) - return safe_load_yaml_file(name) if YAML.respond_to?(:safe_load_file) - - data = IO.binread(name) - YAML.safe_load(data, permitted_classes: [Regexp]) - rescue - YAML.safe_load(data, [Regexp]) - end - - def safe_load_yaml_file(name) - YAML.safe_load_file(name, permitted_classes: [Regexp]) - rescue - YAML.safe_load_file(name, [Regexp]) - end -end - +Hoe.plugin :cov Hoe.plugin :doofus Hoe.plugin :gemspec2 -Hoe.plugin :git +Hoe.plugin :git2 Hoe.plugin :minitest -Hoe.plugin :email unless ENV["CI"] +Hoe.plugin :rubygems spec = Hoe.spec "mime-types" do developer("Austin Ziegler", "halostatue@gmail.com") - require_ruby_version ">= 2.0" - self.history_file = "History.md" self.readme_file = "README.rdoc" license "MIT" + require_ruby_version ">= 2.0" + + spec_extras[:metadata] = ->(val) { val["rubygems_mfa_required"] = "true" } + extra_deps << ["mime-types-data", "~> 3.2015"] extra_dev_deps << ["hoe", ">= 3.0", "< 5"] @@ -69,10 +35,6 @@ spec = Hoe.spec "mime-types" do extra_dev_deps << ["minitest-hooks", "~> 1.4"] extra_dev_deps << ["rake", ">= 10.0", "< 14.0"] extra_dev_deps << ["standard", "~> 1.0"] - - if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.0") - extra_dev_deps << ["simplecov", "~> 0.7"] - end end namespace :benchmark do diff --git a/lib/mime/type.rb b/lib/mime/type.rb index f0ec15e..d7c2a9f 100644 --- a/lib/mime/type.rb +++ b/lib/mime/type.rb @@ -93,7 +93,7 @@ def to_s end # The released version of the mime-types library. - VERSION = "3.4.1" + VERSION = "3.4.2" include Comparable diff --git a/mime-types.gemspec b/mime-types.gemspec index 76ce9c7..d41493c 100644 --- a/mime-types.gemspec +++ b/mime-types.gemspec @@ -1,15 +1,15 @@ # -*- encoding: utf-8 -*- -# stub: mime-types 3.4.1 ruby lib +# stub: mime-types 3.4.2 ruby lib Gem::Specification.new do |s| s.name = "mime-types".freeze - s.version = "3.4.1" + s.version = "3.4.2" s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version= - s.metadata = { "bug_tracker_uri" => "https://github.com/mime-types/ruby-mime-types/issues", "changelog_uri" => "https://github.com/mime-types/ruby-mime-types/blob/master/History.md", "homepage_uri" => "https://github.com/mime-types/ruby-mime-types/", "source_code_uri" => "https://github.com/mime-types/ruby-mime-types/" } if s.respond_to? :metadata= + s.metadata = { "bug_tracker_uri" => "https://github.com/mime-types/ruby-mime-types/issues", "changelog_uri" => "https://github.com/mime-types/ruby-mime-types/blob/master/History.md", "homepage_uri" => "https://github.com/mime-types/ruby-mime-types/", "rubygems_mfa_required" => "true", "source_code_uri" => "https://github.com/mime-types/ruby-mime-types/" } if s.respond_to? :metadata= s.require_paths = ["lib".freeze] s.authors = ["Austin Ziegler".freeze] - s.date = "2023-02-17" + s.date = "2023-08-07" s.description = "The mime-types library provides a library and registry for information about\nMIME content type definitions. It can be used to determine defined filename\nextensions for MIME types, or to use filename extensions to look up the likely\nMIME type definitions.\n\nVersion 3.0 is a major release that requires Ruby 2.0 compatibility and removes\ndeprecated functions. The columnar registry format introduced in 2.6 has been\nmade the primary format; the registry data has been extracted from this library\nand put into {mime-types-data}[https://github.com/mime-types/mime-types-data].\nAdditionally, mime-types is now licensed exclusively under the MIT licence and\nthere is a code of conduct in effect. There are a number of other smaller\nchanges described in the History file.".freeze s.email = ["halostatue@gmail.com".freeze] s.extra_rdoc_files = ["Code-of-Conduct.md".freeze, "Contributing.md".freeze, "History.md".freeze, "Licence.md".freeze, "Manifest.txt".freeze, "README.rdoc".freeze] @@ -18,13 +18,13 @@ 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 = "3.4.7".freeze + s.rubygems_version = "3.4.10".freeze s.summary = "The mime-types library provides a library and registry for information about MIME content type definitions".freeze s.specification_version = 4 s.add_runtime_dependency(%q.freeze, ["~> 3.2015"]) - s.add_development_dependency(%q.freeze, ["~> 5.17"]) + s.add_development_dependency(%q.freeze, ["~> 5.19"]) s.add_development_dependency(%q.freeze, [">= 3.0", "< 5"]) s.add_development_dependency(%q.freeze, ["~> 1.0"]) s.add_development_dependency(%q.freeze, ["~> 1.1"]) @@ -36,6 +36,6 @@ Gem::Specification.new do |s| s.add_development_dependency(%q.freeze, ["~> 1.4"]) s.add_development_dependency(%q.freeze, [">= 10.0", "< 14.0"]) s.add_development_dependency(%q.freeze, ["~> 1.0"]) - s.add_development_dependency(%q.freeze, ["~> 0.7"]) s.add_development_dependency(%q.freeze, [">= 4.0", "< 7"]) + s.add_development_dependency(%q.freeze, ["~> 0.21"]) end From ceec17cc7576e889be8f3c2942ecbe7accee4213 Mon Sep 17 00:00:00 2001 From: Robb Shecter Date: Sun, 22 Jan 2023 21:23:49 -0700 Subject: [PATCH 2/3] Change logging to `debug` level. ...for the 'already registered' warning. Closes #170. --- lib/mime/types.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mime/types.rb b/lib/mime/types.rb index e9db72b..a6053bc 100644 --- a/lib/mime/types.rb +++ b/lib/mime/types.rb @@ -187,7 +187,7 @@ def add(*types) # truthy value to suppress that warning. def add_type(type, quiet = false) if !quiet && @type_variants[type.simplified].include?(type) - MIME::Types.logger.warn <<-WARNING.chomp.strip + MIME::Types.logger.debug <<-WARNING.chomp.strip Type #{type} is already registered as a variant of #{type.simplified}. WARNING end From 24c6da796b7ed0bdd9fdda85cbe1ca4b283d0dfe Mon Sep 17 00:00:00 2001 From: Austin Ziegler Date: Mon, 7 Aug 2023 00:01:00 -0400 Subject: [PATCH 3/3] Update release documentation for logging changes - Also update other message log levels. --- History.md | 14 +++++++++++++- lib/mime/type.rb | 2 +- lib/mime/types/cache.rb | 4 ++-- lib/mime/types/deprecations.rb | 2 +- lib/mime/types/registry.rb | 2 +- 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/History.md b/History.md index b45679b..a41fd62 100644 --- a/History.md +++ b/History.md @@ -1,6 +1,17 @@ # Changelog -## 3.4.2 / 2023-08-07 +## 3.5.0 / 2023-08-07 + +- 1 minor enhancement: + + - Robb Shecter changed the default log level for duplicate type variant from + `warn` to `debug` in [#170][]. This works because `MIME::Types.logger` is + intended to fit the `::Logger` interface, and the default logger + (`WarnLogger`) is a subclass of `::Logger` that passes through to + `Kernel.warn`. + + - Further consideration has changed cache load messages from `warn` to + `error` and deprecation messages from `warn` to `debug`. - 1 bug fix: @@ -292,6 +303,7 @@ [#153]: https://github.com/mime-types/ruby-mime-types/pull/153 [#166]: https://github.com/mime-types/ruby-mime-types/issues/166 [#167]: https://github.com/mime-types/ruby-mime-types/pull/167 +[#170]: https://github.com/mime-types/ruby-mime-types/pull/170 [code-of-conduct.md]: Code-of-Conduct_md.html [contributor covenant]: http://contributor-covenant.org [mime-types-data]: https://github.com/mime-types/mime-types-data diff --git a/lib/mime/type.rb b/lib/mime/type.rb index d7c2a9f..feae131 100644 --- a/lib/mime/type.rb +++ b/lib/mime/type.rb @@ -93,7 +93,7 @@ def to_s end # The released version of the mime-types library. - VERSION = "3.4.2" + VERSION = "3.5.0" include Comparable diff --git a/lib/mime/types/cache.rb b/lib/mime/types/cache.rb index 2e70775..aecbf7b 100644 --- a/lib/mime/types/cache.rb +++ b/lib/mime/types/cache.rb @@ -22,13 +22,13 @@ def load(cache_file = nil) if cache.version == MIME::Types::Data::VERSION Marshal.load(cache.data) else - MIME::Types.logger.warn <<-WARNING.chomp.strip + MIME::Types.logger.error <<-WARNING.chomp.strip Could not load MIME::Types cache: invalid version WARNING nil end rescue => e - MIME::Types.logger.warn <<-WARNING.chomp.strip + MIME::Types.logger.error <<-WARNING.chomp.strip Could not load MIME::Types cache: #{e} WARNING nil diff --git a/lib/mime/types/deprecations.rb b/lib/mime/types/deprecations.rb index cf9c297..dc869fa 100644 --- a/lib/mime/types/deprecations.rb +++ b/lib/mime/types/deprecations.rb @@ -25,7 +25,7 @@ def self.deprecated(klass, sym, message = nil, &block) # :nodoc: else message end - MIME::Types.logger.warn <<-WARNING.chomp.strip + MIME::Types.logger.debug <<-WARNING.chomp.strip #{caller(2..2).first}: #{klass}#{level}#{sym} is deprecated #{message}. WARNING diff --git a/lib/mime/types/registry.rb b/lib/mime/types/registry.rb index e557a5c..eb27094 100644 --- a/lib/mime/types/registry.rb +++ b/lib/mime/types/registry.rb @@ -45,7 +45,7 @@ def add(*types) def lazy_load? return unless ENV.key?("RUBY_MIME_TYPES_LAZY_LOAD") - MIME::Types.logger.warn <<-WARNING.chomp.strip + MIME::Types.logger.debug <<-WARNING.chomp.strip Lazy loading ($RUBY_MIME_TYPES_LAZY_LOAD) is deprecated and will be removed. WARNING