class Synqa::LocalContentLocation
A directory of files on a local system. The corresponding content tree can be calculated directly using Ruby library functions.
Attributes
the base directory, for example of type Based::BaseDirectory
. Methods invoked are: allFiles, subDirs and fullPath. For file and dir objects returned by allFiles & subDirs, methods invoked are: relativePath and fullPath
the ruby class that generates the hash, e.g. Digest::SHA256
Public Class Methods
Synqa::ContentLocation::new
# File lib/synqa.rb, line 813 def initialize(baseDirectory, hashClass, cachedContentFile = nil) super(cachedContentFile) @baseDirectory = baseDirectory @hashClass = hashClass end
Public Instance Methods
get the content tree for this base directory by iterating over all sub-directories and files within the base directory (and excluding the excluded files) and calculating file hashes using the specified Ruby hash class If there is an existing cached content file, use that to get the hash values of files whose modification time is earlier than the time value for the cached content tree. Also, if a cached content file is specified, write the final content tree back out to the cached content file.
# File lib/synqa.rb, line 830 def getContentTree cachedTimeAndMapOfHashes = getCachedContentTreeMapOfHashes cachedTime = cachedTimeAndMapOfHashes[0] cachedMapOfHashes = cachedTimeAndMapOfHashes[1] contentTree = ContentTree.new() contentTree.time = Time.now.utc for subDir in @baseDirectory.subDirs contentTree.addDir(subDir.relativePath) end for file in @baseDirectory.allFiles cachedDigest = cachedMapOfHashes[file.relativePath] if cachedTime and cachedDigest and File.stat(file.fullPath).mtime < cachedTime digest = cachedDigest else digest = hashClass.file(file.fullPath).hexdigest end contentTree.addFile(file.relativePath, digest) end contentTree.sort! if cachedContentFile != nil contentTree.writeToFile(cachedContentFile) end return contentTree end
get the full path of a relative path (i.e. of a file/directory within the base directory)
# File lib/synqa.rb, line 820 def getFullPath(relativePath) return @baseDirectory.fullPath + relativePath end