storage 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 184a2c065d267a1a8c69ea2b28cb10029ed87386
4
- data.tar.gz: 92487bed7cda01963ec791f9a97be0c7aabf0cf4
3
+ metadata.gz: debdbb389e3c318ff68a502dc87ac52fbd047894
4
+ data.tar.gz: 1857d2fa6a260d0862400d519d2ac0c34c4f1a51
5
5
  SHA512:
6
- metadata.gz: 690d4ab3a737bd1d4d4cdbdefc6837604af4f7776ce9fb76cbd8243e3cec6d3c88fa4b81e621337af72d6fb930eab0cbc783c1385af58f4149e18c2e4935c461
7
- data.tar.gz: b0b17efdf1edfa68fb8ed89daf2ddfdcf0d2478d9194c8a5ffe654f9569e95a990d676577fdaa8e265a5f753f801c5f773f97a8a57c6b4b2f5eb4da51c264ea5
6
+ metadata.gz: 8a1e73f719687b06f538a307b7caaa06ee3f598d44f0b2baa2e6f4c4233281e91235d6d426f2e90bf45479af58ee047f815e5eba82e30e7b5c314e904c240cce
7
+ data.tar.gz: 8338bc57f95931f7e6db01c5ae8ba0c8ee9d7339b38e0bb57fde7051afb2a4f68e8cc5554228d2b4b72f800fde66f0025e20cfc4b36846cfe3e9f74cf084267e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- storage (0.3.1)
4
+ storage (0.3.2)
5
5
  fog
6
6
  mime-types
7
7
 
data/README.md CHANGED
@@ -34,11 +34,15 @@ Storage.store "some/file.rb", name: "file.rb", bucket: "sample"
34
34
  Storage.store File.open("some/file.rb"), name: "file.rb", bucket: "sample", public: true
35
35
 
36
36
  # Retrieve the public url for that file
37
- Storage.get "file.rb"
37
+ Storage.get "file.rb", bucket: "sample"
38
38
  #=> http://s3.amazon.com/sample-files/file.rb
39
39
 
40
+ # Retrieve the public url for a private file,
41
+ # setting expiration to 5 minutes (300 seconds).
42
+ Storage.get "private.rb", bucket: "sample", expires: Time.now.to_i + 300
43
+
40
44
  # Remove a file.
