Sha256: 77005d47856954e52b3f700551417ebb0cfd4c539cc110a2a2af94f47d5de5b2

Contents?: true

Size: 877 Bytes

Versions: 1

Compression:

Stored size: 877 Bytes

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)
        case resource
        when String
          ::File.open(path(filename), 'w'){ |f| f.write resource }
        # see also https://bugs.ruby-lang.org/issues/11199
        when Pathname
          ::IO.copy_stream resource.to_s, path(filename)
        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

1 entries across 1 versions & 1 rubygems

Version Path
tori-0.0.7 lib/tori/backend/filesystem.rb