Sha256: 32a0c54609ca55720e98493d5f970dbcfcfd42af977fedf47f99f4a1ba85711b

Contents?: true

Size: 739 Bytes

Versions: 2

Compression:

Stored size: 739 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 }
        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.0.6 lib/tori/backend/filesystem.rb
tori-0.0.5 lib/tori/backend/filesystem.rb