41
- Storage.remove "file.rb"
45
+ Storage.remove "file.rb", bucket: "sample"
42
46
  ```
43
47
 
44
48
  ### FileSystem
@@ -32,9 +32,6 @@ module Storage
32
32
  end
33
33
 
34
34
  def store(file, options = {})
35
- object = find_object(file, options) rescue nil
36
- fail FileAlreadyExistsError if object
37
-
38
35
  bucket = find_bucket_or_create(options.fetch(:bucket))
39
36
  file = File.open(file, "rb") unless file.respond_to?(:read) && !file.kind_of?(Pathname)
40
37
 
@@ -2,7 +2,7 @@ module Storage
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 3
5
- PATCH = 1
5
+ PATCH = 2
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  end
8
8
  end
@@ -41,31 +41,27 @@ describe Storage::Strategies::S3 do
41
41
 
42
42
  it "should save a file using file handler" do
43
43
  handler = File.open(source)
44
-
45
- setup_expectations
44
+ setup_create_object
46
45
 
47
46
  Storage.store(handler, name: "lorem.txt", bucket: "files")
48
47
  end
49
48
 
50
49
  it "should save a file using a path" do
51
- setup_expectations
52
-
50
+ setup_create_object
53
51
  Storage.store(source, name: "lorem.txt", bucket: "files")
54
52
  end
55
53
 
56
54
  it "should remove an existing file" do
57
55
  object = double("object")
58
56
 
59
- setup_bucket(bucket)
60
- setup_object(object)
57
+ setup_get_object object: object
61
58
  expect(object).to receive(:destroy).and_return(true)
62
59
 
63
60
  expect(Storage.remove("lorem.txt", bucket: "files")).to be_truthy
64
61
  end
65
62
 
66
63
  it "should raise when trying to removing an nonexisting file" do
67
- setup_bucket(bucket)
68
- setup_get(nil)
64
+ setup_get_object object: nil
69
65
 
70
66
  expect {
71
67
  Storage.remove("lorem.txt", bucket: "files")
@@ -75,8 +71,7 @@ describe Storage::Strategies::S3 do
75
71
  it "should retrieve an existing file (public url)" do
76
72
  object = double("object", public_url: "PUBLIC_URL")
77
73
 
78
- setup_bucket(bucket)
79
- setup_object(object)
74
+ setup_get_object object: object
80
75
 
81
76
  expect(Storage.get("lorem.txt", bucket: "files")).to eq("PUBLIC_URL")
82
77
  end
@@ -85,15 +80,13 @@ describe Storage::Strategies::S3 do
85
80
  object = double("object", public_url: nil)
86
81
 
87
82
  expect(object).to receive_message_chain("url").with(Time.now.to_i + 3600).and_return("PRIVATE_URL")
88
- setup_bucket(bucket)
89
- setup_object(object)
83
+ setup_get_object object: object
90
84
 
91
- expect(Storage.get("lorem.txt", :bucket => "files")).to eq("PRIVATE_URL")
85
+ expect(Storage.get("lorem.txt", bucket: "files")).to eq("PRIVATE_URL")
92
86
  end
93
87
 
94
88
  it "should raise when trying to retrieve an missing file" do
95
- setup_bucket(bucket)
96
- setup_get(nil)
89
+ setup_get_object object: nil
97
90
 
98
91
  expect {
99
92
  Storage.get("lorem.txt", bucket: "files")
@@ -101,80 +94,62 @@ describe Storage::Strategies::S3 do
101
94
  end
102
95
 
103
96
  it "should raise when trying to retrieve an missing bucket" do
104
- setup_bucket(nil)
97
+ setup_get_bucket bucket: nil
105
98
 
106
99
  expect {
107
100
  Storage.get("lorem.txt", bucket: "files")
108
101
  }.to raise_error(Storage::MissingFileError)
109
102
  end
110
103
 
111
- it "should create a bucket and trying to store a file on a missing bucket" do
112
- setup_object
113
- setup_bucket(nil)
114
-
115
- expect(connection).to receive_message_chain("directories.create").with(key: "files", public: false).and_return(bucket)
116
-
104
+ it "should create a bucket when trying to store a file on a missing bucket" do
117
105
  bucket.as_null_object
106
+ setup_create_bucket
118
107
 
119
108
  Storage.store(source, name: "lorem.txt", bucket: "files")
120
109
  end
121
110
 
122
- it "should raise when saving a file that already exists" do
123
- object = double("object")
124
-
125
- setup_bucket(bucket)
126
- setup_get(object)
127
-
128
- expect {
129
- Storage.store(source, name: "lorem.txt", bucket: "files")
130
- }.to raise_error(Storage::FileAlreadyExistsError)
131
- end
132
-
133
111
  it "should set file permission to public" do
134
- setup_expectations public_access: true
112
+ setup_create_object public: true
135
113
  Storage.store(source, name: "lorem.txt", bucket: "files", public: true)
136
114
  end
137
115
 
138
116
  it "should set file permission to private (default)" do
139
- setup_expectations public_access: false
117
+ setup_create_object public: false
140
118
  Storage.store(source, name: "lorem.txt", bucket: "files")
141
119
  end
142
120
 
143
121
  it "should set file permission to private" do
144
- setup_expectations public_access: false
122
+ setup_create_object public: false
145
123
  Storage.store(source, name: "lorem.txt", bucket: "files", public: false)
146
124
  end
147
125
 
148
126
  it "should set file permission to private (access option)" do
149
- setup_expectations public_access: false
127
+ setup_create_object public: false
150
128
  Storage.store(source, name: "lorem.txt", bucket: "files", access: :private)
151
129
  end
152
130
 
153
131
  it "should set file permission to public (access option)" do
154
- setup_expectations public_access: true
132
+ setup_create_object public: true
155
133
  Storage.store(source, name: "lorem.txt", bucket: "files", access: :public_read)
156
134
  end
157
135
 
158
- def setup_bucket(bucket)
136
+ def setup_create_object(bucket: self.bucket, object: nil, public: false, file_name: "lorem.txt")
159
137
  allow(connection).to receive_message_chain("directories.get").with("files").and_return(bucket)
138
+ expect(bucket).to receive_message_chain("files.create").with(key: file_name, body: kind_of(File), public: public)
160
139
  end
161
140
 
162
- def setup_object(object = nil)
163
- expect(adapter).to receive_message_chain("find_object").and_return(object)
141
+ def setup_get_object(bucket: self.bucket, file_name: "lorem.txt", object: nil)
142
+ expect(connection).to receive_message_chain("directories.get").with("files").and_return(bucket)
143
+ expect(bucket).to receive_message_chain("files.get").with(file_name).and_return(object)
164
144
  end
165
145
 
166
- def setup_create(public_access)
167
- expect(bucket).to receive_message_chain("files.create").with(key: "lorem.txt", body: kind_of(File), public: public_access)
168
- end
169
-
170
- def setup_get(object)
171
- expect(bucket).to receive_message_chain("files.get").with("lorem.txt").and_return(object)
146
+ def setup_create_bucket(bucket: nil)
147
+ allow(connection).to receive_message_chain("directories.get").with("files").and_return(bucket)
148
+ expect(connection).to receive_message_chain("directories.create").with(key: "files", public: false).and_return(self.bucket)
172
149
  end
173
150
 
174
- def setup_expectations(the_bucket: bucket, object: nil, public_access: false)
175
- setup_bucket(the_bucket)
176
- setup_object(object)
177
- setup_create(public_access)
151
+ def setup_get_bucket(bucket: self.bucket)
152
+ allow(connection).to receive_message_chain("directories.get").with("files").and_return(bucket)
178
153
  end
179
154
  end
180
155
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira