storage 0.1.1 → 0.1.2

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- storage (0.1.1)
4
+ storage (0.1.2)
5
5
  aws-s3 (~> 0.6.2)
6
6
 
7
7
  GEM
@@ -3,26 +3,29 @@ module Storage
3
3
  module FileSystem
4
4
  extend self
5
5
 
6
- def self.prepare!
6
+ def prepare!
7
7
  FileUtils.mkdir_p File.expand_path(Storage::Config.path)
8
8
  end
9
9
 
10
10
  def fullpath(file)
11
- File.expand_path(File.join(Storage::Config.path, file))
11
+ File.expand_path File.join(Storage::Config.path, file)
12
12
  end
13
13
 
14
- def get(file)
14
+ def get(file, *noop)
15
+ prepare!
15
16
  path = fullpath(file)
16
17
  raise Storage::MissingFileError unless File.file?(path)
17
18
  path
18
19
  end
19
20
 
20
- def remove(file)
21
+ def remove(file, *noop)
22
+ prepare!
21
23
  path = get(file)
22
24
  File.unlink(path)
23
25
  end
24
26
 
25
27
  def store(file, options = {})
28
+ prepare!
26
29
  file = File.open(file, "rb") unless file.respond_to?(:read) && !file.kind_of?(Pathname)
27
30
  path = fullpath(options[:name])
28
31
 
@@ -3,7 +3,7 @@ module Storage
3
3
  module S3
4
4
  extend self
5
5
 
6
- def prepare!
6
+ def connect!
7
7
  AWS::S3::Base.establish_connection!({
8
8
  :access_key_id => Storage::Config.access_key,
9
9
  :secret_access_key => Storage::Config.secret_key
@@ -11,6 +11,7 @@ module Storage
11
11
  end
12
12
 
13
13
  def get(file, options = {})
14
+ connect!
14
15
  object = find_object(file, options)
15
16
  AWS::S3::S3Object.url_for(file, options[:bucket], :authenticated => false)
16
17
  rescue AWS::S3::NoSuchKey, AWS::S3::NoSuchBucket
@@ -18,16 +19,18 @@ module Storage
18
19
  end
19
20
 
20
21
  def store(file, options = {})
22
+ connect!
21
23
  object = find_object(file, options) rescue nil
22
24
 
23
25
  raise Storage::FileAlreadyExistsError if object
24
26
 
25
27
  bucket = find_bucket_or_create(options[:bucket])
26
28
  file = File.open(file, "rb") unless file.respond_to?(:read) && !file.kind_of?(Pathname)
27
- AWS::S3::S3Object.store(options[:name], file, bucket.name, :access => :public_read)
29
+ AWS::S3::S3Object.store(options[:name], file, bucket.name, :access => options.fetch(:access, :public_read))
28
30
  end
29
31
 
30
32
  def remove(file, options = {})
33
+ connect!
31
34
  object = find_object(file, options)
32
35
  object.delete
33
36
  rescue AWS::S3::NoSuchKey, AWS::S3::NoSuchBucket
@@ -2,7 +2,7 @@ module Storage
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- PATCH = 1
5
+ PATCH = 2
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
data/lib/storage.rb CHANGED
@@ -18,7 +18,6 @@ module Storage
18
18
  #
19
19
  def self.setup(&block)
20
20
  yield Config
21
- strategy.prepare!
22
21
  end
23
22
 
24
23
  # A shortcut to the current strategy.
@@ -21,14 +21,14 @@ describe Storage::Strategies::S3 do
21
21
  options = {:access_key_id => "abc", :secret_access_key => "123"}
22
22
  AWS::S3::Base.should_receive(:establish_connection!).with(options)
23
23
 
24
- Storage::Strategies::S3.prepare!
24
+ Storage::Strategies::S3.connect!
25
25
  end
26
26
 
27
27
  it "should not reconnect when a connection is already established" do
28
28
  AWS::S3::Base.should_receive(:connected?).and_return(true)
29
29
  AWS::S3::Base.should_not_receive(:establish_connection!)
30
30
 
31
- Storage::Strategies::S3.prepare!
31
+ Storage::Strategies::S3.connect!
32
32
  end
33
33
 
34
34
  it "should save a file using file handler" do
@@ -51,8 +51,6 @@ describe Storage::Strategies::S3 do
51
51
  end
52
52
 
53
53
  it "should raise when trying to removing an unexesting file" do
54
- pending "spec is failing but real code works"
55
-
56
54
  Storage::Strategies::S3.should_receive(:find_object).and_raise(AWS::S3::NoSuchKey)
57
55
 
58
56
  expect {
@@ -70,8 +68,6 @@ describe Storage::Strategies::S3 do
70
68
  end
71
69
 
72
70
  it "should raise when trying to retrieve an unexesting file" do
73
- pending "spec is failing but real code works"
74
-
75
71
  AWS::S3::S3Object.should_receive(:find).with("lorem.txt", "files").and_raise(AWS::S3::NoSuchKey)
76
72
  AWS::S3::S3Object.should_not_receive(:url_for)
77
73
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: storage
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.1
5
+ version: 0.1.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Nando Vieira
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-31 00:00:00 Z
13
+ date: 2011-06-01 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-s3
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
142
  requirements: []
143
143
 
144
144
  rubyforge_project:
145
- rubygems_version: 1.8.3
145
+ rubygems_version: 1.8.5
146
146
  signing_key:
147
147
  specification_version: 3
148
148
  summary: "This gem provides a simple API for multiple storage backends. Supported storages: Amazon S3 and FileSystem."