Class: Cumulus::S3::LifecycleConfig
- Inherits:
-
Object
- Object
- Cumulus::S3::LifecycleConfig
- Defined in:
- lib/s3/models/LifecycleConfig.rb
Instance Attribute Summary collapse
-
#days_until_delete ⇒ Object
readonly
Returns the value of attribute days_until_delete.
-
#days_until_glacier ⇒ Object
readonly
Returns the value of attribute days_until_glacier.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#past_days_until_delete ⇒ Object
readonly
Returns the value of attribute past_days_until_delete.
-
#past_days_until_glacier ⇒ Object
readonly
Returns the value of attribute past_days_until_glacier.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#!=(other) ⇒ Object
Public: Check if this LifecycleConfig is not equal to the other object.
-
#==(other) ⇒ Object
Public: Check LifecycleConfig equality with other objects.
-
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS.
-
#initialize(json = nil) ⇒ LifecycleConfig
constructor
Public: Constructor.
-
#populate!(aws) ⇒ Object
Public: Populate this LifecycleConfig with the values in an AWS Configuration object.
-
#to_aws ⇒ Object
Public: Produce an AWS hash representing this LifecycleConfig.
-
#to_h ⇒ Object
Public: Converts this LifecycleConfig to a hash that matches Cumulus configuration.
Constructor Details
#initialize(json = nil) ⇒ LifecycleConfig
Public: Constructor
json - a hash representing the JSON configuration. Expects to be passed
an object from the "lifecycle" array of S3 bucket configuration.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/s3/models/LifecycleConfig.rb', line 17 def initialize(json = nil) if json @name = json["name"] @prefix = json["prefix"] @days_until_glacier = json["days-until-glacier"] @days_until_delete = json["days-until-delete"] if json["past-versions"] @past_days_until_glacier = json["past-versions"]["days-until-glacier"] @past_days_until_delete = json["past-versions"]["days-until-delete"] end end end |
Instance Attribute Details
#days_until_delete ⇒ Object (readonly)
Returns the value of attribute days_until_delete.
9 10 11 |
# File 'lib/s3/models/LifecycleConfig.rb', line 9 def days_until_delete @days_until_delete end |
#days_until_glacier ⇒ Object (readonly)
Returns the value of attribute days_until_glacier.
8 9 10 |
# File 'lib/s3/models/LifecycleConfig.rb', line 8 def days_until_glacier @days_until_glacier end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/s3/models/LifecycleConfig.rb', line 6 def name @name end |
#past_days_until_delete ⇒ Object (readonly)
Returns the value of attribute past_days_until_delete.
11 12 13 |
# File 'lib/s3/models/LifecycleConfig.rb', line 11 def past_days_until_delete @past_days_until_delete end |
#past_days_until_glacier ⇒ Object (readonly)
Returns the value of attribute past_days_until_glacier.
10 11 12 |
# File 'lib/s3/models/LifecycleConfig.rb', line 10 def past_days_until_glacier @past_days_until_glacier end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
7 8 9 |
# File 'lib/s3/models/LifecycleConfig.rb', line 7 def prefix @prefix end |
Instance Method Details
#!=(other) ⇒ Object
Public: Check if this LifecycleConfig is not equal to the other object
other - the other object to check
Returns whether this LifecycleConfig is not equal to ‘other`
137 138 139 |
# File 'lib/s3/models/LifecycleConfig.rb', line 137 def !=(other) !(self == other) end |
#==(other) ⇒ Object
Public: Check LifecycleConfig equality with other objects.
other - the other object to check
Returns whether this LifecycleConfig is equal to ‘other`
118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/s3/models/LifecycleConfig.rb', line 118 def ==(other) if !other.is_a? LifecycleConfig or @name != other.name or @prefix != other.prefix or @days_until_glacier != other.days_until_glacier or @days_until_delete != other.days_until_delete or @past_days_until_glacier != other.past_days_until_glacier or @past_days_until_delete != other.past_days_until_delete false else true end end |
#diff(aws) ⇒ Object
Public: Produce an array of differences between this local configuration and the configuration in AWS
aws - the AWS resource
Returns an array of LifecycleDiffs that were found
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/s3/models/LifecycleConfig.rb', line 91 def diff(aws) diffs = [] if @prefix != aws.prefix diffs << LifecycleDiff.new(LifecycleChange::PREFIX, aws, self) end if @days_until_glacier != aws.days_until_glacier diffs << LifecycleDiff.new(LifecycleChange::DAYS_UNTIL_GLACIER, aws, self) end if @days_until_delete != aws.days_until_delete diffs << LifecycleDiff.new(LifecycleChange::DAYS_UNTIL_DELETE, aws, self) end if @past_days_until_glacier != aws.past_days_until_glacier diffs << LifecycleDiff.new(LifecycleChange::PAST_UNTIL_GLACIER, aws, self) end if @past_days_until_delete != aws.past_days_until_delete diffs << LifecycleDiff.new(LifecycleChange::PAST_UNTIL_DELETE, aws, self) end diffs end |
#populate!(aws) ⇒ Object
Public: Populate this LifecycleConfig with the values in an AWS Configuration object.
aws - the aws object to populate from
34 35 36 37 38 39 40 41 |
# File 'lib/s3/models/LifecycleConfig.rb', line 34 def populate!(aws) @name = aws.id @prefix = aws.prefix @days_until_glacier = (aws.transition.days unless aws.transition.storage_class.downcase != "glacier") rescue nil @days_until_delete = aws.expiration.days rescue nil @past_days_until_glacier = (aws.noncurrent_version_transition.noncurrent_days unless aws.noncurrent_version_transition.storage_class.downcase != "glacier") rescue nil @past_days_until_delete = aws.noncurrent_version_expiration.noncurrent_days rescue nil end |
#to_aws ⇒ Object
Public: Produce an AWS hash representing this LifecycleConfig.
Returns the hash.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/s3/models/LifecycleConfig.rb', line 46 def to_aws { id: @name, prefix: @prefix, status: "Enabled", transition: if @days_until_glacier then { days: @days_until_glacier, storage_class: "GLACIER" } end, expiration: if @days_until_delete then { days: @days_until_delete } end, noncurrent_version_transition: if @past_days_until_glacier then { noncurrent_days: @past_days_until_glacier, storage_class: "GLACIER" } end, noncurrent_version_expiration: if @past_days_until_delete then { noncurrent_days: @past_days_until_delete } end }.reject { |k, v| v.nil? } end |
#to_h ⇒ Object
Public: Converts this LifecycleConfig to a hash that matches Cumulus configuration.
Returns the hash.
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/s3/models/LifecycleConfig.rb', line 72 def to_h { "name" => @name, "prefix" => @prefix, "days-until-glacier" => @days_until_glacier, "days-until-delete" => @days_until_delete, "past-versions" => if @past_days_until_glacier or @past_days_until_delete then { "days-until-glacier" => @past_days_until_glacier, "days-until-delete" => @past_days_until_delete, }.reject { |k, v| v.nil? } end, }.reject { |k, v| v.nil? } end |