Sha256: 586047d0a28799010ac6d4a73a4d685ff7eaceae739e6449d23f81750567c489

Contents?: true

Size: 1.16 KB

Versions: 34

Compression:

Stored size: 1.16 KB

Contents

require 'aws-sdk'
require 'awspec/resource_reader'
require 'awspec/helper/finder'

module Awspec::Type
  class Base
    include Awspec::Helper::Finder
    include Awspec::BlackListForwardable

    attr_reader :id, :resource_via_client

    def initialize(id = nil)
      @display_name = id
      @id = nil
    end

    def to_s
      type = self.class.name.demodulize.underscore
      "#{type} '#{@display_name}'"
    end

    def inspect
      to_s
    end

    def exists?
      @id
    end

    def self.aws_resource(resource)
      define_method :resource do
        @resource ||= Awspec::ResourceReader.new(resource.new(@id))
      end
    end

    def self.tags_allowed
      define_method :has_tag? do |key, value|
        tags = @resource_via_client.tags
        return false unless tags
        tags.any? { |t| t['key'] == key && t['value'] == value }
      end
    end

    def method_missing(name)
      describe = name.to_sym
      if @resource_via_client.members.include?(describe)
        @resource_via_client[describe]
      else
        super unless self.respond_to?(:resource)
        method_missing_via_black_list(name, delegate_to: resource)
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
awspec-0.55.0 lib/awspec/type/base.rb
awspec-0.54.0 lib/awspec/type/base.rb
awspec-0.52.4 lib/awspec/type/base.rb
awspec-0.52.3 lib/awspec/type/base.rb
awspec-0.52.2 lib/awspec/type/base.rb
awspec-0.52.1 lib/awspec/type/base.rb
awspec-0.52.0 lib/awspec/type/base.rb
awspec-0.51.0 lib/awspec/type/base.rb
awspec-0.50.0 lib/awspec/type/base.rb
awspec-0.49.0 lib/awspec/type/base.rb
awspec-0.48.0 lib/awspec/type/base.rb
awspec-0.47.0 lib/awspec/type/base.rb
awspec-0.46.0 lib/awspec/type/base.rb
awspec-0.45.0 lib/awspec/type/base.rb
awspec-0.44.0 lib/awspec/type/base.rb
awspec-0.43.0 lib/awspec/type/base.rb
awspec-0.42.0 lib/awspec/type/base.rb
awspec-0.41.0 lib/awspec/type/base.rb
awspec-0.40.0 lib/awspec/type/base.rb
awspec-0.39.0 lib/awspec/type/base.rb