Class: CycloneLariat::Resources::Queue
- Inherits:
-
Object
- Object
- CycloneLariat::Resources::Queue
- Defined in:
- lib/cyclone_lariat/resources/queue.rb
Constant Summary collapse
- SNS_SUFFIX =
:queue
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.
-
#dest ⇒ Object
readonly
Returns the value of attribute dest.
-
#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
- .from_arn(arn) ⇒ Object
-
.from_name(name, region:, account_id:) ⇒ Object
Name example: test-event-queue-cyclone_lariat-note_added.fifo instance: teste kind: event publisher: cyclone_lariat type: note_added dest: nil fifo: true.
-
.from_url(url) ⇒ Object
URL example: sqs.eu-west-1.amazonaws.com/247606935658/test-event-queue-cyclone_lariat-note_added.fifo url_array => https host_array => sqs host_array => eu-west-1 url_array => 247606935658 # account_id url_array => test-event-queue-cyclone_lariat-note_added.fifo # name.
Instance Method Summary collapse
- #arn ⇒ Object
- #attributes ⇒ Object
- #custom? ⇒ Boolean
-
#initialize(instance:, kind:, region:, dest:, account_id:, publisher:, type:, fifo:, content_based_deduplication: nil, tags: nil, name: nil) ⇒ Queue
constructor
A new instance of Queue.
- #name ⇒ Object (also: #to_s)
- #protocol ⇒ Object
- #queue? ⇒ Boolean
- #standard? ⇒ Boolean
- #tags ⇒ Object
- #topic? ⇒ Boolean
- #url ⇒ Object
Constructor Details
#initialize(instance:, kind:, region:, dest:, account_id:, publisher:, type:, fifo:, content_based_deduplication: nil, tags: nil, name: nil) ⇒ Queue
Returns a new instance of Queue.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 12 def initialize(instance:, kind:, region:, dest:, account_id:, publisher:, type:, fifo:, content_based_deduplication: nil, tags: nil, name: nil) @instance = instance @kind = kind @region = region @dest = dest @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.
10 11 12 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 10 def account_id @account_id end |
#content_based_deduplication ⇒ Object (readonly)
Returns the value of attribute content_based_deduplication.
10 11 12 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 10 def content_based_deduplication @content_based_deduplication end |
#dest ⇒ Object (readonly)
Returns the value of attribute dest.
10 11 12 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 10 def dest @dest end |
#fifo ⇒ Object (readonly)
Returns the value of attribute fifo.
10 11 12 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 10 def fifo @fifo end |
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
10 11 12 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 10 def instance @instance end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
10 11 12 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 10 def kind @kind end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
10 11 12 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 10 def publisher @publisher end |
#region ⇒ Object (readonly)
Returns the value of attribute region.
10 11 12 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 10 def region @region end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
10 11 12 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 10 def type @type end |
Class Method Details
.from_arn(arn) ⇒ Object
133 134 135 136 137 138 139 140 141 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 133 def from_arn(arn) arn_array = arn.split(':') raise ArgumentError, "Arn `#{arn}` should consists `arn`" unless arn_array[0] == 'arn' raise ArgumentError, "Arn `#{arn}` should consists `aws`" unless arn_array[1] == 'aws' raise ArgumentError, "Arn `#{arn}` should consists `sqs`" unless arn_array[2] == 'sqs' from_name(arn_array[5], region: arn_array[3], account_id: arn_array[4]) end |
.from_name(name, region:, account_id:) ⇒ Object
Name example: test-event-queue-cyclone_lariat-note_added.fifo instance: teste kind: event publisher: cyclone_lariat type: note_added dest: nil fifo: true
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 83 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, "Queue name #{name} consists unexpected suffix #{fifo_suffix}" end fifo = suffix_exists queue_array = full_name.split('-') raise ArgumentError, "Topic name should consists `#{SNS_SUFFIX}`" unless queue_array[2] != SNS_SUFFIX queue_array.clear if queue_array.size < 5 new( instance: queue_array[0], kind: queue_array[1], region: region, dest: queue_array[5], account_id: account_id, publisher: queue_array[3], type: queue_array[4], fifo: fifo, name: name ) end |
.from_url(url) ⇒ Object
URL example: sqs.eu-west-1.amazonaws.com/247606935658/test-event-queue-cyclone_lariat-note_added.fifo url_array => https host_array => sqs host_array => eu-west-1 url_array => 247606935658 # account_id url_array => test-event-queue-cyclone_lariat-note_added.fifo # name
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 113 def from_url(url) raise ArgumentError, 'Url is not http format' unless url =~ URI::DEFAULT_PARSER.make_regexp url_array = url.split('/') raise ArgumentError, 'Url should start from https' unless url_array[0] == 'https:' host_array = url_array[2].split('.') raise ArgumentError, 'It is not queue url' unless host_array[0] == 'sqs' from_name(url_array[4], region: host_array[1], account_id: url_array[3]) end |
Instance Method Details
#arn ⇒ Object
26 27 28 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 26 def arn ['arn', 'aws', 'sqs', region, account_id, name].join ':' end |
#attributes ⇒ Object
67 68 69 70 71 72 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 67 def attributes attrs = {} attrs['FifoQueue'] = 'true' if fifo attrs['ContentBasedDeduplication'] = 'true' if content_based_deduplication attrs end |
#custom? ⇒ Boolean
37 38 39 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 37 def custom? !standard? end |
#name ⇒ Object Also known as: to_s
45 46 47 48 49 50 51 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 45 def name @name ||= begin name = [instance, kind, SNS_SUFFIX, publisher, type, dest].compact.join '-' name += '.fifo' if fifo name end end |
#protocol ⇒ Object
63 64 65 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 63 def protocol 'sqs' end |
#queue? ⇒ Boolean
59 60 61 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 59 def queue? true end |
#standard? ⇒ Boolean
41 42 43 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 41 def standard? instance && kind && publisher && type && true end |
#tags ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 144 def @tags ||= begin if standard? { 'standard' => 'true', 'instance' => String(instance), 'kind' => String(kind), 'publisher' => String(publisher), 'type' => String(type), 'dest' => dest ? String(dest) : 'undefined', 'fifo' => fifo ? 'true' : 'false' } else { 'standard' => 'false', 'name' => String(name), 'fifo' => fifo ? 'true' : 'false' } end end end |
#topic? ⇒ Boolean
55 56 57 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 55 def topic? false end |
#url ⇒ Object
Url example:
https://sqs.eu-west-1.amazonaws.com/247606935658/stage-event-queue
33 34 35 |
# File 'lib/cyclone_lariat/resources/queue.rb', line 33 def url "https://sqs.#{region}.amazonaws.com/#{account_id}/#{name}" end |