attach-s3 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 444db1e1f183c9d4e7b28e2d3eeb7b69ee775889
4
+ data.tar.gz: 3a32f6f2749bd527afa329b70033d1c7e778d310
5
+ SHA512:
6
+ metadata.gz: de89ffba215503e66061d25b5f9ad68dceb7026b955e3410e190943c183854828799a849f4a2919f89d3ddb7d7cbd043f3a5d6d40b2d050d8c18af789ac7eb45
7
+ data.tar.gz: be5079db78c36b0787130dade4c08d4380085dd6012b60fcfd7793ac3a7718ffb671a8dbab425d14e712242a19cc70f51d7942316f1ce274abbe0c9fd63dc2ba
@@ -0,0 +1,7 @@
1
+ require "attach/s3/version"
2
+ require "attach/s3/backend"
3
+
4
+ module Attach
5
+ module S3
6
+ end
7
+ end
@@ -0,0 +1,48 @@
1
+ require 'fileutils'
2
+ require 'attach/backends/abstract'
3
+ require 'aws-sdk'
4
+
5
+ module Attach
6
+ module S3
7
+ class Backend < Attach::Backends::Abstract
8
+
9
+ def read(attachment)
10
+ s3 = setup_s3_request
11
+ path = path_for_attachment(attachment)
12
+
13
+ resp = s3.bucket(@config[:bucket]).object(path).get
14
+ resp.body.read
15
+ end
16
+
17
+ def write(attachment, data)
18
+ s3 = setup_s3_request
19
+ path = path_for_attachment(attachment)
20
+
21
+ s3.bucket(@config[:bucket]).object(path).put(body: attachment.binary)
22
+ end
23
+
24
+ def delete(attachment)
25
+ s3 = setup_s3_request
26
+ path = path_for_attachment(attachment)
27
+
28
+ s3.bucket(@config[:bucket]).object(path).delete
29
+ end
30
+
31
+ private
32
+
33
+ def setup_s3_request
34
+ Aws.config.update({
35
+ region: @config[:region],
36
+ credentials: Aws::Credentials.new(@config[:access_key], @config[:secret_access_key])
37
+ })
38
+
39
+ Aws::S3::Resource.new
40
+ end
41
+
42
+ def path_for_attachment(attachment)
43
+ ::File.join("attachments", attachment.token[0,2], attachment.token[2,2], attachment.token[4,40], attachment.file_name)
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ module Attach
2
+ module S3
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: attach-s3
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dean Perry
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: attach
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '2.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: aws-sdk
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.14'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.14'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ description: S3 backend module for the Attach gem
76
+ email:
77
+ - dean@voupe.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - lib/attach/s3.rb
83
+ - lib/attach/s3/backend.rb
84
+ - lib/attach/s3/version.rb
85
+ homepage: https://github.com/deanpcmad/attach-s3
86
+ licenses:
87
+ - MIT
88
+ metadata: {}
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 2.6.11
106
+ signing_key:
107
+ specification_version: 4
108
+ summary: S3 backend module for the Attach gem
109
+ test_files: []