Sha256: f7256a4a5ecdabe4c692e0f7a46bb8bd0f5e46474ae08133156a57f39f80d44f

Contents?: true

Size: 1.42 KB

Versions: 129

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

module Aws
  # @api private
  module Stubbing
    class StubData

      def initialize(operation)
        @rules = operation.output
        @pager = operation[:pager]
      end

      def stub(data = {})
        stub = EmptyStub.new(@rules).stub
        remove_paging_tokens(stub)
        apply_data(data, stub)
        stub
      end

      private

      def remove_paging_tokens(stub)
        if @pager
          @pager.instance_variable_get("@tokens").keys.each do |path|
            if divide = (path[' || '] || path[' or '])
              path = path.split(divide)[0]
            end
            parts = path.split(/\b/)
            # if nested struct/expression, EmptyStub auto-pop "string"
            # currently not support remove "string" for nested/expression
            # as it requires reverse JMESPATH search
            stub[parts[0]] = nil if parts.size == 1
          end
          if more_results = @pager.instance_variable_get('@more_results')
            parts = more_results.split(/\b/)
            # if nested struct/expression, EmptyStub auto-pop false value
            # no further work needed
            stub[parts[0]] = false if parts.size == 1
          end
        end
      end

      def apply_data(data, stub)
        ParamValidator.new(@rules, validate_required: false, input: false).validate!(data)
        DataApplicator.new(@rules).apply_data(data, stub)
      end
    end
  end
end

Version data entries

129 entries across 129 versions & 1 rubygems

Version Path
aws-sdk-core-3.180.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.179.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.178.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.177.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.176.1 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.176.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.175.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.174.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.173.1 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.173.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.172.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.171.1 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.171.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.170.1 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.170.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.169.0 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.168.4 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.168.3 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.168.2 lib/aws-sdk-core/stubbing/stub_data.rb
aws-sdk-core-3.168.1 lib/aws-sdk-core/stubbing/stub_data.rb