Sha256: 7308cff8d634dd22630748d26d2a863a9981bc8d467265345c59c0b4137167c9

Contents?: true

Size: 1.04 KB

Versions: 11

Compression:

Stored size: 1.04 KB

Contents

module Awspec
  module BlackListForwardable
    class CalledMethodInBlackList < StandardError
    end

    def method_missing_via_black_list(name, delegate_to: nil)
      raise ArguementError, 'delegate_to: must be specified' unless delegate_to
      raise CalledMethodInBlackList, "Method call #{name.inspect} is black-listed" if match_black_list?(name)
      attr = delegate_to.send(name)
      case attr
      when Aws::Resources::Resource
        ResourceReader.new(attr)
      else
        attr
      end
    end

    private

    BLACK_LIST_RE = /
      clear|
      create|delete|put|update|add|
      attach|detach|
      reboot|start|stop|terminate|
      modify|reset|replace|
      authorize|revoke|
      deregister
    /ix

    def match_black_list?(name)
      BLACK_LIST_RE =~ name
    end
  end

  class ResourceReader
    include BlackListForwardable

    def initialize(resource)
      @resource_via_client = resource
    end

    def method_missing(name)
      method_missing_via_black_list(name, delegate_to: @resource_via_client)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
awspec-0.37.3 lib/awspec/resource_reader.rb
awspec-0.37.2 lib/awspec/resource_reader.rb
awspec-0.37.1 lib/awspec/resource_reader.rb
awspec-0.37.0 lib/awspec/resource_reader.rb
awspec-0.36.1 lib/awspec/resource_reader.rb
awspec-0.36.0 lib/awspec/resource_reader.rb
awspec-0.35.0 lib/awspec/resource_reader.rb
awspec-0.34.0 lib/awspec/resource_reader.rb
awspec-0.33.0 lib/awspec/resource_reader.rb
awspec-0.32.0 lib/awspec/resource_reader.rb
awspec-0.31.0 lib/awspec/resource_reader.rb