omnistore 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,111 +1,32 @@
1
+ require 'omnistore/storage/local/mountpoint'
2
+
1
3
  module OmniStore
2
4
  module Storage
3
5
  module Local
4
6
  extend self
5
7
 
6
- class Mountpoint
7
- MEGABYTE = 1024*1024
8
- attr_reader :dir
9
-
10
- def initialize(name, dir)
11
- @name = name
12
- @dir = dir
13
- end
14
-
15
- def name
16
- @name
17
- end
18
-
19
- def url(key = nil, options = {})
20
- "file://#{dir}/#{key}"
21
- end
22
-
23
- def exist?(path)
24
- File.exist?(expand(path))
25
- end
26
-
27
- def delete(path)
28
- FileUtils.rm(expand(path))
29
- end
30
-
31
- def read(path, options = {}, &block)
32
- size = options[:chunk_size] || MEGABYTE
33
- open(expand(path), 'rb') do |f|
34
- block.call(f.read(size)) until f.eof?
35
- end
36
- end
37
-
38
- def write(path, options_or_data = nil, options = {})
39
- opts = convert_args_to_options_hash(options_or_data, options)
40
- size = opts[:chunk_size] || MEGABYTE
41
- data = convert_data_to_io_obj(opts)
42
- begin
43
- open(expand(path), 'wb') do |f|
44
- f.write(data.read(size)) until data.eof?
45
- end
46
- ensure
47
- data.close unless data.closed?
48
- end
49
- end
50
-
51
- def move(src, dest, other = self, options = {})
52
- src_path = expand(src)
53
- dest_path = expand(dest, other.dir)
54
- FileUtils.mkdir_p(File.dirname(dest_path)) if options[:force]
55
- FileUtils.mv(src_path, dest_path, options)
56
- end
57
-
58
- private
59
-
60
- def expand(path, dir = @dir)
61
- File.expand_path(path, dir)
62
- end
63
-
64
- def convert_args_to_options_hash(*args)
65
- case args.count
66
- when 0 then {}
67
- when 1 then args[0].is_a?(Hash) ? args[0] : { :data => args[0] }
68
- when 2 then args[1].merge(:data => args[0])
69
- else
70
- msg = "expected 0, 1 or 2 arguments, got #{args.count}"
71
- raise ArgumentError, msg
72
- end
73
- end
74
-
75
- def convert_data_to_io_obj(options)
76
- data = options.delete(:data)
77
- if data.is_a?(String)
78
- data.force_encoding("BINARY") if data.respond_to?(:force_encoding)
79
- StringIO.new(data)
80
- elsif data.is_a?(Pathname)
81
- open_file(data.to_s)
82
- elsif data.respond_to?(:read) and data.respond_to?(:eof?)
83
- data
84
- else
85
- msg = "invalid :data option, expected a String, Pathname or "
86
- msg << "an object that responds to #read and #eof?"
87
- raise ArgumentError, msg
88
- end
89
- end
90
-
91
- def open_file(path)
92
- file_opts = ['rb']
93
- file_opts << { :encoding => "BINARY" } if Object.const_defined?(:Encoding)
94
- File.open(path, *file_opts)
95
- end
96
- end
97
-
98
8
  def mount!
99
- @@mountpoint = {}
9
+ @@keys = {}
100
10
  case mountpoint = OmniStore::Config.mountpoint
101
- when Array then mountpoint.each {|m| validate(m); @@mountpoint[m] = Mountpoint.new(File.basename(m), m) }
102
- when Hash then mountpoint.each {|k,v| validate(v); @@mountpoint[k] = Mountpoint.new(k, v) }
103
- else m = mountpoint.to_s; validate(m); @@mountpoint[m] = Mountpoint.new(File.basename(m), m)
11
+ when Array
12
+ mountpoint.each do |m|
13
+ validate(m)
14
+ @@keys[m] = {:name => File.basename(m), :dir => m}
15
+ end
16
+ when Hash
17
+ mountpoint.each do |k,v|
18
+ validate(v)
19
+ @@keys[k] = {:name => k, :dir => v}
20
+ end
21
+ else
22
+ m = mountpoint.to_s
23
+ validate(m)
24
+ @@keys[m] = {:name => File.basename(m), :dir => m}
104
25
  end
105
26
  end
106
27
 
