Sha256: 5198b232350029fa64e113f77b8d8a01e8d16099a3cd75d2acc2a2b8fce05c71

Contents?: true

Size: 1.35 KB

Versions: 115

Compression:

Stored size: 1.35 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
        if @rules
          stub_ref(@rules)
        else
          EmptyStructure.new
        end
      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.shape.struct_class.new) do |struct, (mname, mref)|
          # For eventstream shape, it returns an Enumerator
          unless mref.eventstream
            struct[mname] = stub_ref(mref, visited)
          end
          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

115 entries across 115 versions & 1 rubygems

Version Path
aws-sdk-core-3.46.1 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.46.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.45.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.44.2 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.44.1 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.44.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.43.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.42.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.41.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.40.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.39.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.38.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.37.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.36.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.35.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.34.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.33.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.32.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.31.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.30.0 lib/aws-sdk-core/stubbing/empty_stub.rb