echo_uploads 0.0.6 → 0.0.7

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: 1d98d216e5f8935292fe62e093dec3a81bc9099b
4
- data.tar.gz: 4ae8d8d9f0e74121a88b8e4b12a860902259adb2
3
+ metadata.gz: 75454542bb29646f3b17fd5d72d86a1d6e8802ab
4
+ data.tar.gz: 9fd264f1b0e217f776afd90820ad68d2db645306
5
5
  SHA512:
6
- metadata.gz: fbc8a9e235934a44f4ff7cf68f1cabcf61871fd4ee604ff8a67a25f8176341d65d087d4abedbfa49625eaf5ad87b97ac405896cc6e94f862a7187fa5ed21c63c
7
- data.tar.gz: cb0240f8cb5372d336b99fb235c43ea599e38f623404880b75f3d88d50acc601334c1d513de6c123ace6acd6b9d85f1608e7ca1817ce4f562543f3adfdf86587
6
+ metadata.gz: 8526cdc620a6311028ac8a54a509b38d78058e93f226d7c32a89470a620ef0edd38f419b54fa57a9611a7157171e90070fa3b04392d0f6254457d5017207278b
7
+ data.tar.gz: 0f44dea04658d84809108fb9edde1f45c2d6a4860f060b9f2f305de25b5962c5ab5b5511ea9706cb6ddd38949f1283866ccb8ee7acd1bc2401ae3c3ec1b4324a
@@ -111,6 +111,10 @@ module EchoUploads
111
111
  end
112
112
  end
113
113
 
114
+ def read
115
+ storage.read key
116
+ end
117
+
114
118
  def storage
115
119
  class_from_string(storage_type).new
116
120
  end
@@ -18,7 +18,7 @@ module EchoUploads
18
18
  end
19
19
 
20
20
  def read(key)
21
- File.read path(key)
21
+ ::File.read path(key)
22
22
  end
23
23
 
24
24
  def write(key, file)
@@ -178,6 +178,12 @@ module EchoUploads
178
178
  send("#{attr}_tmp_metadata").present?
179
179
  end
180
180
 
181
+ # Define the read_x method. Delegates to the #read method of the store (e.g.
182
+ # FilesystemStore).
183
+ define_method("read_#{attr}") do
184
+ echo_uploads_map_metadata(attr, options, &:read)
185
+ end
186
+
181
187
  # Define the association with the metadata model.
182
188
  if options[:multiple]
183
189
  has_many("#{attr}_metadatas".to_sym,
@@ -3,26 +3,27 @@
3
3
  module EchoUploads
4
4
  class S3Store < ::EchoUploads::AbstractStore
5
5
  def delete(key)
6
- bucket.objects[key].delete
6
+ bucket.objects[path(key)].delete
7
7
  end
8
8
 
9
9
  def exists?(key)
10
- bucket.objects[key].exists?
10
+ bucket.objects[path(key)].exists?
11
11
  end
12
12
 
13
13
  def read(key)
14
14
  data = ''
15
- bucket.objects[key].read { |chunk| data << chunk }
15
+ bucket.objects[path(key)].read { |chunk| data << chunk }
16
16
  data
17
17
  end
18
18
 
19
19
  def url(key, options = {})
20
20
  options = {method: :read}.merge(options)
21
- bucket.objects[key].url_for options.delete(:method), options
21
+ bucket.objects[path(key)].url_for options.delete(:method), options
22
22
  end
23
23
 
24
24
  def write(key, file)
25
- bucket.objects[key].write file
25
+ file.rewind
26
+ bucket.objects[path(key)].write file
26
27
  end
27
28
 
28
29
  private
@@ -43,9 +44,15 @@ module EchoUploads
43
44
  end
44
45
 
45
46
  def folder
46
- Rails.configuration.echo_uploads.s3.folder || raise(
47
- 'You must define config.echo_uploads.s3.folder in your application config.'
48
- )
47
+ if Rails.configuration.respond_to?(:echo_uploads) and Rails.configuration.echo_uploads.s3.folder
48
+ Rails.configuration.echo_uploads.s3.folder
49
+ else
50
+ ::File.join 'echo_uploads', Rails.env
51
+ end
52
+ end
53
+
54
+ def path(key)
55
+ ::File.join folder, key
49
56
  end
50
57
  end
51
58
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: echo_uploads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarrett Colby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-04 00:00:00.000000000 Z
11
+ date: 2014-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mime-types