Class: CycloneLariat::Resources::Topic
- Inherits:
-
Object
- Object
- CycloneLariat::Resources::Topic
- Defined in:
- lib/cyclone_lariat/resources/topic.rb
Constant Summary collapse
- SNS_SUFFIX =
:fanout
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
-
#content_based_deduplication ⇒ Object
readonly
Returns the value of attribute content_based_deduplication.
-
#fifo ⇒ Object
readonly
Returns the value of attribute fifo.
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#publisher ⇒ Object
readonly
Returns the value of attribute publisher.
-
#region ⇒ Object
readonly
Returns the value of attribute region.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #arn ⇒ Object
- #attributes ⇒ Object
- #custom? ⇒ Boolean
-
#initialize(instance:, kind:, region:, account_id:, publisher:, type:, fifo:, content_based_deduplication: nil, tags: nil, name: nil) ⇒ Topic
constructor
A new instance of Topic.
- #name ⇒ Object (also: #to_s)
- #protocol ⇒ Object
- #queue? ⇒ Boolean
- #standard? ⇒ Boolean
- #tags ⇒ Object
- #topic? ⇒ Boolean
Constructor Details
#initialize(instance:, kind:, region:, account_id:, publisher:, type:, fifo:, content_based_deduplication: nil, tags: nil, name: nil) ⇒ Topic
Returns a new instance of Topic.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 10 def initialize(instance:, kind:, region:, account_id:, publisher:, type:, fifo:, content_based_deduplication: nil, tags: nil, name: nil) @instance = instance @kind = kind @region = region @account_id = account_id @publisher = publisher @type = type @fifo = fifo @tags = @name = name @content_based_deduplication = content_based_deduplication end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
8 9 10 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 8 def account_id @account_id end |
#content_based_deduplication ⇒ Object (readonly)
Returns the value of attribute content_based_deduplication.
8 9 10 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 8 def content_based_deduplication @content_based_deduplication end |
#fifo ⇒ Object (readonly)
Returns the value of attribute fifo.
8 9 10 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 8 def fifo @fifo end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
8 9 10 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 8 def instance @instance end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
8 9 10 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 8 def kind @kind end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
8 9 10 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 8 def publisher @publisher end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
8 9 10 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 8 def region @region end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 8 def type @type end |
Class Method Details
.from_arn(arn) ⇒ Object
100 101 102 103 104 105 106 107 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 100 def from_arn(arn) arn_array = arn.split(':') raise ArgumentError, 'Arn should consists `arn`' unless arn_array[0] == 'arn' raise ArgumentError, 'Arn should consists `aws`' unless arn_array[1] == 'aws' raise ArgumentError, 'Arn should consists `sns`' unless arn_array[2] == 'sns' from_name(arn_array[5], region: arn_array[3], account_id: arn_array[4]) end |
.from_name(name, region:, account_id:) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 71 def from_name(name, region:, account_id:) is_fifo_array = name.split('.') full_name = is_fifo_array[0] fifo_suffix = is_fifo_array[-1] suffix_exists = fifo_suffix != full_name if suffix_exists && fifo_suffix != 'fifo' raise ArgumentError, "Topic name #{name} consists unexpected suffix #{fifo_suffix}" end fifo = suffix_exists topic_array = full_name.split('-') raise ArgumentError, "Topic name should consists `#{SNS_SUFFIX}`" unless topic_array[2] != SNS_SUFFIX topic_array.clear if topic_array.size < 5 new( instance: topic_array[0], kind: topic_array[1], publisher: topic_array[3], type: topic_array[4], region: region, account_id: account_id, fifo: fifo, name: name ) end |
Instance Method Details
#==(other) ⇒ Object
66 67 68 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 66 def ==(other) arn == other.arn end |
#arn ⇒ Object
23 24 25 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 23 def arn ['arn', 'aws', 'sns', region, account_id, to_s].join ':' end |
#attributes ⇒ Object
45 46 47 48 49 50 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 45 def attributes attrs = {} attrs['FifoTopic'] = 'true' if fifo attrs['ContentBasedDeduplication'] = 'true' if content_based_deduplication attrs end |
#custom? ⇒ Boolean
27 28 29 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 27 def custom? !standard? end |
#name ⇒ Object Also known as: to_s
37 38 39 40 41 42 43 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 37 def name @name ||= begin name = [instance, kind, SNS_SUFFIX, publisher, type].compact.join '-' name += '.fifo' if fifo name end end |
#protocol ⇒ Object
60 61 62 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 60 def protocol 'sns' end |
#queue? ⇒ Boolean
56 57 58 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 56 def queue? false end |
#standard? ⇒ Boolean
31 32 33 34 35 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 31 def standard? return false unless instance && kind && publisher && type true end |
#tags ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 110 def @tags ||= begin if standard? [ { key: 'standard', value: 'true' }, { key: 'instance', value: String(instance) }, { key: 'kind', value: String(kind) }, { key: 'publisher', value: String(publisher) }, { key: 'type', value: String(type) }, { key: 'fifo', value: fifo ? 'true' : 'false' } ] else [ { key: 'standard', value: 'false' }, { key: 'name', value: String(name) }, { key: 'fifo', value: fifo ? 'true' : 'false' } ] end end end |
#topic? ⇒ Boolean
52 53 54 |
# File 'lib/cyclone_lariat/resources/topic.rb', line 52 def topic? true end |