Sha256: 7bfcbd6b4ae868af5f7fb71c78ef0e6848a109672cc2ffb3d58491716403d857

Contents?: true

Size: 1.29 KB

Versions: 42

Compression:

Stored size: 1.29 KB

Contents

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

    def subscriptions
      fetch_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)
      check_existence
      # 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?
      raise Awspec::NoExistingResource.new(self.class, @display_name) if @subscriptions.nil?
      @subscriptions
    end
  end
end

Version data entries

42 entries across 42 versions & 3 rubygems

Version Path
awspec-1.25.1 lib/awspec/type/sns_topic.rb
awspec-1.25.0 lib/awspec/type/sns_topic.rb
awspec-1.24.4 lib/awspec/type/sns_topic.rb
awspec-1.24.3 lib/awspec/type/sns_topic.rb
awspec-1.24.2 lib/awspec/type/sns_topic.rb
awspec-1.24.1 lib/awspec/type/sns_topic.rb
awspec-1.24.0 lib/awspec/type/sns_topic.rb
awspec-1.23.0 lib/awspec/type/sns_topic.rb
awspec-1.22.1 lib/awspec/type/sns_topic.rb
awspec-1.22.0 lib/awspec/type/sns_topic.rb
awspec-1.21.1 lib/awspec/type/sns_topic.rb
awspec-1.21.0 lib/awspec/type/sns_topic.rb
awspec-1.20.0 lib/awspec/type/sns_topic.rb
awspec-1.19.2 lib/awspec/type/sns_topic.rb
awspec-1.19.1 lib/awspec/type/sns_topic.rb
awspec-1.19.0 lib/awspec/type/sns_topic.rb
cthiesfork-awspec-1.2.4 lib/awspec/type/sns_topic.rb
awspec-api_gateway_extended-1.2.4 lib/awspec/type/sns_topic.rb
awspec-api_gateway_extended-1.2.3 lib/awspec/type/sns_topic.rb
awspec-1.18.6 lib/awspec/type/sns_topic.rb