107
- def mountpoint(key = @@mountpoint.keys[0])
108
- @@mountpoint[key]
28
+ def mountpoint(key = @@keys.keys.first)
29
+ new_mountpoint(key)
109
30
  end
110
31
 
111
32
  def exist?(path, mp = mountpoint)
@@ -126,9 +47,9 @@ module OmniStore
126
47
 
127
48
  def each(&block)
128
49
  if block_given?
129
- @@mountpoint.each{|m| yield m }
50
+ @@keys.each{|key| yield new_mountpoint(key) }
130
51
  else
131
- Enumerator.new(@@mountpoint.values)
52
+ Enumerator.new(@@keys.map{|key| new_mountpoint(key) })
132
53
  end
133
54
  end
134
55
 
@@ -137,6 +58,11 @@ module OmniStore
137
58
  def validate(mountpoint)
138
59
  raise OmniStore::Errors::InvalidMountpoint unless File.exist?(mountpoint) && File.directory?(mountpoint)
139
60
  end
61
+
62
+ def new_mountpoint(key)
63
+ return nil unless @@keys.key?(key)
64
+ Mountpoint.new(@@keys[key][:name], @@keys[key][:dir])
65
+ end
140
66
  end
141
67
  end
142
68
  end
@@ -0,0 +1,103 @@
1
+ module OmniStore
2
+ module Storage
3
+ module Local
4
+ class Mountpoint
5
+ MEGABYTE = 1024*1024
6
+ attr_reader :dir
7
+
8
+ def initialize(name, dir)
9
+ @name = name
10
+ @dir = dir
11
+ end
12
+
13
+ def name
14
+ @name
15
+ end
16
+
17
+ def url(key = nil, options = {})
18
+ "file://#{dir}/#{key}"
19
+ end
20
+
21
+ def exist?(path)
22
+ File.exist?(expand(path))
23
+ end
24
+
25
+ def delete(path)
26
+ FileUtils.rm(expand(path))
27
+ end
28
+
29
+ def read(path, options = {}, &block)
30
+ size = options[:chunk_size] || MEGABYTE
31
+ open(expand(path), 'rb') do |f|
32
+ if block_given?
33
+ block.call(f.read(size)) until f.eof?
34
+ else
35
+ f.read
36
+ end
37
+ end
38
+ end
39
+
40
+ def write(path, options_or_data = nil, options = {})
41
+ opts = convert_args_to_options_hash(options_or_data, options)
42
+ size = opts[:chunk_size] || MEGABYTE
43
+ data = convert_data_to_io_obj(opts)
44
+ begin
45
+ open(expand(path), 'wb') do |f|
46
+ f.write(data.read(size)) until data.eof?
47
+ end
48
+ ensure
49
+ data.close unless data.closed?
50
+ end
51
+ end
52
+
53
+ def move(src, dest, other = self, options = {})
54
+ src_path = expand(src)
55
+ dest_path = expand(dest, other.dir)
56
+ FileUtils.mkdir_p(File.dirname(dest_path)) if options[:force]
57
+ FileUtils.mv(src_path, dest_path, options)
58
+ end
59
+
60
+ private
61
+
62
+ def expand(path, dir = @dir)
63
+ File.expand_path(path, dir)
64
+ end
65
+
66
+ def convert_args_to_options_hash(*args)
67
+ case args.count
68
+ when 0 then {}
69
+ when 1 then args[0].is_a?(Hash) ? args[0] : { :data => args[0] }
70
+ when 2 then args[1].merge(:data => args[0])
71
+ else
72
+ msg = "expected 0, 1 or 2 arguments, got #{args.count}"
73
+ raise ArgumentError, msg
74
+ end
75
+ end
76
+
77
+ def convert_data_to_io_obj(options)
78
+ data = options.delete(:data)
79
+ if data.is_a?(String)
80
+ data.force_encoding("BINARY") if data.respond_to?(:force_encoding)
81
+ StringIO.new(data)
82
+ elsif data.is_a?(Pathname)
83
+ open_file(data.to_s)
84
+ elsif data.respond_to?(:read) and data.respond_to?(:eof?)
85
+ data
86
+ else
87
+ msg = "invalid :data option, expected a String, Pathname or "
88
+ msg << "an object that responds to #read and #eof?"
89
+ raise ArgumentError, msg
90
+ end
91
+ end
92
+
93
+ def open_file(path)
94
+ file_opts = ['rb']
95
+ file_opts << { :encoding => "BINARY" } if Object.const_defined?(:Encoding)
96
+ File.open(path, *file_opts)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
102
+
103
+
@@ -1,63 +1,33 @@
1
1
  require 'aws-sdk'
