defog 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,6 +19,12 @@ Defog also provides a few simple remote-file management methods to minimize
19
19
  the need to dig down into the Fog layer; but full access to the underlying
20
20
  fog objects is available should it be needed.
21
21
 
22
+ <b>NOTE:</b> Currently the only supported providers are :local and :AWS since
23
+ those are what the author currently uses. Please fork and add others!
24
+ (There's just a very small amount of provider-specific code in {one
25
+ file}[https://github.com/ronen/defog/blob/master/lib/defog/fog_wrapper.rb],
26
+ plus spec examples.)
27
+
22
28
  == Usage Summary
23
29
 
24
30
  Full Rdoc is available at http://rubydoc.info/gems/defog
@@ -52,15 +58,11 @@ Open a proxy to a remote file by creating a <code>Defog::File</code> object:
52
58
  <code>mode</code> can be "r", "r+", "w", "w+", "a", or "a+" with the usual
53
59
  semantics, and can be suffixed with "b" or with ":" and encoding as usual.
54
60
 
55
- When opened in a readable mode ("r", "r+", "w+", "a+"), first caches the
61
+ When opened in a readable mode ("r", "r+", "w+", "a+"), Defog first caches the
56
62
  cloud file in the local proxy. When opened in a writeable mode ("r+", "w",
57
- "w+", "a", "a+"), arranges to upload the changes back to the cloud file
63
+ "w+", "a", "a+"), Defog arranges to upload the changes back to the cloud file
58
64
  at close time.
59
65
 
60
- Closing the file object (explicitly or implicitly at the end of
61
- the block) synchronizes the local proxy with the remote storage and (by
62
- default) deletes the local proxy file.
63
-
64
66
  The <code>Defog::File</code> class inherits from <code>::File</code>. So
65
67
  you can use it directly for I/O operations, such as
66
68
 
@@ -76,7 +78,12 @@ You can also access the proxy file via its path, allowing things such as
76
78
 
77
79
  (Note that the proxy file path has the same file extension as the cloud key string.)
78
80
 
79
- To suppress updating the remote storage, delete the local proxy file before
81
+ Closing the file object (explicitly or implicitly at the end of the block)
82
+ synchronizes the local proxy with the remote storage if needed, and then (by
83
+ default) deletes the local proxy file.
84
+
85
+ To suppress deleting the local proxy file, use <code>:persist => true</code> (see
86
+ Persistence below). To suppress updating the remote storage, delete the local proxy file before
80
87
  closing (e.g. via <code>File.unlink(file.path)</code>) or pass
81
88
  <code>:synchronize => false</code> to the <code>#close</code> method.
82
89
 
@@ -190,6 +197,16 @@ And it's fair game to delete proxy files outside of Defog, such as via a
190
197
  cron job. Of course in these cases it's up to you to make sure not to
191
198
  unintentionally delete a proxy file that's currently open.
192
199
 
200
+ == Accessing Fog
201
+
202
+ You can access the underlying fog objects as needed:
203
+
204
+ defog = Defog::Proxy.new(:provider => ...)
205
+
206
+ defog.fog_connection # => the Fog::Storage object
207
+ defog.fog_directory # => the fog directory that contains the files being proxied
208
+ defog.file("key").fog_model # => the fog model for the cloud file
209
+
193
210
  == Installation
194
211
 
195
212
  Gemfile:
@@ -44,7 +44,7 @@ module Defog #:nodoc: all
44
44
  def initialize(opts={})
45
45
  opts = opts.keyword_args(:local_root => :required)
46
46
  @local_root = Pathname.new(opts.local_root).realpath
47
- @location = @local_root.to_s.gsub(%r{/},'_')
47
+ @location = @local_root.to_s.gsub(%r{/},'-')
48
48
  @fog_connection = Fog::Storage.new(:provider => provider, :local_root => @local_root)
49
49
  @fog_directory = @fog_connection.directories.get('.')
50
50
  end
