alephant-storage 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/alephant/storage.rb +16 -6
- data/lib/alephant/storage/version.rb +1 -1
- data/spec/storage_spec.rb +11 -7
- 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: 8fccd9b0f5a266058512868d06792602434af812
|
4
|
+
data.tar.gz: 04b8c2837df0bd8513daf831a1c66b8da416650e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26b873e444f04b127ec94294a03598a97dc2b49388e7956b7a846deeadca1f60e65fc877f762d57ff4a24b118acc829b60782f61557dd534dc362450d7bbea16
|
7
|
+
data.tar.gz: d175c2e061929702060d5bcae794c502d0e510adc4f59cc16e54973a1b719fa1823cca5482a094565a2565efdeb938198524efdd32bc31aec8296f5c2dbfd963
|
data/lib/alephant/storage.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "alephant/storage/version"
|
2
|
+
require "alephant/logger"
|
3
|
+
require "aws-sdk"
|
4
|
+
require "date"
|
4
5
|
|
5
6
|
module Alephant
|
6
7
|
class Storage
|
@@ -16,7 +17,7 @@ module Alephant
|
|
16
17
|
"event" => "StorageInitialized",
|
17
18
|
"id" => id,
|
18
19
|
"path" => path,
|
19
|
-
"method" => "#{self.class}#initialize"
|
20
|
+
"method" => "#{self.class}#initialize"
|
20
21
|
)
|
21
22
|
end
|
22
23
|
|
@@ -29,7 +30,7 @@ module Alephant
|
|
29
30
|
)
|
30
31
|
end
|
31
32
|
|
32
|
-
def put(id, data, content_type =
|
33
|
+
def put(id, data, content_type = "text/plain", meta = {})
|
33
34
|
bucket.objects["#{path}/#{id}"].write(
|
34
35
|
data,
|
35
36
|
{
|
@@ -51,7 +52,7 @@ module Alephant
|
|
51
52
|
object = bucket.objects["#{path}/#{id}"]
|
52
53
|
content = object.read
|
53
54
|
content_type = object.content_type
|
54
|
-
meta_data = object.metadata.to_h
|
55
|
+
meta_data = object.metadata.to_h.merge(add_custom_meta(object))
|
55
56
|
|
56
57
|
logger.metric "StorageGets"
|
57
58
|
logger.info(
|
@@ -69,5 +70,14 @@ module Alephant
|
|
69
70
|
:meta => meta_data
|
70
71
|
}
|
71
72
|
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
def add_custom_meta(object)
|
77
|
+
{
|
78
|
+
:head_ETag => object.etag,
|
79
|
+
:"head_Last-Modified" => DateTime.parse(object.last_modified).httpdate
|
80
|
+
}
|
81
|
+
end
|
72
82
|
end
|
73
83
|
end
|
data/spec/storage_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require
|
2
|
-
require 'pry'
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Alephant::Storage do
|
5
4
|
let(:id) { :id }
|
@@ -60,7 +59,7 @@ describe Alephant::Storage do
|
|
60
59
|
expect_any_instance_of(AWS::S3).to receive(:buckets).and_return({ id => s3_bucket })
|
61
60
|
instance = subject.new(id, path)
|
62
61
|
|
63
|
-
instance.put(id, data,
|
62
|
+
instance.put(id, data, "foo/bar")
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
@@ -68,8 +67,10 @@ describe Alephant::Storage do
|
|
68
67
|
it "gets bucket path/id content data" do
|
69
68
|
s3_object_collection = double()
|
70
69
|
expect(s3_object_collection).to receive(:read).and_return("content")
|
71
|
-
expect(s3_object_collection).to receive(:content_type).and_return("foo/bar")
|
72
|
-
expect(s3_object_collection).to receive(:metadata).and_return({ :foo => :bar})
|
70
|
+
expect(s3_object_collection).to receive(:content_type).and_return("foo/bar" )
|
71
|
+
expect(s3_object_collection).to receive(:metadata).and_return({ :foo => :bar })
|
72
|
+
expect(s3_object_collection).to receive(:etag).and_return("foo_123")
|
73
|
+
expect(s3_object_collection).to receive(:last_modified).and_return("2016-04-11 10:39:57 +0000")
|
73
74
|
|
74
75
|
s3_bucket = double()
|
75
76
|
expect(s3_bucket).to receive(:objects).and_return(
|
@@ -86,11 +87,14 @@ describe Alephant::Storage do
|
|
86
87
|
expected_hash = {
|
87
88
|
:content => "content",
|
88
89
|
:content_type => "foo/bar",
|
89
|
-
:meta => {
|
90
|
+
:meta => {
|
91
|
+
:foo => :bar,
|
92
|
+
:head_ETag => "foo_123",
|
93
|
+
:"head_Last-Modified" => "Mon, 11 Apr 2016 10:39:57 GMT"
|
94
|
+
}
|
90
95
|
}
|
91
96
|
|
92
97
|
expect(object_hash).to eq(expected_hash)
|
93
98
|
end
|
94
99
|
end
|
95
100
|
end
|
96
|
-
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- BBC News
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|