Sha256: 5f6fa0561acd8628a097b16fe6c2bd2d54b174373b71f55c5efc50136ab9a741

Contents?: true

Size: 900 Bytes

Versions: 2

Compression:

Stored size: 900 Bytes

Contents

module Storage
  module Strategies
    module FileSystem
      extend self

      def self.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)
        path = fullpath(file)
        raise Storage::MissingFileError unless File.file?(path)
        path
      end

      def remove(file)
        path = get(file)
        File.unlink(path)
      end

      def store(file, options = {})
        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

2 entries across 2 versions & 1 rubygems

Version Path
storage-0.1.1 lib/storage/strategies/file_system.rb
storage-0.1.0 lib/storage/strategies/file_system.rb