Class: Cumulus::SQS::DeadLetterConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/sqs/models/DeadLetterConfig.rb

Overview

Public: An object representing configuration for a queue’s dead letter options

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(json = nil) ⇒ DeadLetterConfig

Public: Constructor

json - a hash containing the JSON configuration for dead letter options



16
17
18
19
20
21
# File 'lib/sqs/models/DeadLetterConfig.rb', line 16

def initialize(json = nil)
  if !json.nil?
    @target = json["target"]
    @max_receives = json["max-receives"]
  end
end

Instance Attribute Details

#max_receivesObject (readonly)

Returns the value of attribute max_receives.



11
12
13
# File 'lib/sqs/models/DeadLetterConfig.rb', line 11

def max_receives
  @max_receives
end

#targetObject (readonly)

Returns the value of attribute target.



10
11
12
# File 'lib/sqs/models/DeadLetterConfig.rb', line 10

def target
  @target
end

Instance Method Details

#diff(aws) ⇒ Object

Public: Produce an array of differences between two DeadLetterConfig objects

aws - the DeadLetterConfig object built from aws config

Returns an array of the DeadLetterDiffs that were found



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/sqs/models/DeadLetterConfig.rb', line 54

def diff(aws)
  diffs = []

  if @target != aws.target
    diffs << DeadLetterDiff.new(DeadLetterChange::TARGET, aws.target, @target)
  end

  if @max_receives != aws.max_receives
    diffs << DeadLetterDiff.new(DeadLetterChange::RECEIVE, aws.max_receives, @max_receives)
  end

  diffs
end

#populate!(aws) ⇒ Object

Public: Populate a config object with AWS configuration

aws - the JSON string containing dead letter attributes in AWS



40
41
42
43
44
45
46
47
# File 'lib/sqs/models/DeadLetterConfig.rb', line 40

def populate!(aws)
  attributes = JSON.parse(URI.decode(aws))

  @target = SQS::queue_arns.key(attributes["deadLetterTargetArn"])
  @max_receives = if attributes["maxReceiveCount"] then attributes["maxReceiveCount"].to_i end

  self
end

#to_awsObject



30
31
32
33
34
35
# File 'lib/sqs/models/DeadLetterConfig.rb', line 30

def to_aws
  {
    "deadLetterTargetArn" => SQS::queue_arns[@target],
    "maxReceiveCount" => @max_receives
  }
end

#to_hashObject



23
24
25
26
27
28
# File 'lib/sqs/models/DeadLetterConfig.rb', line 23

def to_hash
  {
    "target" => @target,
    "max-receives" => @max_receives,
  }
end