lib/bagit/bag.rb in bagit-0.4.6 vs lib/bagit/bag.rb in bagit-0.5.0
- old
+ new
@@ -6,22 +6,44 @@
require "bagit/manifest"
require "bagit/string"
require "bagit/valid"
module BagIt
+ class FileFinder
+ def self.find(dir)
+ raise NotImplementedError
+ end
+ end
+
+ class StandardFileFinder < FileFinder
+ def self.find(dir)
+ Dir[File.join(dir, "**", "*")].select { |f| File.file? f }
+ end
+ end
+
+ class StandardWithHiddenFileFinder < FileFinder
+ def self.find(dir)
+ Dir.glob(File.join(dir, "**", "*"), File::FNM_DOTMATCH).select { |f| File.file? f }
+ end
+ end
+
# Represents the state of a bag on a filesystem
class Bag
attr_reader :bag_dir
+ attr_reader :detect_hidden
include Validity # Validity functionality
include Info # bagit & bag info functionality
include Manifest # manifest related functionality
include Fetch # fetch related functionality
# Make a new Bag based at path
- def initialize(path, info = {}, _create = false)
+ def initialize(path, info = {}, _create = false, detect_hidden = false)
@bag_dir = path
+ @detect_hidden = detect_hidden
+ @file_finder = @detect_hidden ? StandardWithHiddenFileFinder : StandardFileFinder
+
# make the dir structure if it doesn't exist
FileUtils.mkdir bag_dir unless File.directory? bag_dir
FileUtils.mkdir data_dir unless File.directory? data_dir
# write some tag info if its not there
@@ -35,10 +57,10 @@
File.join @bag_dir, "data"
end
# Return the paths to each bag file relative to bag_dir
def bag_files
- Dir[File.join(data_dir, "**", "*")].select { |f| File.file? f }
+ @file_finder.find(data_dir)
end
# Return the paths to each tag file relative to bag_dir
def tag_files
files = []