2
+ require 'omnistore/storage/s3/mountpoint'
2
3
 
3
4
  module OmniStore
4
5
  module Storage
5
6
  module S3
6
7
  extend self
7
8
 
8
- class Mountpoint
9
- attr_reader :bucket
10
-
11
- def initialize(name, bucket)
12
- @name = name
13
- @bucket = bucket
14
- end
15
-
16
- def name
17
- @name
18
- end
19
-
20
- def url(key = nil, options = {})
21
- if key
22
- bucket.objects[key].public_url(:secure => options[:secure] != false).to_s
23
- else
24
- bucket.url
25
- end
26
- end
27
-
28
- def exist?(key)
29
- bucket.objects[key].exists?
30
- end
31
-
32
- def delete(key, options = {})
33
- bucket.objects[key].delete(options)
34
- end
35
-
36
- def read(key, options = {}, &block)
37
- bucket.objects[key].read(options, &block)
38
- end
39
-
40
- def write(key, options_or_data = nil, options = {})
41
- bucket.objects[key].write(options_or_data, options)
42
- end
43
-
44
- def move(src, dest, other = self, options = {})
45
- options[:bucket_name] = other.bucket.name
46
- bucket.objects[src].move_to(dest, options)
47
- end
48
- end
49
-
50
9
  def mount!
51
- @@buckets = {}
10
+ @@keys = {}
52
11
  case mountpoint = OmniStore::Config.mountpoint
53
- when Array then mountpoint.each {|m| b = validate(m); @@buckets[m] = Mountpoint.new(m, b) }
54
- when Hash then mountpoint.each {|k,v| b = validate(v); @@buckets[k] = Mountpoint.new(k, b) }
55
- else m = mountpoint.to_s; b = validate(m); @@buckets[m] = Mountpoint.new(m, b)
12
+ when Array
13
+ mountpoint.each do |m|
14
+ b = validate(m)
15
+ @@keys[m] = {:name => m, :bucket => b}
16
+ end
17
+ when Hash
18
+ mountpoint.each do |k,v|
19
+ b = validate(v)
20
+ @@keys[k] = {:name => k, :bucket => b}
21
+ end
22
+ else
23
+ m = mountpoint.to_s
24
+ b = validate(m)
25
+ @@keys[m] = {:name => m, :bucket => b}
56
26
  end
57
27
  end
58
28
 
59
- def mountpoint(key = @@buckets.keys[0])
60
- @@buckets[key]
29
+ def mountpoint(key = @@keys.keys.first)
30
+ new_mountpoint(key)
61
31
  end
62
32
 
63
33
  def exist?(path, mp = mountpoint)
@@ -79,9 +49,9 @@ module OmniStore
79
49
 
80
50
  def each(&block)
81
51
  if block_given?
82
- @@buckets.each{|b| yield b }
52
+ @@keys.each{|key| yield new_mountpoint(key) }
83
53
  else
84
- Enumerator.new(@@buckets.values)
54
+ Enumerator.new(@@keys.map{|key| new_mountpoint(key)})
85
55
  end
86
56
  end
87
57
 
@@ -101,6 +71,11 @@ module OmniStore
101
71
  opts[:proxy_uri] = OmniStore::Config.proxy_uri if OmniStore::Config.proxy_uri
102
72
  opts
103
73
  end
74
+
75
+ def new_mountpoint(key)
76
+ return nil unless @@keys.key?(key)
77
+ Mountpoint.new(@@keys[key][:name], @@keys[key][:bucket])
78
+ end
104
79
  end
105
80
  end
106
81
  end
