Skip to content

Commit

Permalink
Fix requires to isolate all files as much as possible.
Browse files Browse the repository at this point in the history
  • Loading branch information
hainesr committed Feb 24, 2024
1 parent d3fc218 commit cd10d10
Show file tree
Hide file tree
Showing 19 changed files with 74 additions and 43 deletions.
16 changes: 1 addition & 15 deletions lib/zip-container.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013, 2014 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,20 +30,6 @@
#
# Author: Robert Haines

require 'rubygems'
require 'bundler/setup'

require 'zip/filesystem'

require 'zip-container/util'
require 'zip-container/version'
require 'zip-container/errors'
require 'zip-container/entries/reserved'
require 'zip-container/entries/managed'
require 'zip-container/entries/entry'
require 'zip-container/entries/file'
require 'zip-container/entries/directory'
require 'zip-container/container'
require 'zip-container/file'
require 'zip-container/dir'

Expand Down
5 changes: 4 additions & 1 deletion lib/zip-container/container.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2014, 2015 The University of Manchester, UK.
# Copyright (c) 2014-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,6 +30,9 @@
#
# Author: Robert Haines

require_relative 'entries/managed'
require_relative 'entries/reserved'

##
module ZipContainer
# The superclass of anything that represents a Zip Container. That
Expand Down
4 changes: 3 additions & 1 deletion lib/zip-container/dir.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2014 The University of Manchester, UK.
# Copyright (c) 2014-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,6 +30,8 @@
#
# Author: Robert Haines

require_relative 'container'

require 'forwardable'

module ZipContainer
Expand Down
6 changes: 5 additions & 1 deletion lib/zip-container/entries/directory.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2015 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,6 +30,10 @@
#
# Author: Robert Haines

require_relative 'entry'
require_relative 'managed'
require_relative 'reserved'

##
module ZipContainer
# A ManagedDirectory acts as the interface to a set of (possibly) managed
Expand Down
4 changes: 3 additions & 1 deletion lib/zip-container/entries/entry.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,6 +30,8 @@
#
# Author: Robert Haines

require_relative '../util'

##
module ZipContainer
# ManagedEntry is the superclass of ManagedDirectory and ManagedFile. It
Expand Down
4 changes: 3 additions & 1 deletion lib/zip-container/entries/file.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2015 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,6 +30,8 @@
#
# Author: Robert Haines

require_relative 'entry'

##
module ZipContainer
# A ManagedFile is used to reserve a filename in a Container namespace.
Expand Down
16 changes: 12 additions & 4 deletions lib/zip-container/entries/managed.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013, 2014 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,6 +30,11 @@
#
# Author: Robert Haines

require_relative 'entry'
require_relative 'file'
require_relative '../errors'
require_relative '../util'

##
module ZipContainer
# This module provides support for managed file and directory entries.
Expand Down Expand Up @@ -203,15 +208,18 @@ def initialize_managed_entries(entries = [])
# the container namespace and act as an interface to the (possibly)
# managed files within it.
def register_managed_entry(entry)
unless entry.is_a?(ManagedDirectory) || entry.is_a?(ManagedFile)
unless entry.is_a?(ManagedEntry)
raise ArgumentError,
'The supplied entry must be of type ' \
'ManagedDirectory or ManagedFile or a subclass of either.'
end

entry.parent = self
@directories[entry.name] = entry if entry.is_a? ManagedDirectory
@files[entry.name] = entry if entry.is_a? ManagedFile
if entry.is_a?(ManagedFile)
@files[entry.name] = entry
else
@directories[entry.name] = entry
end
end

private
Expand Down
4 changes: 3 additions & 1 deletion lib/zip-container/entries/reserved.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013, 2014 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,6 +30,8 @@
#
# Author: Robert Haines

require_relative '../util'

##
module ZipContainer
# This module provides support for reserved names.
Expand Down
4 changes: 3 additions & 1 deletion lib/zip-container/errors.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2015 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,6 +30,8 @@
#
# Author: Robert Haines

