Sha256: 066198b3919ccb90483739e67cfcd5a17bf3e379a9c8af6a74b55c17eaa2d751

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 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
    /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

5 entries across 5 versions & 1 rubygems

Version Path
awspec-0.29.0 lib/awspec/resource_reader.rb
awspec-0.28.1 lib/awspec/resource_reader.rb
awspec-0.28.0 lib/awspec/resource_reader.rb
awspec-0.27.2 lib/awspec/resource_reader.rb
awspec-0.27.1 lib/awspec/resource_reader.rb