@@ -0,0 +1,47 @@
1
+ module OmniStore
2
+ module Storage
3
+ module S3
4
+ class Mountpoint
5
+ attr_reader :bucket
6
+
7
+ def initialize(name, bucket)
8
+ @name = name
9
+ @bucket = bucket
10
+ end
11
+
12
+ def name
13
+ @name
14
+ end
15
+
16
+ def url(key = nil, options = {})
17
+ if key
18
+ bucket.objects[key].public_url(:secure => options[:secure] != false).to_s
19
+ else
20
+ bucket.url
21
+ end
22
+ end
23
+
24
+ def exist?(key)
25
+ bucket.objects[key].exists?
26
+ end
27
+
28
+ def delete(key, options = {})
29
+ bucket.objects[key].delete(options)
30
+ end
31
+
32
+ def read(key, options = {}, &block)
33
+ bucket.objects[key].read(options, &block)
34
+ end
35
+
36
+ def write(key, options_or_data = nil, options = {})
37
+ bucket.objects[key].write(options_or_data, options)
38
+ end
39
+
40
+ def move(src, dest, other = self, options = {})
41
+ options[:bucket_name] = other.bucket.name
42
+ bucket.objects[src].move_to(dest, options)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module OmniStore
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -0,0 +1,62 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniStore::Storage::Local::Mountpoint do
4
+ subject { OmniStore::Storage::Local.mountpoint }
5
+
6
+ context 'when single mountpoit' do
7
+ its(:name) { should eq File.basename(MOUNTPOINT) }
8
+ its(:url) { should eq "file://#{File.expand_path(MOUNTPOINT)}/" }
9
+ end
10
+
11
+ context 'when double mountpoint' do
12
+ before do
13
+ OmniStore::Config.mountpoint = { :a => MOUNTPOINT, :b => TMPDIR }
14
+ OmniStore::Storage.remount!
15
+ end
16
+ subject { OmniStore::Storage::Local.mountpoint(:b) }
17
+
18
+ its(:name) { should eq :b }
19
+ its(:url) { should eq "file://#{File.expand_path(TMPDIR)}/" }
20
+ end
21
+
22
+ describe '#url' do
23
+ let(:key) { nil }
24
+ subject { OmniStore::Storage::Local.mountpoint.url(key) }
25
+
26
+ context 'when key is not specified' do
27
+ it { should eq "file://#{File.expand_path(MOUNTPOINT)}/" }
28
+ end
29
+
30
+ context 'when key specified' do
31
+ let(:key) { 'test' }
32
+ it { should eq "file://#{File.expand_path(MOUNTPOINT)}/#{key}" }
33
+ end
34
+ end
35
+
36
+ describe '#move' do
37
+ let(:src) { t = Tempfile.new(TEST_FILENAME, MOUNTPOINT); File.basename(t.path) }
38
+ let(:dst) { TEST_FILENAME + Time.new.to_i.to_s }
39
+ let(:other) { OmniStore::Storage::Local.mountpoint(:a) }
40
+ subject { lambda { OmniStore::Storage::Local.mountpoint.move(src, dst, other) } }
41
+
42
+ before do
43
+ OmniStore::Config.mountpoint = { :a => MOUNTPOINT, :b => TMPDIR }
44
+ OmniStore::Storage.remount!
45
+ end
46
+ after { other.delete(dst) rescue nil }
47
+
48
+ context 'when specified a file path that does not exist' do
49
+ let(:src) { TEST_FILENAME + Time.new.to_i.to_s }
50
+ it { should raise_error }
51
+ end
52
+
53
+ context 'when specified a file path that exist' do
54
+ it { should_not raise_error }
55
+ end
56
+
57
+ context 'when move to another mountpoint' do
58
+ let(:other) { OmniStore::Storage::Local.mountpoint(:b) }
59
+ it { should_not raise_error }
60
+ end
61
+ end
62
+ end
@@ -70,65 +70,4 @@ describe OmniStore::Storage::Local do
70
70
  subject { OmniStore::Storage::Local.each }
71
71
  it { should be_a Enumerator }
72
72
  end
