better_s3 2.0.0 → 2.1.0
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.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/lib/better_s3.rb +8 -3
- data/lib/better_s3/version.rb +2 -2
- data/spec/better_s3_spec.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f353fe83d9250c3710846877955af0f93bdc7184
|
4
|
+
data.tar.gz: 1fec7d76a7d13ae820770605905c97a7e1a2a883
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 218978aa776f7d86410bfe901ec9ea90e6b4db55b550208f40b0c08daf937cf1ea944e86c214a5464e9128dbe133aa6aea9927d6e78981f2bb59bbfb73bdf45c
|
7
|
+
data.tar.gz: 1e3bc8c17d16771e4b64333657eee2209eb90549f296f8d65cdf2c33a2172fd1673fd25c2436bb4cb0e68f3b01248d90be5adeb55a2ed6cc9b9f4c317d124467
|
data/README.md
CHANGED
@@ -32,6 +32,26 @@ content = { foo: "bar" }.to_json
|
|
32
32
|
s3.put "filename.ext", content
|
33
33
|
```
|
34
34
|
|
35
|
+
## Override the client's bucket name
|
36
|
+
|
37
|
+
If you need to change buckets, you don't have to create a new client or
|
38
|
+
modify the configuration.
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
require "better_s3"
|
42
|
+
BetterS3.configure do |c|
|
43
|
+
c.bucket = "bucketname"
|
44
|
+
end
|
45
|
+
s3 = BetterS3.new
|
46
|
+
s3.bucket
|
47
|
+
=> "bucketname"
|
48
|
+
s3.bucket = "otherbucket"
|
49
|
+
s3.bucket
|
50
|
+
=> "otherbucket"
|
51
|
+
BetterS3.configuration.bucket
|
52
|
+
=> "bucketname"
|
53
|
+
```
|
54
|
+
|
35
55
|
## Configuration
|
36
56
|
|
37
57
|
To configure BetterS3 use the configuration block pattern
|
data/lib/better_s3.rb
CHANGED
@@ -33,7 +33,12 @@ class BetterS3
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
attr_accessor :s3, :_payload_body, :file_copied
|
36
|
+
attr_accessor :s3, :_payload_body, :file_copied, :bucket
|
37
|
+
|
38
|
+
def initialize
|
39
|
+
@bucket = BetterS3.configuration.bucket
|
40
|
+
end
|
41
|
+
|
37
42
|
def s3
|
38
43
|
@s3 ||= Aws::S3::Client.new
|
39
44
|
end
|
@@ -69,13 +74,13 @@ class BetterS3
|
|
69
74
|
# @param hsh [String] the content to be put into s3 (it really should be JSON)
|
70
75
|
# @param remote_file_name [String] the s3 bucket object key where the file should be put
|
71
76
|
def push_object_to_s3(hsh, remote_file_name)
|
72
|
-
s3.put_object(bucket:
|
77
|
+
s3.put_object(bucket: bucket.to_s,
|
73
78
|
key: remote_file_name.to_s,
|
74
79
|
body: hsh)
|
75
80
|
end
|
76
81
|
|
77
82
|
def copy_file_from_s3(remote_file_name)
|
78
|
-
s3.get_object({ bucket:
|
83
|
+
s3.get_object({ bucket: bucket.to_s, key: remote_file_name.to_s },
|
79
84
|
target: full_file_path(remote_file_name))
|
80
85
|
@file_copied = true
|
81
86
|
end
|
data/lib/better_s3/version.rb
CHANGED
data/spec/better_s3_spec.rb
CHANGED
@@ -66,4 +66,32 @@ describe BetterS3 do
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
describe "#bucket" do
|
71
|
+
before do
|
72
|
+
BetterS3.configure do |c|
|
73
|
+
c.bucket = "mybucketwithahole"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
it "is the current bucket name" do
|
77
|
+
expect(subject.bucket).to eq "mybucketwithahole"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#bucket=" do
|
82
|
+
before do
|
83
|
+
BetterS3.configure do |c|
|
84
|
+
c.bucket = "mybucketwithahole"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
it "sets the client's bucket name" do
|
88
|
+
subject.bucket = "otherbucket"
|
89
|
+
expect(subject.bucket).to eq "otherbucket"
|
90
|
+
end
|
91
|
+
|
92
|
+
it "leaves the configuration unmodified" do
|
93
|
+
subject.bucket = "otherbucket"
|
94
|
+
expect(BetterS3.configuration.bucket).to eq "mybucketwithahole"
|
95
|
+
end
|
96
|
+
end
|
69
97
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: better_s3
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Courtland Caldwell
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: aws-sdk
|