class Aws::ParamConverter
@api private
Attributes
@api private
Public Class Methods
Source
# File lib/aws-sdk-core/param_converter.rb, line 111 def add(shape_class, value_class, converter = nil, &block) @converters[shape_class][value_class] = converter || block end
Registers a new value converter. Converters run in the context of a shape and value class.
# add a converter that stringifies integers shape_class = Seahorse::Model::Shapes::StringShape ParamConverter.add(shape_class, Integer) { |i| i.to_s }
@param [Class<Model::Shapes::Shape>] shape_class @param [Class] value_class @param [#call] converter (nil) An object that responds to ‘#call`
accepting a single argument. This function should perform the value conversion if possible, returning the result. If the conversion is not possible, the original value should be returned.
@return [void]
Source
# File lib/aws-sdk-core/param_converter.rb, line 126 def c(shape, value, instance = nil) if converter = converter_for(shape, value) converter.call(value, instance) else value end end
@api private
Source
# File lib/aws-sdk-core/param_converter.rb, line 92 def convert(shape, params) new(shape).convert(params) end
Source
# File lib/aws-sdk-core/param_converter.rb, line 115 def ensure_open(file, converter) if file.closed? new_file = File.open(file.path, 'rb') converter.opened_files << new_file new_file else file end end
Source
# File lib/aws-sdk-core/param_converter.rb, line 18 def initialize(rules) @rules = rules @opened_files = [] end
Private Class Methods
Source
# File lib/aws-sdk-core/param_converter.rb, line 136 def converter_for(shape_class, value) unless @converters[shape_class].key?(value.class) @mutex.synchronize { unless @converters[shape_class].key?(value.class) @converters[shape_class][value.class] = find(shape_class, value) end } end @converters[shape_class][value.class] end
Source
# File lib/aws-sdk-core/param_converter.rb, line 161 def each_base_class(shape_class, &block) shape_class.ancestors.each do |ancestor| yield(ancestor) if @converters.key?(ancestor) end end
Source
# File lib/aws-sdk-core/param_converter.rb, line 147 def find(shape_class, value) converter = nil each_base_class(shape_class) do |klass| @converters[klass].each do |value_class, block| if value_class === value converter = block break end end break if converter end converter end
Public Instance Methods
Source
# File lib/aws-sdk-core/param_converter.rb, line 36 def close_opened_files @opened_files.each(&:close) @opened_files = [] end
Source
# File lib/aws-sdk-core/param_converter.rb, line 28 def convert(params) if @rules structure(@rules, params) else params end end
@param [Hash] params @return [Hash]
Private Instance Methods
Source
# File lib/aws-sdk-core/param_converter.rb, line 86 def c(ref, value) self.class.c(ref.shape.class, value, self) end
Source
# File lib/aws-sdk-core/param_converter.rb, line 57 def list(ref, values) values = c(ref, values) if values.is_a?(Array) values.map { |v| member(ref.shape.member, v) } else values end end
Source
# File lib/aws-sdk-core/param_converter.rb, line 66 def map(ref, values) values = c(ref, values) if values.is_a?(Hash) values.each.with_object({}) do |(key, value), hash| hash[member(ref.shape.key, key)] = member(ref.shape.value, value) end else values end end
Source
# File lib/aws-sdk-core/param_converter.rb, line 77 def member(ref, value) case ref.shape when StructureShape then structure(ref, value) when ListShape then list(ref, value) when MapShape then map(ref, value) else c(ref, value) end end
Source
# File lib/aws-sdk-core/param_converter.rb, line 43 def structure(ref, values) values = c(ref, values) if ::Struct === values || Hash === values values.each_pair do |k, v| unless v.nil? if ref.shape.member?(k) values[k] = member(ref.shape.member(k), v) end end end end values end