73
-
74
- describe OmniStore::Storage::Local::Mountpoint do
75
- subject { OmniStore::Storage::Local.mountpoint }
76
-
77
- context 'when single mountpoit' do
78
- its(:name) { should eq File.basename(MOUNTPOINT) }
79
- its(:url) { should eq "file://#{File.expand_path(MOUNTPOINT)}/" }
80
- end
81
-
82
- context 'when double mountpoint' do
83
- before do
84
- OmniStore::Config.mountpoint = { :a => MOUNTPOINT, :b => TMPDIR }
85
- OmniStore::Storage.remount!
86
- end
87
- subject { OmniStore::Storage::Local.mountpoint(:b) }
88
-
89
- its(:name) { should eq :b }
90
- its(:url) { should eq "file://#{File.expand_path(TMPDIR)}/" }
91
- end
92
-
93
- describe '#url' do
94
- let(:key) { nil }
95
- subject { OmniStore::Storage::Local.mountpoint.url(key) }
96
-
97
- context 'when key is not specified' do
98
- it { should eq "file://#{File.expand_path(MOUNTPOINT)}/" }
99
- end
100
-
101
- context 'when key specified' do
102
- let(:key) { 'test' }
103
- it { should eq "file://#{File.expand_path(MOUNTPOINT)}/#{key}" }
104
- end
105
- end
106
-
107
- describe '#move' do
108
- let(:src) { t = Tempfile.new(TEST_FILENAME, MOUNTPOINT); File.basename(t.path) }
109
- let(:dst) { TEST_FILENAME + Time.new.to_i.to_s }
110
- let(:other) { OmniStore::Storage::Local.mountpoint(:a) }
111
- subject { lambda { OmniStore::Storage::Local.mountpoint.move(src, dst, other) } }
112
-
113
- before do
114
- OmniStore::Config.mountpoint = { :a => MOUNTPOINT, :b => TMPDIR }
115
- OmniStore::Storage.remount!
116
- end
117
- after { other.delete(dst) rescue nil }
118
-
119
- context 'when specified a file path that does not exist' do
120
- let(:src) { TEST_FILENAME + Time.new.to_i.to_s }
121
- it { should raise_error }
122
- end
123
-
124
- context 'when specified a file path that exist' do
125
- it { should_not raise_error }
126
- end
127
-
128
- context 'when move to another mountpoint' do
129
- let(:other) { OmniStore::Storage::Local.mountpoint(:b) }
130
- it { should_not raise_error }
131
- end
132
- end
133
- end
134
73
  end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'OmniStore::Storage::S3::Mountpoint' do
4
+
5
+ before(:each) do
6
+ AWS::S3::Bucket.any_instance.stub(:exists?).and_return(true)
7
+ OmniStore::Config.storage = 's3'
8
+ OmniStore::Config.mountpoint = AWS_BUCKET
9
+ OmniStore::Storage.remount!
10
+ end
11
+
12
+ subject { OmniStore::Storage::S3.mountpoint }
13
+
14
+ context 'when single mountpoit' do
15
+ its(:name) { should eq AWS_BUCKET }
16
+ its(:url) { should match "#{AWS_BUCKET}" }
17
+ end
18
+
19
+ context 'when double mountpoint' do
20
+ before do
21
+ OmniStore::Config.mountpoint = { :a => AWS_BUCKET, :b => AWS_BUCKET }
22
+ OmniStore::Storage.remount!
23
+ end
24
+ subject { OmniStore::Storage::S3.mountpoint(:b) }
25
+
26
+ its(:name) { should eq :b }
27
+ its(:url) { should match "#{AWS_BUCKET}" }
28
+ end
29
+
30
+ describe '#url' do
31
+ let(:key) { nil }
32
+ let(:options) { {} }
33
+ subject { OmniStore::Storage::S3.mountpoint.url(key, options) }
34
+
35
+ context 'when key is not specified' do
36
+ it { should match "#{AWS_BUCKET}" }
37
+ end
38
+
39
+ context 'when key specified' do
40
+ let(:key) { 'test' }
41
+ it { should match "#{AWS_BUCKET}/#{key}" }
42
+ end
43
+
44
+ context 'when secure is true' do
45
+ let(:key) { 'test' }
46
+ let(:options) { { :secure => true } }
47
+ it { should match "^https://.*#{AWS_BUCKET}.*/#{key}" }
48
+ end
49
+
50
+ context 'when secure is false' do
51
+ let(:key) { 'test' }
52
+ let(:options) { { :secure => false } }
53
+ it { should match "^http://.*#{AWS_BUCKET}.*/#{key}" }
54
+ end
55
+
56
+ end
57
+
58
+ describe '#delete' do
59
+ let(:src) { TEST_FILENAME }
60
+ before { AWS::S3::S3Object.any_instance.stub(:delete).with({}) }
61
+ subject { lambda { OmniStore::Storage::S3.mountpoint.delete(src) } }
62
+
63
+ it { should_not raise_error }
64
+ end
65
+
66
+ describe '#read' do
67
+ let(:src) { TEST_FILENAME }
68
+ let(:data) { 'Hello World' }
69
+ before { AWS::S3::S3Object.any_instance.stub(:read).and_yield(data) }
70
+ subject { OmniStore::Storage::S3.mountpoint.read(src){|chunk| chunk } }
71
+
72
+ it { should eq data }
73
+ end
74
+
75
+ describe '#write' do
76
+ let(:src) { TEST_FILENAME }
77
+ let(:data) { 'Hello World' }
78
+ before { AWS::S3::S3Object.any_instance.stub(:write).with(data, {}) }
79
+ subject { lambda { OmniStore::Storage::S3.mountpoint.write(src, data) } }
80
+
81
+ it { should_not raise_error }
82
+ end
83
+
84
+ describe '#move' do
85
+ let(:src) { TEST_FILENAME }
86
+ let(:dst) { TEST_FILENAME + Time.new.to_i.to_s }
87
+ let(:other) { OmniStore::Storage::S3.mountpoint(:a) }
88
+ subject { lambda { OmniStore::Storage::S3.mountpoint.move(src, dst, other) } }
89
+
90
+ before do
91
+ OmniStore::Config.mountpoint = { :a => AWS_BUCKET, :b => AWS_BUCKET + 'b' }
92
+ OmniStore::Storage.remount!
93
+ end
94
+
95
+ context 'when move to same mountpoint' do
96
+ before do
97
+ AWS::S3::S3Object.any_instance.stub(:move_to).with do |*args|
98
+ args[0].should eq dst
99
+ args[1][:bucket_name].should eq AWS_BUCKET
100
+ true
101
+ end
102
+ end
103
+ it { should_not raise_error }
104
+ end
105
+
106
+ context 'when move to another mountpoint' do
107
+ before do
108
+ AWS::S3::S3Object.any_instance.stub(:move_to).with do |*args|
109
+ args[0].should eq dst
110
+ args[1][:bucket_name].should eq other.bucket.name
111
+ true
112
+ end
113
+ end
114
+ let(:other) { OmniStore::Storage::S3.mountpoint(:b) }
115
+ it { should_not raise_error }
116
+ end
117
+ end
118
+
119
+ end
@@ -1,5 +1,4 @@
1
1
  require 'spec_helper'
