Sha256: 79b2e53cd2ab599c3f4c8f0eace56665b15e35e966df4ae5ee9696a7c487e8ec

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

module Awspec::Type
  class SnsTopic < ResourceBase
    def initialize(topic_arn)
      super
      @topic_arn = topic_arn
      # lazy instantiation
      @subscriptions = nil
    end

    def subscriptions
      @subscriptions.keys
    end

    def resource_via_client
      @resource_via_client ||= find_sns_topic(@topic_arn)
    end

    def id
      # A SNS Topic doesn't have an ID...
      @id ||= resource_via_client.topic_arn if resource_via_client
    end

    def has_subscription?(subscribed_arn)
      fetch_subscriptions
      @subscriptions.key?(subscribed_arn.to_sym)
    end

    def subscribed(subscribed_arn)
      subs_key = subscribed_arn.to_sym
      fetch_subscriptions
      raise "'#{subscribed_arn}' is not a valid subscription ARN" unless @subscriptions.key?(subs_key)
      @subscriptions[subs_key]
    end

    def method_missing(method_name)
      # delegates the method invocation to Awspec::Helper::Finder::SnsTopic::SnsTopic class
      @resource_via_client.send method_name
    end

    private

    def fetch_subscriptions
      @subscriptions = find_sns_topic_subs(@topic_arn) if @subscriptions.nil?
      @subscriptions
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
awspec-1.12.3 lib/awspec/type/sns_topic.rb
awspec-1.12.2 lib/awspec/type/sns_topic.rb
awspec-1.12.1 lib/awspec/type/sns_topic.rb
awspec-1.12.0 lib/awspec/type/sns_topic.rb