Skip to content

Commit

Permalink
mime-types 3.1
Browse files Browse the repository at this point in the history
*   3 bug fixes

    *   A test for MIME::Types::Cache fails under Ruby 2.3 because of frozen
        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
        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 sufficient.

*   1 governance change

    *   Updated to Contributor Covenant 1.4.
  • Loading branch information
halostatue committed May 22, 2016
1 parent a46e29d commit 6fc325f
Show file tree
Hide file tree
Showing 15 changed files with 343 additions and 275 deletions.
24 changes: 16 additions & 8 deletions .hoerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,27 @@
exclude: !ruby/regexp '/
\.(tmp|swp)$
|
(CVS|tmp)\/
\.(?:autotest|gemtest|gitignore|hoerc|minitest.rb|simplecov-prelude.rb)
|
(?i:TAGS)
^(?i:TAGS)
|
\.(svn|git|hg|DS_Store|idea|vagrant)\/
\.(?:
DS_Store|
bundle|
git|
hg|
idea|
svn|
vagrant
)\/
|
Gemfile(?:\.lock)?
[gG]emfile(?:\.lock)?
|
\.(rubocop|coveralls|pullreview|travis).yml$
support\/
|
\.gemspec
\.(?:coveralls|pullreview|travis|rubocop.*)\.yml
|
\.byebug_history
.byebug_history
|
Vagrantfile
\.gemspec$
/x'
87 changes: 60 additions & 27 deletions Code-of-Conduct.rdoc
Original file line number Diff line number Diff line change
@@ -1,41 +1,74 @@
== Contributor Code of Conduct
== Contributor Covenant Code of Conduct

As contributors and maintainers of this project, and in the interest of
fostering an open and welcoming community, we pledge to respect all people who
contribute through reporting issues, posting feature requests, updating
documentation, submitting pull requests or patches, and other activities.
## Our Pledge

We are committed to making participation in this project a harassment-free
experience for everyone, regardless of level of experience, gender, gender
identity and expression, sexual orientation, disability, personal appearance,
body size, race, ethnicity, age, religion, or nationality.
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age,
body size, disability, ethnicity, gender identity and expression, level of
experience, nationality, personal appearance, race, religion, or sexual
identity and orientation.

=== Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery
* Personal attacks
* Trolling or insulting/derogatory comments
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing other's private information, such as physical or electronic
addresses, without explicit permission
* Other unethical or unprofessional conduct.
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

=== Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct. By adopting this Code of Conduct,
project maintainers commit themselves to fairly and consistently applying these
principles to every aspect of managing this project. Project maintainers who do
not follow or enforce the Code of Conduct may be permanently removed from the
project team.
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

This code of conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community.
=== Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an
appointed representative at an online or offline event. Representation of a
project may be further defined and clarified by project maintainers.

=== Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by opening an issue or contacting one or more of the project
maintainers.
reported by contacting the project team at [INSERT EMAIL ADDRESS]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an
incident. Further details of specific enforcement policies may be posted
separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

=== Attribution

