Sha256: fb05c59470d6db3fcfcffd8b8b93126e3f25b4e18218c58e362094d1d7d96933

Contents?: true

Size: 1.24 KB

Versions: 48

Compression:

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

48 entries across 48 versions & 1 rubygems

Version Path
aws-sdk-core-3.6.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.5.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.4.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.3.1 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.3.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.2.1 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.2.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.1.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc20 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc19 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc18 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc17 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc16 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc15 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc14 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc13 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc12 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc11 lib/aws-sdk-core/stubbing/empty_stub.rb
aws-sdk-core-3.0.0.rc10 lib/aws-sdk-core/stubbing/empty_stub.rb