Sha256: f91778e1c5efb5a777cf85e59dd24e439653998381ec6954240b40aa542a1b7c
Contents?: true
Size: 1.34 KB
Versions: 719
Compression:
Stored size: 1.34 KB
Contents
# frozen_string_literal: true module TencentCloud module Common # common model class AbstractModel def serialize flat(self) end def self.format_params(prefix = nil, params) d = {} case params when Hash params.each do |k, v| key = prefix ? "#{prefix}.#{k}" : k.to_s d.update(format_params(key, v)) end when Array params.each_with_index do |v, i| key = prefix ? "#{prefix}.#{i}" : i.to_s d.update(format_params(key, v)) end else d[prefix] = params end d end private def flat(obj) case obj when AbstractModel params = nil keys = obj.instance_variables keys.each do |k| value = obj.instance_variable_get k key = k.to_s.split('@').at 1 next unless value r = flat(value) unless r.nil? params ||= {} params[key] = r end end params when Array arr = nil obj.each do |v| r = flat(v) unless r.nil? arr ||= [] arr << r end end arr else obj end end end end end
Version data entries
719 entries across 719 versions & 1 rubygems