echo_uploads 0.0.11 → 0.0.13

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: 363da8049a3d95db7e590c2680081788edcc1405
4
- data.tar.gz: da7c0bdef6ea0899b0087848437f4554d1361ee6
3
+ metadata.gz: a19cdd2aff5a28b347afebdf8935726149ef8843
4
+ data.tar.gz: c4889c53066a7d7864f88b1a0bf2753a24438c03
5
5
  SHA512:
6
- metadata.gz: 2fd7a6828ce9252148d1b4c9bf4020963aea88ebb6656832c1d54e6bf3a46f1eeddd8b9a59b7762fc5b35d6c5ab829e744295f845eb42fd75e186cc5251ce7d3
7
- data.tar.gz: a567d2d9ffb9e6e3da3ebe3225e4ce23faa56eebde9b0c67d8660592db8effd0f5d01afc1317f5b71f87ad6c2923b44aee4961bb8565fdc6ab86ff6fccab7061
6
+ metadata.gz: 9ab54bb35760568dc29cd84e6827c004b093adcdf2e9de2c6a180d4dfdf337b16ea9b432cd08cb01362596a8f2c248a9f64f1900b54dc7473c441a0412755de4
7
+ data.tar.gz: c3c9ea0f24c22092e1b5566c6b78d234caa9b469f65e44188a830fca18be19625f8f9d5b7073679239648048784ffc4756fbfb21193ef7250854e3511c15a339
data/lib/echo_uploads.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  module EchoUploads; end
2
2
 
3
+ require 'echo_uploads/version'
3
4
  require 'echo_uploads/railtie'
4
5
  require 'echo_uploads/validation'
5
6
  require 'echo_uploads/perm_file_saving'
@@ -85,9 +85,9 @@ module EchoUploads
85
85
  # EchoUploads::MappedFile, which is a subclass of
86
86
  # ActionDispatch::Http::UploadedFile.
87
87
  if file.is_a?(ActionDispatch::Http::UploadedFile)
88
- storage.write key, file.tempfile
88
+ storage.write key, file.tempfile, self
89
89
  else
90
- storage.write key, file
90
+ storage.write key, file, self
91
91
  end
92
92
 
93
93
  # If we mapped the files, they were temporarily written to tmp/echo_uploads.
@@ -21,7 +21,7 @@ module EchoUploads
21
21
  ::File.read path(key)
22
22
  end
23
23
 
24
- def write(key, file)
24
+ def write(key, file, metadata)
25
25
  _path = path key
26
26
  unless ::File.exists?(_path)
27
27
  unless ::File.exists?(folder)
@@ -1,46 +1,48 @@
1
1
  # Uses the official Amazon Web Services SDK gem:
2
2
  # gem install aws-sdk
3
+ # Incompatible with 1.x.x versions of the aws-sdk gem.
3
4
  module EchoUploads
4
5
  class S3Store < ::EchoUploads::AbstractStore
5
6
  def delete(key)
6
- bucket.objects[path(key)].delete
7
+ bucket.object(path(key)).delete
7
8
  end
8
9
 
9
10
  def exists?(key)
10
- bucket.objects[path(key)].exists?
11
+ bucket.object(path(key)).exists?
11
12
  end
12
13
 
13
14
  def read(key)
14
- data = ''
15
- bucket.objects[path(key)].read { |chunk| data << chunk }
16
- data
15
+ bucket.object(path(key)).get.body.read
17
16
  end
18
17
 
19
18
  def url(key, options = {})
20
- options = {method: :read}.merge(options)
21
- bucket.objects[path(key)].url_for options.delete(:method), options
19
+ options = {method: :get}.merge(options)
20
+ url_str = bucket.object(path(key)).presigned_url options.delete(:method), options
21
+ URI.parse url_str
22
22
  end
23
23
 
24
- def write(key, file)
24
+ def write(key, file, metadata)
25
25
  file.rewind
26
- bucket.objects[path(key)].write file
26
+ bucket.object(path(key)).put body: file, content_type: metadata.mime_type
27
27
  end
28
28
 
29
29
  private
30
30
 
31
+ def aws_config
32
+ Rails.configuration.echo_uploads.aws || {}
33
+ end
34
+
31
35
  def bucket
32
- if Rails.configuration.echo_uploads.aws
33
- s3 = AWS::S3.new Rails.configuration.echo_uploads.aws
34
- else
35
- s3 = AWS::S3.new
36
- end
37
- bucket_name = Rails.configuration.echo_uploads.s3.bucket || raise(
38
- 'You must define config.echo_uploads.s3.bucket in your application config.'
39
- )
40
- if s3.buckets[bucket_name].nil?
41
- s3.buckets.create bucket_name
36
+ if @bucket.nil?
37
+ bucket_name = Rails.configuration.echo_uploads.s3.bucket || raise(
38
+ 'You must define config.echo_uploads.s3.bucket in your application config.'
39
+ )
40
+ @bucket = Aws::S3::Bucket.new bucket_name, aws_config
41
+ unless @bucket.exists?
42
+ raise "S3 bucket does not exist: #{bucket_name.inspect}"
43
+ end
42
44
  end
43
- s3.buckets[bucket_name]
45
+ @bucket
44
46
  end
45
47
 
46
48
  def folder
@@ -0,0 +1,3 @@
1
+ module EchoUploads
2
+ VERSION = '0.0.13'
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: echo_uploads
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jarrett Colby
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: mime-types
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: turn
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +58,7 @@ files:
58
58
  - lib/echo_uploads/s3_store.rb
59
59
  - lib/echo_uploads/temp_file_saving.rb
60
60
  - lib/echo_uploads/validation.rb
61
+ - lib/echo_uploads/version.rb
61
62
  homepage: https://github.com/jarrett/echo_uploads
62
63
  licenses:
63
64
  - MIT