Sha256: 3099e3a86efbcee299892043289d4fc4b1e686cda0c70dcff08a9c3c19a9506e
Contents?: true
Size: 1.02 KB
Versions: 2
Compression:
Stored size: 1.02 KB
Contents
module Tori module Backend class FileSystem attr_accessor :root def initialize(root) @root = root FileUtils.mkdir_p @root.to_s end def write(filename, resource, opts = nil) case resource when String ::File.open(path(filename), 'w'){ |f| f.write resource } when Pathname # see also https://bugs.ruby-lang.org/issues/11199 ::File.open(resource) { |src| FileUtils.mkdir_p path(filename).dirname ::File.open(path(filename), 'w'){ |dst| ::IO.copy_stream src, dst } } else ::IO.copy_stream resource, path(filename) end end def delete(filename) ::File.unlink path(filename) end def exist?(filename) ::File.exist? path(filename) end alias exists? exist? def read(filename) ::File.read path(filename) end def path(filename) @root.join filename.to_s end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
tori-0.2.0 | lib/tori/backend/filesystem.rb |
tori-0.1.0 | lib/tori/backend/filesystem.rb |