Sha256: 90cab89d6b6909f851633acc0c35c839b971b6c5f2314dd2810223578bf73654

Contents?: true

Size: 1.25 KB

Versions: 20

Compression:

Stored size: 1.25 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
      if match_black_list?(name) && !match_white_list?(name)
        raise CalledMethodInBlackList, "Method call #{name.inspect} is black-listed"
      end
      attr = delegate_to.send(name)
      if !attr.is_a?(Struct) && attr.class.name.match(/^Aws::/)
        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|enable_|remove
    /ix

    def match_black_list?(name)
      BLACK_LIST_RE =~ name
    end

    WHITE_LIST_RE = /password_reset_required|attached_policies/ix

    def match_white_list?(name)
      WHITE_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

20 entries across 20 versions & 1 rubygems

Version Path
awspec-1.9.0 lib/awspec/resource_reader.rb
awspec-1.8.0 lib/awspec/resource_reader.rb
awspec-1.7.0 lib/awspec/resource_reader.rb
awspec-1.6.1 lib/awspec/resource_reader.rb
awspec-1.6.0 lib/awspec/resource_reader.rb
awspec-1.5.4 lib/awspec/resource_reader.rb
awspec-1.5.3 lib/awspec/resource_reader.rb
awspec-1.5.2 lib/awspec/resource_reader.rb
awspec-1.5.1 lib/awspec/resource_reader.rb
awspec-1.5.0 lib/awspec/resource_reader.rb
awspec-1.4.3 lib/awspec/resource_reader.rb
awspec-1.4.2 lib/awspec/resource_reader.rb
awspec-1.4.1 lib/awspec/resource_reader.rb
awspec-1.4.0 lib/awspec/resource_reader.rb
awspec-1.3.1 lib/awspec/resource_reader.rb
awspec-1.3.0 lib/awspec/resource_reader.rb
awspec-1.2.0 lib/awspec/resource_reader.rb
awspec-1.1.0 lib/awspec/resource_reader.rb
awspec-1.0.0 lib/awspec/resource_reader.rb
awspec-1.0.0.rc lib/awspec/resource_reader.rb