@param [Seahorse::Models::Shapes::Structure] output_shape This should
be the output shape for an operation.
# File lib/aws-sdk-core/client_stubs.rb, line 135 def initialize(output_shape) @shape = output_shape end
@param [Hash] data An optional hash of data to format into the stubbed
object.
# File lib/aws-sdk-core/client_stubs.rb, line 141 def format(data = {}) if @shape.nil? empty_stub(data) else validate_data(data) stub(@shape, data) end end
# File lib/aws-sdk-core/client_stubs.rb, line 222 def empty_stub(data) if data.empty? Structure.new(data) else msg = 'unable to generate a stubbed response from the given data; ' msg << 'this operation does not return data' raise ArgumentError, msg end end
# File lib/aws-sdk-core/client_stubs.rb, line 169 def structure_obj(shape, hash) stubs = Structure.new(shape.member_names) shape.members.each do |member_name, member_shape| value = structure_value(shape, member_name, member_shape, hash) stubs[member_name] = stub(member_shape, value) end stubs end
# File lib/aws-sdk-core/client_stubs.rb, line 178 def structure_value(shape, member_name, member_shape, hash) if hash.key?(member_name) hash[member_name] elsif Seahorse::Model::Shapes::Structure === member_shape && shape.required.include?(member_name) then {} else nil end end
# File lib/aws-sdk-core/client_stubs.rb, line 152 def stub(shape, value) case shape when Seahorse::Model::Shapes::Structure then stub_structure(shape, value) when Seahorse::Model::Shapes::List then stub_list(shape, value || []) when Seahorse::Model::Shapes::Map then stub_map(shape, value || {}) else stub_scalar(shape, value) end end
# File lib/aws-sdk-core/client_stubs.rb, line 191 def stub_list(shape, array) stubs = [] array.each do |value| stubs << stub(shape.member, value) end stubs end
# File lib/aws-sdk-core/client_stubs.rb, line 199 def stub_map(shape, value) stubs = {} value.each do |key, value| stubs[key] = stub(shape.value, value) end stubs end
# File lib/aws-sdk-core/client_stubs.rb, line 207 def stub_scalar(shape, value) if value.nil? case shape when Seahorse::Model::Shapes::String then shape.name when Seahorse::Model::Shapes::Integer then 0 when Seahorse::Model::Shapes::Float then 0.0 when Seahorse::Model::Shapes::Boolean then false when Seahorse::Model::Shapes::Timestamp then Time.now else nil end else value end end
# File lib/aws-sdk-core/client_stubs.rb, line 161 def stub_structure(shape, hash) if hash structure_obj(shape, hash) else nil end end
# File lib/aws-sdk-core/client_stubs.rb, line 232 def validate_data(data) args = [@shape, { validate_required:false }] Seahorse::Client::ParamValidator.new(*args).validate!(data) end