alephant-storage 1.0.1 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 889202b55e05eb45edf31c121184fee3e51835e6
4
- data.tar.gz: 5cef1b309ecf8f3771f59f853275b792416bb898
3
+ metadata.gz: 8fccd9b0f5a266058512868d06792602434af812
4
+ data.tar.gz: 04b8c2837df0bd8513daf831a1c66b8da416650e
5
5
  SHA512:
6
- metadata.gz: afe5c58169cb7f15526c21bf317670b4191c0458362f2bc4a5dbd314bce81eab2396b6e1bd57c295d2a9156d9ee306cb5d8c4ba25b0416af5a920415f805c75e
7
- data.tar.gz: 72a60b743f631a82b12841992859982bdc7187e3d98896120ff4021e30dc50e0d730ef31198b183e0fd62b068ee7a2d646b26b3e968494cb7bac7b12f897a331
6
+ metadata.gz: 26b873e444f04b127ec94294a03598a97dc2b49388e7956b7a846deeadca1f60e65fc877f762d57ff4a24b118acc829b60782f61557dd534dc362450d7bbea16
7
+ data.tar.gz: d175c2e061929702060d5bcae794c502d0e510adc4f59cc16e54973a1b719fa1823cca5482a094565a2565efdeb938198524efdd32bc31aec8296f5c2dbfd963
@@ -1,6 +1,7 @@
1
- require 'alephant/storage/version'
2
- require 'alephant/logger'
3
- require 'aws-sdk'
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 = 'text/plain', meta = {})
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
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  class Storage
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
data/spec/storage_spec.rb CHANGED
@@ -1,5 +1,4 @@
1
- require 'spec_helper'
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, 'foo/bar')
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 => { :foo => :bar }
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.1
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-03-16 00:00:00.000000000 Z
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