2
- require 'fileutils'
3
2
 
4
3
  describe "OmniStore::Storage::S3" do
5
4
 
@@ -79,112 +78,4 @@ describe "OmniStore::Storage::S3" do
79
78
  it { should be_a Enumerator }
80
79
  end
81
80
 
82
- describe 'OmniStore::Storage::S3::Mountpoint' do
83
- subject { OmniStore::Storage::S3.mountpoint }
84
-
85
- context 'when single mountpoit' do
86
- its(:name) { should eq AWS_BUCKET }
87
- its(:url) { should match "#{AWS_BUCKET}" }
88
- end
89
-
90
- context 'when double mountpoint' do
91
- before do
92
- OmniStore::Config.mountpoint = { :a => AWS_BUCKET, :b => AWS_BUCKET }
93
- OmniStore::Storage.remount!
94
- end
95
- subject { OmniStore::Storage::S3.mountpoint(:b) }
96
-
97
- its(:name) { should eq :b }
98
- its(:url) { should match "#{AWS_BUCKET}" }
99
- end
100
-
101
- describe '#url' do
102
- let(:key) { nil }
103
- let(:options) { {} }
104
- subject { OmniStore::Storage::S3.mountpoint.url(key, options) }
105
-
106
- context 'when key is not specified' do
107
- it { should match "#{AWS_BUCKET}" }
108
- end
109
-
110
- context 'when key specified' do
111
- let(:key) { 'test' }
112
- it { should match "#{AWS_BUCKET}/#{key}" }
113
- end
114
-
115
- context 'when secure is true' do
116
- let(:key) { 'test' }
117
- let(:options) { { :secure => true } }
118
- it { should match "^https://.*#{AWS_BUCKET}.*/#{key}" }
119
- end
120
-
121
- context 'when secure is false' do
122
- let(:key) { 'test' }
123
- let(:options) { { :secure => false } }
124
- it { should match "^http://.*#{AWS_BUCKET}.*/#{key}" }
125
- end
126
-
127
- end
128
-
129
- describe '#delete' do
130
- let(:src) { TEST_FILENAME }
131
- before { AWS::S3::S3Object.any_instance.stub(:delete).with({}) }
132
- subject { lambda { OmniStore::Storage::S3.mountpoint.delete(src) } }
133
-
134
- it { should_not raise_error }
135
- end
136
-
137
- describe '#read' do
138
- let(:src) { TEST_FILENAME }
139
- let(:data) { 'Hello World' }
140
- before { AWS::S3::S3Object.any_instance.stub(:read).and_yield(data) }
141
- subject { OmniStore::Storage::S3.mountpoint.read(src){|chunk| chunk } }
142
-
143
- it { should eq data }
144
- end
145
-
146
- describe '#write' do
147
- let(:src) { TEST_FILENAME }
148
- let(:data) { 'Hello World' }
149
- before { AWS::S3::S3Object.any_instance.stub(:write).with(data, {}) }
150
- subject { lambda { OmniStore::Storage::S3.mountpoint.write(src, data) } }
151
-
152
- it { should_not raise_error }
153
- end
154
-
155
- describe '#move' do
156
- let(:src) { TEST_FILENAME }
157
- let(:dst) { TEST_FILENAME + Time.new.to_i.to_s }
158
- let(:other) { OmniStore::Storage::S3.mountpoint(:a) }
159
- subject { lambda { OmniStore::Storage::S3.mountpoint.move(src, dst, other) } }
160
-
161
- before do
162
- OmniStore::Config.mountpoint = { :a => AWS_BUCKET, :b => AWS_BUCKET + 'b' }
163
- OmniStore::Storage.remount!
164
- end
165
-
166
- context 'when move to same mountpoint' do
167
- before do
168
- AWS::S3::S3Object.any_instance.stub(:move_to).with do |*args|
169
- args[0].should eq dst
170
- args[1][:bucket_name].should eq AWS_BUCKET
171
- true
172
- end
173
- end
174
- it { should_not raise_error }
175
- end
176
-
177
- context 'when move to another mountpoint' do
178
- before do
179
- AWS::S3::S3Object.any_instance.stub(:move_to).with do |*args|
180
- args[0].should eq dst
181
- args[1][:bucket_name].should eq other.bucket.name
182
- true
183
- end
184
- end
185
- let(:other) { OmniStore::Storage::S3.mountpoint(:b) }
186
- it { should_not raise_error }
187
- end
188
- end
189
- end
190
81
  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.10
