Sha256: e6b015ad9d51441e5b598930868bf54e088a5c73931b82a3450baf7a4d0378d6

Contents?: true

Size: 1022 Bytes

Versions: 4

Compression:

Stored size: 1022 Bytes

Contents

module Storage
  module Strategies
    module FileSystem
      extend self

      def connect!
      end

      def disconnect!
      end

      def prepare!
        FileUtils.mkdir_p File.expand_path(Storage::Config.path)
      end

      def fullpath(file)
        File.expand_path File.join(Storage::Config.path, file)
      end

      def get(file, *noop)
        prepare!
        path = fullpath(file)
        raise Storage::MissingFileError unless File.file?(path)
        path
      end

      def remove(file, *noop)
        prepare!
        path = get(file)
        File.unlink(path)
      end

      def store(file, options = {})
        prepare!
        file = File.open(file, "rb") unless file.respond_to?(:read) && !file.kind_of?(Pathname)
        path = fullpath(options[:name])

        raise Storage::FileAlreadyExistsError if File.file?(path)

        File.open(path, "wb") do |handler|
          while line = file.gets
            handler.write line
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
storage-0.3.2 lib/storage/strategies/file_system.rb
storage-0.3.1 lib/storage/strategies/file_system.rb
storage-0.3.0 lib/storage/strategies/file_system.rb
storage-0.2.0 lib/storage/strategies/file_system.rb