Sha256: c5b2b4f6f2df8f16d1396d5bc0ed5f9852139694b08e5118f6d3bcd4df6cf720

Contents?: true

Size: 1.16 KB

Versions: 997

Compression:

Stored size: 1.16 KB

Contents

module Aws
  module Stubbing
    class EmptyStub

      include Seahorse::Model::Shapes

      # @param [Seahorse::Models::Shapes::ShapeRef] rules
      def initialize(rules)
        @rules = rules
      end

      # @return [Structure]
      def stub
        stub_ref(@rules)
      end

      private

      def stub_ref(ref, visited = [])
        if visited.include?(ref.shape)
          return nil
        else
          visited = visited + [ref.shape]
        end
        case ref.shape
        when StructureShape then stub_structure(ref, visited)
        when ListShape then []
        when MapShape then {}
        else stub_scalar(ref)
        end
      end

      def stub_structure(ref, visited)
        ref.shape.members.inject(ref[:struct_class].new) do |struct, (mname, mref)|
          struct[mname] = stub_ref(mref, visited)
          struct
        end
      end

      def stub_scalar(ref)
        case ref.shape
        when StringShape then ref.shape.name || 'string'
        when IntegerShape then 0
        when FloatShape then 0.0
        when BooleanShape then false
        when TimestampShape then Time.now
        else nil
        end
      end

    end
  end
end

Version data entries

997 entries across 997 versions & 2 rubygems

Version Path
aws-sdk-core-2.1.17 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.16 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.15 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.14 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.13 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.12 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.11 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.10 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.9 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.8 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.7 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.5 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.4 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.3 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.2 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.1 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-2.1.0 lib/aws-sdk-core/stubbing/empty_stub.rb