This Code of Conduct is adapted from the
{Contributor Covenant}[http://contributor-covenant.org], version 1.2.0,
This Code of Conduct is adapted from the {Contributor
Covenant}[http://contributor-covenant.org], version 1.4,
available at
{http://contributor-covenant.org/version/1/2/0/}[http://contributor-covenant.org/version/1/2/0/].
{http://contributor-covenant.org/version/1/4/}[http://contributor-covenant.org/version/1/4/].
23 changes: 22 additions & 1 deletion History.rdoc
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
== NEXT / 2016-MM-DD
== 3.1 / 2016-05-22

* 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}[https://github.com/mime-types/ruby-mime-types/pull/112].

* 3 bug fixes

* A test for MIME::Types::Cache fails under Ruby 2.3 because of frozen
strings, {#118}[https://github.com/mime-types/ruby-mime-types/issues/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}[https://github.com/mime-types/ruby-mime-types/issues/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 sufficient.

* 1 governance change

* Updated to {Contributor Covenant 1.4}[Code-of-Conduct_rdoc.html].

== 3.0 / 2015-11-21

* 2 governance changes
Expand Down
11 changes: 1 addition & 10 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.autotest
.gemtest
.gitignore
.hoerc
Code-of-Conduct.rdoc
Contributing.rdoc
History.rdoc
Expand All @@ -13,6 +9,7 @@ lib/mime-types.rb
lib/mime/type.rb
lib/mime/type/columnar.rb
lib/mime/types.rb
lib/mime/types/_columnar.rb
lib/mime/types/cache.rb
lib/mime/types/columnar.rb
lib/mime/types/container.rb
Expand All @@ -21,12 +18,6 @@ lib/mime/types/full.rb
lib/mime/types/loader.rb
lib/mime/types/logger.rb
lib/mime/types/registry.rb
support/benchmarks/load.rb
support/benchmarks/load_allocations.rb
support/benchmarks/object_counts.rb
support/profile/columnar.rb
support/profile/columnar_full.rb
support/profile/full.rb
test/bad-fixtures/malformed
test/fixture/json.json
test/fixture/old-data
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ spec = Hoe.spec 'mime-types' do
extra_dev_deps << ['minitest-autotest', '~> 1.0']
extra_dev_deps << ['minitest-focus', '~> 1.0']
extra_dev_deps << ['minitest-bonus-assertions', '~> 2.0']
extra_dev_deps << ['minitest-hooks', '~> 1.4']
extra_dev_deps << ['rake', '~> 10.0']
extra_dev_deps << ['fivemat', '~> 1.3' ]
extra_dev_deps << ['minitest-rg', '~> 5.2']
Expand Down
11 changes: 9 additions & 2 deletions lib/mime/type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def to_s
end

# The released version of the mime-types library.
VERSION = '3.0'
VERSION = '3.1'

include Comparable

Expand Down Expand Up @@ -450,7 +450,14 @@ def encode_with(coder)
coder['obsolete'] = obsolete?
coder['use-instead'] = use_instead if use_instead
end
coder['xrefs'] = xrefs unless xrefs.empty?
unless xrefs.empty?
{}.tap do |hash|
xrefs.each do |k, v|
hash[k] = v.sort.to_a
end
coder['xrefs'] = hash
end
end
coder['registered'] = registered?
coder['signature'] = signature? if signature?
coder
Expand Down
10 changes: 5 additions & 5 deletions lib/mime/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ class Types
end
end

require 'mime/types/logger'
require 'mime/types/container'
require 'mime/type'
require 'mime/types/cache'
require 'mime/types/loader'

# MIME::Types is a registry of MIME types. It is both a class (created with
# MIME::Types.new) and a default registry (loaded automatically or through
Expand Down Expand Up @@ -224,5 +220,9 @@ def match(pattern)
end
end

require 'mime/types/columnar' unless defined?(MIME::Types::Columnar)
require 'mime/types/cache'
require 'mime/types/container'
require 'mime/types/loader'
require 'mime/types/logger'
require 'mime/types/_columnar'
require 'mime/types/registry'
135 changes: 135 additions & 0 deletions lib/mime/types/_columnar.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
require 'mime/type/columnar'

# MIME::Types::Columnar is used to extend a MIME::Types container to load data
# by columns instead of from JSON or YAML. Column loads of MIME types loaded
# through the columnar store are synchronized with a Mutex.
#
# MIME::Types::Columnar is not intended to be used directly, but will be added
# to an instance of MIME::Types when it is loaded with
# MIME::Types::Loader#load_columnar.
module MIME::Types::Columnar
LOAD_MUTEX = Mutex.new # :nodoc:

def self.extended(obj) # :nodoc:
super
obj.instance_variable_set(:@__mime_data__, [])
obj.instance_variable_set(:@__files__, Set.new)
end

# Load the first column data file (type and extensions).
def load_base_data(path) #:nodoc:
@__root__ = path

each_file_line('content_type', false) do |line|
line = line.split
content_type = line.shift
extensions = line
# content_type, *extensions = line.split

type = MIME::Type::Columnar.new(self, content_type, extensions)
@__mime_data__ << type
add(type)
end

self
end

private

def each_file_line(name, lookup = true)
LOAD_MUTEX.synchronize do
next if @__files__.include?(name)

i = -1
column = File.join(@__root__, "mime.#{name}.column")

IO.readlines(column, encoding: 'UTF-8'.freeze).each do |line|
line.chomp!

if lookup
type = @__mime_data__[i += 1] or next
yield type, line
else
yield line
end
end

@__files__ << name
end
end

def load_encoding
each_file_line('encoding') do |type, line|
pool ||= {}
line.freeze
type.instance_variable_set(:@encoding, (pool[line] ||= line))
end
end

def load_docs
each_file_line('docs') do |type, line|
type.instance_variable_set(:@docs, opt(line))
end
end

def load_preferred_extension
each_file_line('pext') do |type, line|
type.instance_variable_set(:@preferred_extension, opt(line))
end
end

def load_flags
each_file_line('flags') do |type, line|
line = line.split
type.instance_variable_set(:@obsolete, flag(line.shift))
type.instance_variable_set(:@registered, flag(line.shift))
type.instance_variable_set(:@signature, flag(line.shift))
end
end

def load_xrefs
each_file_line('xrefs') { |type, line|
type.instance_variable_set(:@xrefs, dict(line, array: true))
}
end

def load_friendly
each_file_line('friendly') { |type, line|
type.instance_variable_set(:@friendly, dict(line))
}
end

def load_use_instead
each_file_line('use_instead') do |type, line|
type.instance_variable_set(:@use_instead, opt(line))
end
end

def dict(line, array: false)
if line == '-'.freeze
{}
else
line.split('|'.freeze).each_with_object({}) { |l, h|
k, v = l.split('^'.freeze)
v = nil if v.empty?
h[k] = array ? Array(v) : v
}
end
end

def arr(line)
if line == '-'.freeze
[]
else
line.split('|'.freeze).flatten.compact.uniq
end
end

def opt(line)
line unless line == '-'.freeze
end

def flag(line)
line == '1'.freeze ? true : false
end
end
Loading

0 comments on commit 6fc325f

Please sign in to comment.