Skip to content

Commit

Permalink
Stop using Util as a mixin.
Browse files Browse the repository at this point in the history
It makes no sense. We don't want classes using `Util` to have it
inserted into their superclass hierarchy. Just use it as a normal module.
  • Loading branch information
hainesr committed Feb 24, 2024
1 parent ef6bb47 commit 1491582
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 29 deletions.
8 changes: 3 additions & 5 deletions lib/zip-container/managed_entries.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ module ZipContainer
# +initialize_managed_entries+ in your constructor to ensure that the
# internal lists of managed entries are correctly assigned.
module ManagedEntries
include Util

# :call-seq:
# managed_directories -> Array
#
Expand Down Expand Up @@ -93,7 +91,7 @@ def managed_entry_names
#
# Is the supplied entry/name a managed entry?
def managed_entry?(entry, list = managed_entry_names)
name = entry_name(entry)
name = Util.entry_name(entry)
list.map(&:downcase).include? name.downcase
end

Expand All @@ -110,7 +108,7 @@ def managed_file?(entry)
#
# Is the supplied entry/name a hidden directory?
def hidden_directory?(entry)
name = entry_name(entry)
name = Util.entry_name(entry)
managed_directory?(name) ? all_managed_entries[name].hidden? : false
end

Expand All @@ -119,7 +117,7 @@ def hidden_directory?(entry)
#
# Is the supplied entry/name a hidden file?
def hidden_file?(entry)
name = entry_name(entry)
name = Util.entry_name(entry)
managed_file?(name) ? all_managed_entries[name].hidden? : false
end

Expand Down
4 changes: 0 additions & 4 deletions lib/zip-container/managed_entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,11 @@
#
# Author: Robert Haines

require_relative 'util'

##
module ZipContainer
# ManagedEntry is the superclass of ManagedDirectory and ManagedFile. It
# should not be used directly but may be subclassed if necessary.
class ManagedEntry
include Util

# The name of the ManagedEntry. For the full path name of this entry use
# full_name.
attr_reader :name
Expand Down
4 changes: 1 addition & 3 deletions lib/zip-container/reserved_names.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
module ZipContainer
# This module provides support for reserved names.
module ReservedNames
include Util

# :call-seq:
# reserved_names -> Array
#
Expand Down Expand Up @@ -70,7 +68,7 @@ def reserved_names
# Is the given entry in the reserved list of names? A String or a
# Zip::Entry object can be passed in here.
def reserved_entry?(entry)
name = entry_name(entry)
name = Util.entry_name(entry)
reserved_names.map(&:downcase).include? name.downcase
end

Expand Down
2 changes: 2 additions & 0 deletions lib/zip-container/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
module ZipContainer
# Utility methods useful throughout the rest of the ZipContainer library.
module Util
module_function

# :call-seq:
# entry_name(entry) -> String
#
Expand Down
30 changes: 13 additions & 17 deletions test/util_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,32 @@
require 'zip-container/util'
require 'uri'

class Util
include ZipContainer::Util
end

class TestUtil < Minitest::Test
def setup
@util = Util.new
end

def test_entry_name_strings
assert_equal('test', @util.entry_name('test'))
assert_equal('test', @util.entry_name('test/'))
assert_equal('test/test', @util.entry_name('test/test'))
assert_equal('test/test', @util.entry_name('test/test/'))
assert_equal('test', ZipContainer::Util.entry_name('test'))
assert_equal('test', ZipContainer::Util.entry_name('test/'))
assert_equal('test/test', ZipContainer::Util.entry_name('test/test'))
assert_equal('test/test', ZipContainer::Util.entry_name('test/test/'))
end

def test_entry_name_entries
assert_equal('test', @util.entry_name(Zip::Entry.new('fake.zip', 'test')))
assert_equal('test', @util.entry_name(Zip::Entry.new('fake.zip', 'test/')))
assert_equal(
'test/test', @util.entry_name(Zip::Entry.new('fake.zip', 'test/test'))
'test', ZipContainer::Util.entry_name(Zip::Entry.new('fake.zip', 'test'))
)
assert_equal(
'test', ZipContainer::Util.entry_name(Zip::Entry.new('fake.zip', 'test/'))
)
assert_equal(
'test/test', ZipContainer::Util.entry_name(Zip::Entry.new('fake.zip', 'test/test'))
)
assert_equal(
'test/test', @util.entry_name(Zip::Entry.new('fake.zip', 'test/test/'))
'test/test', ZipContainer::Util.entry_name(Zip::Entry.new('fake.zip', 'test/test/'))
)
end

def test_entry_name_odd_things
uri = URI.parse('http://www.example.com/path')

assert_equal(uri, @util.entry_name(uri))
assert_equal(uri, ZipContainer::Util.entry_name(uri))
end
end

0 comments on commit 1491582

Please sign in to comment.