omnistore 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -3,16 +3,48 @@ module OmniStore
|
|
3
3
|
module Local
|
4
4
|
extend self
|
5
5
|
|
6
|
-
|
6
|
+
class Mountpoint
|
7
|
+
attr_reader :dir
|
8
|
+
|
9
|
+
def initialize(dir)
|
10
|
+
@dir = dir
|
11
|
+
end
|
12
|
+
|
13
|
+
def exist?(path)
|
14
|
+
File.exist?(File.expand_path(path, dir))
|
15
|
+
end
|
16
|
+
|
17
|
+
def delete(path)
|
18
|
+
FileUtils.rm_f(File.expand_path(path, dir))
|
19
|
+
end
|
20
|
+
end
|
7
21
|
|
8
22
|
def mount!
|
9
|
-
mountpoint =
|
10
|
-
|
11
|
-
@@mountpoint =
|
23
|
+
@@mountpoint = {}
|
24
|
+
case mountpoint = OmniStore::Config.mountpoint
|
25
|
+
when Array then mountpoint.each {|m| validate(m); @@mountpoint[m] = Mountpoint.new(m) }
|
26
|
+
when Hash then mountpoint.each {|k,v| validate(v); @@mountpoint[k] = Mountpoint.new(v) }
|
27
|
+
else m = mountpoint.to_s; validate(m); @@mountpoint[m] = Mountpoint.new(m)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def mountpoint(key)
|
32
|
+
@@mountpoint[key]
|
12
33
|
end
|
13
34
|
|
14
35
|
def exist?(path)
|
15
|
-
|
36
|
+
@@mountpoint.values.find {|m| m.exist?(path) }
|
37
|
+
end
|
38
|
+
alias :find :exist?
|
39
|
+
|
40
|
+
def delete(path)
|
41
|
+
@@mountpoint.values.each {|m| m.delete(path) }
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def validate(mountpoint)
|
47
|
+
raise OmniStore::Errors::InvalidMountpoint unless File.exist?(mountpoint) && File.directory?(mountpoint)
|
16
48
|
end
|
17
49
|
end
|
18
50
|
end
|
data/lib/omnistore/storage/s3.rb
CHANGED
@@ -5,24 +5,60 @@ module OmniStore
|
|
5
5
|
module S3
|
6
6
|
extend self
|
7
7
|
|
8
|
-
|
8
|
+
class Mountpoint
|
9
|
+
attr_reader :bucket
|
10
|
+
|
11
|
+
def initialize(bucket)
|
12
|
+
@bucket = bucket
|
13
|
+
end
|
14
|
+
|
15
|
+
def exist?(key)
|
16
|
+
bucket.objects[key].exists?
|
17
|
+
end
|
18
|
+
|
19
|
+
def delete(key, options = {})
|
20
|
+
bucket.objects[key].delete(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def write(key, options_or_data = nil, options = nil)
|
24
|
+
bucket.objects[key].write(options_or_data, options)
|
25
|
+
end
|
26
|
+
end
|
9
27
|
|
10
28
|
def mount!
|
11
|
-
|
12
|
-
|
13
|
-
@@
|
29
|
+
@@buckets = {}
|
30
|
+
case mountpoint = OmniStore::Config.mountpoint
|
31
|
+
when Array then mountpoint.each {|m| b = validate(m); @@buckets[m] = Mountpoint.new(b) }
|
32
|
+
when Hash then mountpoint.each {|k,v| b = validate(v); @@buckets[k] = Mountpoint.new(b) }
|
33
|
+
else m = mountpoint.to_s; b = validate(m); @@buckets[m] = Mountpoint.new(b)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def mountpoint(key)
|
38
|
+
@@buckets[key]
|
14
39
|
end
|
15
40
|
|
16
41
|
def exist?(path)
|
17
|
-
@@
|
42
|
+
@@buckets.values.find {|b| b.exist?(path) }
|
43
|
+
end
|
44
|
+
alias :find :exist?
|
45
|
+
|
46
|
+
def delete(path, options = {})
|
47
|
+
@@buckets.values.each {|b| b.delete(path, options) }
|
18
48
|
end
|
19
49
|
|
20
50
|
def write(path, options_or_data = nil, options = nil)
|
21
|
-
@@
|
51
|
+
@@buckets.values.each {|b| b.write(path, options_or_data, options) }
|
22
52
|
end
|
23
53
|
|
24
54
|
private
|
25
55
|
|
56
|
+
def validate(name)
|
57
|
+
bucket = AWS::S3.new(options).buckets[name]
|
58
|
+
raise OmniStore::Errors::InvalidMountpoint unless bucket.exists?
|
59
|
+
bucket
|
60
|
+
end
|
61
|
+
|
26
62
|
def options
|
27
63
|
opts = {}
|
28
64
|
opts[:access_key_id] = OmniStore::Config.access_key if OmniStore::Config.access_key
|
data/lib/omnistore/version.rb
CHANGED
@@ -3,6 +3,12 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
describe OmniStore::Storage::Local do
|
5
5
|
|
6
|
+
before(:each) do
|
7
|
+
OmniStore::Config.storage = 'local'
|
8
|
+
OmniStore::Config.mountpoint = MOUNTPOINT
|
9
|
+
OmniStore::Storage.remount!
|
10
|
+
end
|
11
|
+
|
6
12
|
it 'should mount' do
|
7
13
|
OmniStore::Storage::Local.mount!.should_not be_nil
|
8
14
|
end
|
@@ -14,9 +20,14 @@ describe OmniStore::Storage::Local do
|
|
14
20
|
|
15
21
|
it 'should exist' do
|
16
22
|
path = 'test.txt'
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
expand_path = File.expand_path(path, OmniStore::Config.mountpoint)
|
24
|
+
FileUtils.touch(expand_path)
|
25
|
+
begin
|
26
|
+
OmniStore::Storage::Local.exist?(path).should be_true
|
27
|
+
OmniStore::Storage::Local.exist?(path+'.bk').should be_false
|
28
|
+
ensure
|
29
|
+
OmniStore::Storage::Local.delete(path)
|
30
|
+
end
|
20
31
|
end
|
21
32
|
|
22
33
|
end
|
@@ -5,7 +5,7 @@ describe "OmniStore::Storage::S3" do
|
|
5
5
|
|
6
6
|
before(:each) do
|
7
7
|
OmniStore::Config.storage = 's3'
|
8
|
-
OmniStore::Config.mountpoint =
|
8
|
+
OmniStore::Config.mountpoint = AWS_BUCKET
|
9
9
|
OmniStore::Storage.remount!
|
10
10
|
end
|
11
11
|
|
@@ -19,10 +19,14 @@ describe "OmniStore::Storage::S3" do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'should exist' do
|
22
|
-
|
23
|
-
OmniStore::Storage::S3.write(
|
24
|
-
|
25
|
-
|
22
|
+
key = 'test.txt'
|
23
|
+
OmniStore::Storage::S3.write(key, '')
|
24
|
+
begin
|
25
|
+
OmniStore::Storage::S3.exist?(key).should be_true
|
26
|
+
OmniStore::Storage::S3.exist?(key+'.bk').should be_false
|
27
|
+
ensure
|
28
|
+
OmniStore::Storage::S3.delete(key)
|
29
|
+
end
|
26
30
|
end
|
27
31
|
|
28
32
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -7,6 +7,8 @@ require 'aws-sdk'
|
|
7
7
|
require 'omnistore'
|
8
8
|
|
9
9
|
MOUNTPOINT = File.join(File.dirname(__FILE__), '/../data')
|
10
|
+
AWS_BUCKET = ENV['AWS_BUCKET']
|
11
|
+
|
10
12
|
OmniStore.configure do |config|
|
11
13
|
config.storage = 'local'
|
12
14
|
config.mountpoint = MOUNTPOINT
|
@@ -26,6 +28,5 @@ RSpec.configure do |config|
|
|
26
28
|
OmniStore::Config.reset_endpoint
|
27
29
|
OmniStore::Config.reset_proxy_uri
|
28
30
|
OmniStore.logger.level = Logger::FATAL
|
29
|
-
FileUtils.rm_rf(Dir.glob(File.join(MOUNTPOINT, '*')))
|
30
31
|
end
|
31
32
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omnistore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: aws-sdk
|
@@ -118,7 +118,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
segments:
|
120
120
|
- 0
|
121
|
-
hash:
|
121
|
+
hash: -480897425
|
122
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
123
|
none: false
|
124
124
|
requirements:
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
version: '0'
|
128
128
|
segments:
|
129
129
|
- 0
|
130
|
-
hash:
|
130
|
+
hash: -480897425
|
131
131
|
requirements: []
|
132
132
|
rubyforge_project:
|
133
133
|
rubygems_version: 1.8.24
|