Sha256: a8c1270d2c1c0323ff49560efd7792795b9fab62a435f06b63df9ccb69f8dff5

Contents?: true

Size: 963 Bytes

Versions: 2

Compression:

Stored size: 963 Bytes

Contents

require 'webmock'
require 'tmpdir'
require 'fileutils'
require 'fake_dropbox/server'

module FakeDropbox
  class Glue
    attr_accessor :dropbox_dir
    
    def initialize(dropbox_dir=ENV['DROPBOX_DIR'])
      if dropbox_dir
        raise "Directory #{dropbox_dir} doesn't exist!" unless File.exists? dropbox_dir
        @dropbox_dir = dropbox_dir
      else
        @dropbox_dir = File.join(Dir.tmpdir, 'fake_dropbox')
        Dir.mkdir(@dropbox_dir) unless File.exists? @dropbox_dir
      end
      
      ENV['DROPBOX_DIR'] = @dropbox_dir
      WebMock.stub_request(:any, /.*dropbox.com.*/).to_rack(FakeDropbox::Server)
    end
    
    def empty!
      if File.expand_path(@dropbox_dir).start_with? Dir.tmpdir
        Dir.glob(File.join(@dropbox_dir, '*')).each do |entry|
          FileUtils.remove_entry_secure entry
        end
      else
        raise "Will not empty a directory which is outside of system's temporary path!"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fake_dropbox-0.2.0 lib/fake_dropbox/glue.rb
fake_dropbox-0.1.0 lib/fake_dropbox/glue.rb