Class: SimpleMessageQueue::Notification::Topic
- Inherits:
-
Object
- Object
- SimpleMessageQueue::Notification::Topic
- Defined in:
- lib/simple_message_queue/notification.rb
Instance Attribute Summary collapse
-
#sns_topic ⇒ Object
readonly
Returns the value of attribute sns_topic.
Class Method Summary collapse
Instance Method Summary collapse
- #delete ⇒ Object
-
#initialize(name, generate_topic_name = true) ⇒ Topic
constructor
A new instance of Topic.
- #name ⇒ Object
- #send(message, subject = nil) ⇒ Object
- #sns ⇒ Object
Constructor Details
#initialize(name, generate_topic_name = true) ⇒ Topic
Returns a new instance of Topic.
44 45 46 47 48 49 50 |
# File 'lib/simple_message_queue/notification.rb', line 44 def initialize(name, generate_topic_name=true) raise SimpleMessageQueue::ConfigurationError unless SimpleMessageQueue.configuration raise SimpleMessageQueue::EnvironmentError unless defined?(SimpleMessageQueue.configuration.environment) topic_name = (generate_topic_name) ? self.class.topic_name(name) : name @sns_topic = sns.topics.create(topic_name) end |
Instance Attribute Details
#sns_topic ⇒ Object (readonly)
Returns the value of attribute sns_topic.
16 17 18 |
# File 'lib/simple_message_queue/notification.rb', line 16 def sns_topic @sns_topic end |
Class Method Details
.find(name) ⇒ Object
19 20 21 22 23 |
# File 'lib/simple_message_queue/notification.rb', line 19 def find(name) topic_name = topic_name(name) sns_topic = SimpleMessageQueue::Notification.sns.topics.find { |t| t.name == topic_name } topic = (sns_topic) ? Topic.new(sns_topic.name, false) : nil end |
.find_by_full_name(full_name) ⇒ Object
25 26 27 28 |
# File 'lib/simple_message_queue/notification.rb', line 25 def find_by_full_name(full_name) sns_topic = SimpleMessageQueue::Notification.sns.topics.find { |t| t.name == full_name } topic = (sns_topic) ? Topic.new(sns_topic.name, false) : nil end |
.topic_name(name) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/simple_message_queue/notification.rb', line 30 def topic_name(name) if defined?(SimpleMessageQueue.configuration.sns_notification_prefix) && !SimpleMessageQueue.configuration.sns_notification_prefix.nil? topic_name = "#{SimpleMessageQueue.configuration.sns_notification_prefix}_#{name}_#{SimpleMessageQueue.configuration.environment}" else topic_name = "#{name}_#{SimpleMessageQueue.configuration.environment}" end topic_name end |
Instance Method Details
#delete ⇒ Object
65 66 67 |
# File 'lib/simple_message_queue/notification.rb', line 65 def delete @sns_topic.delete end |
#name ⇒ Object
52 53 54 |
# File 'lib/simple_message_queue/notification.rb', line 52 def name @sns_topic.name end |
#send(message, subject = nil) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/simple_message_queue/notification.rb', line 56 def send(, subject=nil) = { topic_arn: @sns_topic.arn, message: } [:subject] = subject if subject sns.client.publish() end |
#sns ⇒ Object
40 41 42 |
# File 'lib/simple_message_queue/notification.rb', line 40 def sns SimpleMessageQueue::Notification.sns end |