@@ -61,7 +61,7 @@ module Defog
61
61
  @proxy_root ||= case
62
62
  when defined?(Rails) then Rails.root + "tmp"
63
63
  else Pathname.new(Dir.tmpdir)
64
- end + "defog" + provider.to_s + location
64
+ end + "defog" + "#{provider}-#{location}"
65
65
 
66
66
  end
67
67
 
@@ -1,3 +1,3 @@
1
1
  module Defog
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -67,13 +67,13 @@ shared_examples "a proxy" do |args|
67
67
  context "proxy root location" do
68
68
  it "should default proxy root to tmpdir/defog" do
69
69
  proxy = Defog::Proxy.new(args)
70
- proxy.proxy_root.should == Pathname.new(Dir.tmpdir) + "defog" + proxy.provider.to_s + proxy.location
70
+ proxy.proxy_root.should == Pathname.new(Dir.tmpdir) + "defog" + "#{proxy.provider.to_s}-#{proxy.location}"
71
71
  end
72
72
 
73
73
  it "should default proxy root to Rails.root" do
74
74
  with_rails_defined do
75
75
  proxy = Defog::Proxy.new(args)
76
- proxy.proxy_root.should == Rails.root + "tmp/defog" + proxy.provider.to_s + proxy.location
76
+ proxy.proxy_root.should == Rails.root + "tmp/defog" + "#{proxy.provider.to_s}-#{proxy.location}"
77
77
  end
78
78
  end
79
79
 
@@ -87,7 +87,7 @@ shared_examples "a proxy" do |args|
87
87
  context "cache management" do
88
88
  before(:each) do
89
89
  @proxy = Defog::Proxy.new(args.merge(:max_cache_size => 100, :persist => true))
90
- @proxy.proxy_root.rmtree
90
+ @proxy.proxy_root.rmtree if @proxy.proxy_root.exist?
91
91
  @proxy.proxy_root.mkpath
92
92
  end
93
93
 
@@ -216,7 +216,7 @@ describe Defog::Proxy do
216
216
  it_should_behave_like "a proxy", args
217
217
 
218
218
  it "should use the deslashed local_root as the location" do
219
- Defog::Proxy.new(args).location.should == LOCAL_CLOUD_PATH.to_s.gsub(%r{/},"_")
219
+ Defog::Proxy.new(args).location.should == LOCAL_CLOUD_PATH.to_s.gsub(%r{/},"-")
220
220
  end
221
221
 
222
222
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: defog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-28 00:00:00.000000000 Z
12
+ date: 2012-04-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fog
16
- requirement: &70269507983660 !ruby/object:Gem::Requirement
16
+ requirement: &70315023604540 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70269507983660
24
+ version_requirements: *70315023604540
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: hash_keyword_args
27
- requirement: &70269507983240 !ruby/object:Gem::Requirement
27
+ requirement: &70315023604100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70269507983240
35
+ version_requirements: *70315023604100
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: fastandand
38
- requirement: &70269507982820 !ruby/object:Gem::Requirement
38
+ requirement: &70315023603660 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70269507982820
46
+ version_requirements: *70315023603660
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70269507982400 !ruby/object:Gem::Requirement
49
+ requirement: &70315023603220 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70269507982400
57
+ version_requirements: *70315023603220
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &70269507981980 !ruby/object:Gem::Requirement
60
+ requirement: &70315023602800 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70269507981980
68
+ version_requirements: *70315023602800
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: simplecov
71
- requirement: &70269507981540 !ruby/object:Gem::Requirement
71
+ requirement: &70315023602380 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70269507981540
79
+ version_requirements: *70315023602380
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: simplecov-gem-adapter
82
- requirement: &70269507981020 !ruby/object:Gem::Requirement
82
+ requirement: &70315023601960 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70269507981020
90
+ version_requirements: *70315023601960
91
91
  description: Wrapper to fog gem, proxying access to cloud files as local files.
92
92
  email:
93
93
  - ronen@barzel.org