Sha256: 6e775ff2ef808c6fa2d4acc197e3a7ba922580d31cf76e54e62d0ae174f035df

Contents?: true

Size: 1.24 KB

Versions: 61

Compression:

Stored size: 1.24 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)
      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|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

61 entries across 61 versions & 2 rubygems

Version Path
awspec-0.88.2 lib/awspec/resource_reader.rb
awspec-0.88.1 lib/awspec/resource_reader.rb
awspec-0.88.0 lib/awspec/resource_reader.rb
awspec-0.87.1 lib/awspec/resource_reader.rb
awspec-0.87.0 lib/awspec/resource_reader.rb
awspec-0.86.0 lib/awspec/resource_reader.rb
cmonson_2ndwatch_awspec-0.85.4 lib/awspec/resource_reader.rb
awspec-0.85.3 lib/awspec/resource_reader.rb
cmonson_2ndwatch_awspec-0.85.3 lib/awspec/resource_reader.rb
awspec-0.85.2 lib/awspec/resource_reader.rb
awspec-0.85.1 lib/awspec/resource_reader.rb
awspec-0.85.0 lib/awspec/resource_reader.rb
awspec-0.84.1 lib/awspec/resource_reader.rb
awspec-0.84.0 lib/awspec/resource_reader.rb
awspec-0.83.0 lib/awspec/resource_reader.rb
awspec-0.82.3 lib/awspec/resource_reader.rb
awspec-0.82.2 lib/awspec/resource_reader.rb
awspec-0.82.1 lib/awspec/resource_reader.rb
awspec-0.82.0 lib/awspec/resource_reader.rb
awspec-0.81.1 lib/awspec/resource_reader.rb