Class: Configuration::S3SourceStoreBase::CacheRoot

Inherits:
Object
  • Object
show all
Defined in:
lib/httpimagestore/configuration/s3.rb

Defined Under Namespace

Classes: CacheFile, CacheRootNotAccessibleError, CacheRootNotDirError, CacheRootNotWritableError

Constant Summary collapse

CacheRootError =
Class.new ArgumentError

Instance Method Summary collapse

Constructor Details

#initialize(root_dir) ⇒ CacheRoot

Returns a new instance of CacheRoot.



144
145
146
147
148
149
# File 'lib/httpimagestore/configuration/s3.rb', line 144

def initialize(root_dir)
	@root = Pathname.new(root_dir)
	@root.directory? or raise CacheRootNotDirError.new(root_dir)
	@root.executable? or raise CacheRootNotAccessibleError.new(root_dir)
	@root.writable? or raise CacheRootNotWritableError.new(root_dir)
end

Instance Method Details

#cache_file(bucket, key) ⇒ Object



151
152
153
# File 'lib/httpimagestore/configuration/s3.rb', line 151

def cache_file(bucket, key)
	CacheFile.new(File.join(@root.to_s, *Digest::SHA2.new.update("#{bucket}/#{key}").to_s[0,32].match(/(..)(..)(.*)/).captures))
end