Sha256: ebe02de2eb90b376d608f6b4637691c1ad73d91d8e02fd1d42d7525cb8e9756c

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Awspec
  module BlackListForwardable
    class CalledMethodInBlackList < StandardError
    end

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

1 entries across 1 versions & 1 rubygems

Version Path
awspec-0.30.0 lib/awspec/resource_reader.rb