archived_remote_object 0.1.4 → 0.1.5

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
  SHA256:
3
- metadata.gz: 874166646dc4caa8cd18e73fb3b6e53857254d167c2b3f828d5e06249e0e9768
4
- data.tar.gz: 0342b78ce8efcf8ef6890f19a8491b07ce5d1bc089d3469128648259d89f0ec8
3
+ metadata.gz: b0210c27f442830b091c1849865ace9a29e961fea290e953e85e3315458e774a
4
+ data.tar.gz: 3024af7b02b867cb3a56f752a4cc714a0d457965a6c9737b6edd5dd2cd880be9
5
5
  SHA512:
6
- metadata.gz: 547d157c47e88690dedff50673bd141482fe1aaaea633438d707926b552720104bd87abfa065209d627613f189aa251002196a64e8c44b8356633a8d45e721a1
7
- data.tar.gz: 000c463560bb10a6e85c83db25de9c251b9b5b4ef85b291cf1438aab45a2a3ac9fece985ae1df7fc74ef76cf134d95cf0d7e91b230aa5fcc50828a0e8c09227c
6
+ metadata.gz: eefb9c00c28a82b6f3722f52daa39e0edb6b0aee1fe6d652a3f091c003ccb56de792efd4f7821b901f9e7b41da84c95b905570d29e06529cdfa3ba248f88b1e5
7
+ data.tar.gz: 33eacea6fee046f83957d2fb8d79dbc0bf4456173a566f4cc062b1f8e789cdcb985f00d19de3e30d34e610e8a2db0e2153fa5a4f0834129f12c7d9545e5b82a1
@@ -7,7 +7,7 @@ module ArchivedRemoteObject
7
7
 
8
8
  def initialize
9
9
  self.s3_client = Aws::S3::Client.new(
10
- stub_responses: stubbed?,
10
+ stub_responses: stub_enabled?,
11
11
  region: ArchivedRemoteObject.configuration.aws_region,
12
12
  credentials: Aws::Credentials.new(
13
13
  ArchivedRemoteObject.configuration.aws_access_key_id,
@@ -17,7 +17,7 @@ module ArchivedRemoteObject
17
17
  end
18
18
 
19
19
  def fetch_object_data(key:, stubbed_response: {})
20
- if stubbed?
20
+ if stub_enabled? && !stubbed?(:head_object)
21
21
  response = {
22
22
  storage_class: "DEEP_ARCHIVE",
23
23
  restore: nil,
@@ -29,34 +29,44 @@ module ArchivedRemoteObject
29
29
  end
30
30
 
31
31
  def restore(key:, duration:)
32
- s3_client.stub_responses(:restore_object) if stubbed?
32
+ s3_client.stub_responses(:restore_object) if stub_enabled? && !stubbed?(:restore_object)
33
33
  s3_client.restore_object(bucket: bucket, key: key, restore_request: { days: duration })
34
34
  end
35
35
 
36
36
  def assign_tag(key:, set:)
37
- s3_client.stub_responses(:put_object_tagging) if stubbed?
37
+ s3_client.stub_responses(:put_object_tagging) if stub_enabled? && !stubbed?(:put_object_tagging)
38
38
  s3_client.put_object_tagging(bucket: bucket, key: key, tagging: { tag_set: [{ key: set[0], value: set[1] }] })
39
39
  end
40
40
 
41
41
  def assign_storage_class(key:, storage_class:)
42
- s3_client.stub_responses(:copy_object) if stubbed?
42
+ s3_client.stub_responses(:copy_object) if stub_enabled? && !stubbed?(:copy_object)
43
43
  s3_client.copy_object(bucket: bucket, key: key, copy_source: "#{bucket}/#{key}", storage_class: storage_class)
44
44
  end
45
45
 
46
46
  def delete(key:)
47
- s3_client.stub_responses(:delete_object) if stubbed?
47
+ s3_client.stub_responses(:delete_object) if stub_enabled? && !stubbed?(:delete_object)
48
48
  s3_client.delete_object(bucket: bucket, key: key)
49
49
  end
50
50
 
51
+ def exists?(key:)
52
+ !!fetch_object_data(key: key)
53
+ rescue Aws::S3::Errors::NotFound
54
+ false
55
+ end
56
+
51
57
  private
52
58
 
53
59
  def bucket
54
60
  ArchivedRemoteObject.configuration.aws_bucket
55
61
  end
56
62
 
57
- def stubbed?
63
+ def stub_enabled?
58
64
  ArchivedRemoteObject.configuration.stub_client_requests
59
65
  end
66
+
67
+ def stubbed?(key)
68
+ !!s3_client.instance_variable_get('@stubs').fetch(key, nil)
69
+ end
60
70
  end
61
71
  end
62
72
  end
@@ -36,6 +36,10 @@ module ArchivedRemoteObject
36
36
  remote_client.delete(key: key)
37
37
  end
38
38
 
39
+ def exists?
40
+ remote_client.exists?(key: key)
41
+ end
42
+
39
43
  def sync
40
44
  tap { fetch_attributes }
41
45
  end
@@ -1,3 +1,3 @@
1
1
  module ArchivedRemoteObject
2
- VERSION = "0.1.4".freeze
2
+ VERSION = "0.1.5".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: archived_remote_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aleksey Strizhak