Class: S3AssetDeploy::RemovalManifest

Inherits:
Object
  • Object
show all
Defined in:
lib/s3_asset_deploy/removal_manifest.rb

Constant Summary collapse

PATH =
"s3-asset-deploy-removal-manifest.json".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket_name, s3_client_options: {}) ⇒ RemovalManifest

Returns a new instance of RemovalManifest.



8
9
10
11
12
13
14
15
16
17
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 8

def initialize(bucket_name, s3_client_options: {})
  @bucket_name = bucket_name
  @loaded = false
  @changed = false
  @manifest = {}
  @s3_client_options = {
    region: "us-east-1",
    logger: @logger
  }.merge(s3_client_options)
end

Instance Attribute Details

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



4
5
6
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 4

def bucket_name
  @bucket_name
end

Instance Method Details

#[](key) ⇒ Object



66
67
68
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 66

def [](key)
  @manifest[key]
end

#[]=(key, value) ⇒ Object



70
71
72
73
74
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 70

def []=(key, value)
  return unless loaded?
  @changed = true
  @manifest[key] = value
end

#changed?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 36

def changed?
  @changed
end

#delete(key) ⇒ Object



60
61
62
63
64
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 60

def delete(key)
  return unless loaded?
  @changed = true
  @manifest.delete(key)
end

#inspectObject



84
85
86
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 84

def inspect
  "#<#{self.class.name}:#{"0x0000%x" % (object_id << 1)} @bucket_name='#{bucket_name}'>"
end

#keysObject



56
57
58
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 56

def keys
  @manifest.keys
end

#loadObject



23
24
25
26
27
28
29
30
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 23

def load
  return true if loaded?
  @manifest = fetch_manifest
  @loaded = true
rescue Aws::S3::Errors::NoSuchKey
  @manifest = {}
  @loaded = true
end

#loaded?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 32

def loaded?
  @loaded
end

#s3Object



19
20
21
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 19

def s3
  @s3 ||= Aws::S3::Client.new(@s3_client_options)
end

#saveObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 40

def save
  return false unless loaded?
  return true unless changed?

  s3.put_object({
    bucket: bucket_name,
    key: PATH,
    body: @manifest.to_json,
    content_type: "application/json"
  })

  @changed = false

  true
end

#to_hObject



76
77
78
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 76

def to_h
  @manifest
end

#to_sObject



80
81
82
# File 'lib/s3_asset_deploy/removal_manifest.rb', line 80

def to_s
  @manifest.to_s
end