require 'zip/errors'

##
module ZipContainer
# The base of all errors raised by this library.
Expand Down
3 changes: 3 additions & 0 deletions lib/zip-container/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#
# Author: Robert Haines

require_relative 'container'

require 'zip/filesystem'
require 'forwardable'

module ZipContainer
Expand Down
5 changes: 4 additions & 1 deletion lib/zip-container/util.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2014 The University of Manchester, UK.
# Copyright (c) 2014-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,6 +30,9 @@
#
# Author: Robert Haines

require 'zip' # Remove this when we update to rubyzip 3.x.
require 'zip/entry'

##
module ZipContainer
# Utility methods useful throughout the rest of the ZipContainer library.
Expand Down
5 changes: 3 additions & 2 deletions test/create_dir_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2014-2023 The University of Manchester, UK.
# Copyright (c) 2014-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -31,8 +31,9 @@
# Author: Robert Haines

require_relative 'test_helper'

require 'tmpdir'
require 'zip-container'
require 'zip-container/dir'

class TestCreateDir < Minitest::Test
def test_create_container
Expand Down
5 changes: 3 additions & 2 deletions test/create_file_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2023 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -31,8 +31,9 @@
# Author: Robert Haines

require_relative 'test_helper'

require 'tmpdir'
require 'zip-container'
require 'zip-container/file'

class TestCreateFile < Minitest::Test
# Check creation of standard empty container files.
Expand Down
3 changes: 2 additions & 1 deletion test/errors_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
# Author: Robert Haines

require_relative 'test_helper'
require 'zip-container'

require 'zip-container/errors'

class TestExceptions < Minitest::Test
def test_rescue_container_errors
Expand Down
10 changes: 7 additions & 3 deletions test/managed_entries_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2023 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -30,10 +30,14 @@
#
# Author: Robert Haines

require_relative 'helpers/entry_lists'
require_relative 'test_helper'

require 'tmpdir'
require 'zip-container'
require_relative 'helpers/entry_lists'
require 'zip-container/file'
require 'zip-container/dir'
require 'zip-container/entries/file'
require 'zip-container/entries/directory'

# Classes to test managed entries.
class ManagedZipContainer < ZipContainer::File
Expand Down
5 changes: 3 additions & 2 deletions test/read_dir_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2014-2023 The University of Manchester, UK.
# Copyright (c) 2014-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -31,9 +31,10 @@
# Author: Robert Haines

require_relative 'test_helper'

require 'tmpdir'
require 'os'
require 'zip-container'
require 'zip-container/dir'

class TestReadDir < Minitest::Test
# Check that the empty directory does not verify.
Expand Down
5 changes: 3 additions & 2 deletions test/read_file_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2023 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -31,7 +31,8 @@
# Author: Robert Haines

require_relative 'test_helper'
require 'zip-container'

require 'zip-container/file'

class TestReadFile < Minitest::Test
# Check that the null file does not verify.
Expand Down
8 changes: 6 additions & 2 deletions test/reserved_names_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2013-2023 The University of Manchester, UK.
# Copyright (c) 2013-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -31,7 +31,11 @@
# Author: Robert Haines

require_relative 'test_helper'
require 'zip-container'

require 'zip-container/errors'
require 'zip-container/file'
require 'zip-container/entries/directory'
require 'zip-container/entries/file'

# A class to test the overriding of reserved and managed names.
class NewZipContainer < ZipContainer::File
Expand Down
5 changes: 3 additions & 2 deletions test/util_test.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2014-2023 The University of Manchester, UK.
# Copyright (c) 2014-2024 The University of Manchester, UK.
#
# All rights reserved.
#
Expand Down Expand Up @@ -31,8 +31,9 @@
# Author: Robert Haines

require_relative 'test_helper'

require 'zip-container/util'
require 'uri'
require 'zip-container'

class Util
include ZipContainer::Util
Expand Down

0 comments on commit cd10d10

Please sign in to comment.