4
+ version: 0.0.11
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-09-05 00:00:00.000000000 Z
12
+ date: 2012-09-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk
@@ -96,11 +96,15 @@ files:
96
96
  - lib/omnistore/errors.rb
97
97
  - lib/omnistore/storage.rb
98
98
  - lib/omnistore/storage/local.rb
99
+ - lib/omnistore/storage/local/mountpoint.rb
99
100
  - lib/omnistore/storage/s3.rb
101
+ - lib/omnistore/storage/s3/mountpoint.rb
100
102
  - lib/omnistore/version.rb
101
103
  - omnistore.gemspec
102
104
  - spec/omnistore/config_spec.rb
105
+ - spec/omnistore/storage/local/mountpoint_spec.rb
103
106
  - spec/omnistore/storage/local_spec.rb
107
+ - spec/omnistore/storage/s3/mountpoint_spec.rb
104
108
  - spec/omnistore/storage/s3_spec.rb
105
109
  - spec/omnistore/storage_spec.rb
106
110
  - spec/omnistore_spec.rb
@@ -119,7 +123,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
119
123
  version: '0'
120
124
  segments:
121
125
  - 0
122
- hash: 1003914863
126
+ hash: -552854129
123
127
  required_rubygems_version: !ruby/object:Gem::Requirement
124
128
  none: false
125
129
  requirements:
@@ -128,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
132
  version: '0'
129
133
  segments:
130
134
  - 0
131
- hash: 1003914863
135
+ hash: -552854129
132
136
  requirements: []
133
137
  rubyforge_project:
134
138
  rubygems_version: 1.8.24
@@ -137,7 +141,9 @@ specification_version: 3
137
141
  summary: Providers a single point of entry for storage
138
142
  test_files:
139
143
  - spec/omnistore/config_spec.rb
144
+ - spec/omnistore/storage/local/mountpoint_spec.rb
140
145
  - spec/omnistore/storage/local_spec.rb
146
+ - spec/omnistore/storage/s3/mountpoint_spec.rb
141
147
  - spec/omnistore/storage/s3_spec.rb
142
148
  - spec/omnistore/storage_spec.rb
143
149
  - spec/omnistore_spec.rb