esminc/adhoq

View on GitHub
lib/adhoq/storage/local_file.rb

Summary

Maintainability
A
0 mins
Test Coverage
require 'fog/local'

module Adhoq
  module Storage
    class LocalFile < FogStorage
      attr_reader :root

      def initialize(root_path)
        path = Pathname.new(root_path)

        @fog = Fog::Storage.new(provider: 'Local', local_root: path.parent)
        @dir = path.basename.to_s
      end

      def identifier
        "file://#{[@fog.local_root, @dir].join('/')}"
      end

      private

      def directory
        @fog.directories.get(@dir) || @fog.directories.create(key: @dir)
      end
    end
  end
end