Class: FakeDropbox::Glue

Inherits:
Object
  • Object
show all
Defined in:
lib/fake_dropbox/glue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dropbox_dir = ENV['DROPBOX_DIR']) ⇒ Glue

Returns a new instance of Glue.



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fake_dropbox/glue.rb', line 10

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

Instance Attribute Details

#dropbox_dirObject

Returns the value of attribute dropbox_dir.



8
9
10
# File 'lib/fake_dropbox/glue.rb', line 8

def dropbox_dir
  @dropbox_dir
end

Instance Method Details

#empty!Object



23
24
25
26
27
28
29
30
31
# File 'lib/fake_dropbox/glue.rb', line 23

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