class BingAdsRubySdk::Preprocessors::Order
Attributes
params[R]
wrapper[R]
Public Class Methods
new(wsdl_wrapper, params)
click to toggle source
# File lib/bing_ads_ruby_sdk/preprocessors/order.rb, line 7 def initialize(wsdl_wrapper, params) @wrapper = wsdl_wrapper @params = params end
Public Instance Methods
call()
click to toggle source
# File lib/bing_ads_ruby_sdk/preprocessors/order.rb, line 12 def call process(params, wrapper.request_namespace_type) end
Private Instance Methods
order(hash, allowed_attributes)
click to toggle source
# File lib/bing_ads_ruby_sdk/preprocessors/order.rb, line 51 def order(hash, allowed_attributes) array = allowed_attributes.keys # basically order by index in reference array Hash[ hash.sort_by { |k, _| array.index(wrapper.base_type_name(allowed_attributes, k)) || k.ord } ] end
ordered_params(namespace_type)
click to toggle source
# File lib/bing_ads_ruby_sdk/preprocessors/order.rb, line 47 def ordered_params(namespace_type) wrapper.ordered_fields_hash(namespace_type) end
ordered_value(allowed_attributes, type_name, value)
click to toggle source
# File lib/bing_ads_ruby_sdk/preprocessors/order.rb, line 33 def ordered_value(allowed_attributes, type_name, value) case value when Hash namespace_type = wrapper.namespace_and_type_from_name(allowed_attributes, type_name) process(value, namespace_type) when Array value.map do |elt| namespace_type = wrapper.namespace_and_type_from_name(allowed_attributes, type_name) process(elt, namespace_type) end else value end end
process(obj, namespace_type)
click to toggle source
NOTE: there is a potential for high memory usage here as we're using recursive method calling
# File lib/bing_ads_ruby_sdk/preprocessors/order.rb, line 21 def process(obj, namespace_type) return obj unless obj.is_a?(Hash) allowed_attributes = wrapper.ordered_fields_hash(namespace_type) order(obj, allowed_attributes).tap do |ordered_hash| ordered_hash.each do |type_name, value| ordered_hash[type_name] = ordered_value(allowed_attributes, type_name, value) end end end