dbox 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -192,6 +192,12 @@ Dbox.push(local_path)
192
192
  Dbox.move(new_remote_path, local_path)
193
193
  ```
194
194
 
195
+ #### Check whether a Dropbox DB file is present
196
+
197
+ ```ruby
198
+ Dbox.exists?(local_path)
199
+ ```
200
+
195
201
  #### Example
196
202
 
197
203
  ```sh
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.4.1
data/dbox.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dbox}
8
- s.version = "0.4.0"
8
+ s.version = "0.4.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Ken Pratt}]
12
- s.date = %q{2011-05-16}
12
+ s.date = %q{2011-05-17}
13
13
  s.description = %q{An easy-to-use Dropbox client with fine-grained control over syncs.}
14
14
  s.email = %q{ken@kenpratt.net}
15
15
  s.executables = [%q{dbox}]
data/lib/dbox/api.rb CHANGED
@@ -51,8 +51,6 @@ module Dbox
51
51
  path = escape_path(path)
52
52
  begin
53
53
  res = yield path
54
- log.debug "Result: #{res.inspect}"
55
-
56
54
  case res
57
55
  when Hash
58
56
  res
data/lib/dbox/db.rb CHANGED
@@ -22,17 +22,6 @@ module Dbox
22
22
  db.pull
23
23
  end
24
24
 
25
- def self.load(local_path)
26
- db_file = db_file(local_path)
27
- if File.exists?(db_file)
28
- db = File.open(db_file, "r") {|f| YAML::load(f.read) }
29
- db.local_path = local_path
30
- db
31
- else
32
- raise MissingDatabase, "No DB file found in #{local_path}"
33
- end
34
- end
35
-
36
25
  def self.pull(local_path)
37
26
  load(local_path).pull
38
27
  end
@@ -45,6 +34,20 @@ module Dbox
45
34
  load(local_path).move(new_remote_path)
46
35
  end
47
36
 
37
+ def self.exists?(local_path)
38
+ File.exists?(db_file(local_path))
39
+ end
40
+
41
+ def self.load(local_path)
42
+ if exists?(local_path)
43
+ db = File.open(db_file(local_path), "r") {|f| YAML::load(f.read) }
44
+ db.local_path = local_path
45
+ db
46
+ else
47
+ raise MissingDatabase, "No DB file found in #{local_path}"
48
+ end
49
+ end
50
+
48
51
  # IMPORTANT: DropboxDb.new is private. Please use DropboxDb.create, DropboxDb.clone, or DropboxDb.load as the entry point.
49
52
  private_class_method :new
50
53
  def initialize(local_path, res)
data/lib/dbox.rb CHANGED
@@ -45,6 +45,11 @@ module Dbox
45
45
  Dbox::DB.move(new_remote_path, local_path)
46
46
  end
47
47
 
48
+ def self.exists?(local_path)
49
+ local_path = clean_local_path(local_path)
50
+ Dbox::DB.exists?(local_path)
51
+ end
52
+
48
53
  private
49
54
 
50
55
  def self.clean_remote_path(path)
data/spec/dbox_spec.rb CHANGED
@@ -208,4 +208,21 @@ describe Dbox do
208
208
  expect { Dbox.move(@new_remote, @local) }.to raise_error(Dbox::RemoteAlreadyExists)
209
209
  end
210
210
  end
211
+
212
+ describe "#exists?" do
213
+ it "should be false if the local dir is missing" do
214
+ Dbox.exists?(@local).should be_false
215
+ end
216
+
217
+ it "should be true if the dir exists" do
218
+ Dbox.create(@remote, @local)
219
+ Dbox.exists?(@local).should be_true
220
+ end
221
+
222
+ it "should be false if the dir exists but is missing a .dropbox.db file" do
223
+ Dbox.create(@remote, @local)
224
+ rm "#{@local}/.dropbox.db"
225
+ Dbox.exists?(@local).should be_false
226
+ end
227
+ end
211
228
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbox
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ken Pratt
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-16 00:00:00 Z
18
+ date: 2011-05-17 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: An easy-to-use Dropbox client with fine-grained control over syncs.