Sha256: a9c451c7ade0aadd6314be4f0d0b7389981c262c4fcd1e26abb09128bcb0437f
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
module Zuora module Serializers module Attribute # @param [Object] model: An object responding to .attributes # for which each attr can be .send(attr) # @param [Hash] { [String]: lowerCamelCased key => # [Any]: value } def self.serialize(model) attrs = model.changed_attributes || {} attr_pairs = attrs.map { |attr| serialize_attr model, attr } Hash[attr_pairs] end private def self.serialize_attr(object, attr) # Camelizes the stringified attribute name # Note: This specific transformation (lowerCamelCase) # could be passed in; decoupling recursive traversal # from the end-node render / transformation. key = attr.to_s.camelize(:lower) # Get current attribute's property val = object.send(attr) # Recursively serialize this attribute's # attributes, if they are defined val = serialize val if val.respond_to?(:changed_attributes) [key, val] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
zuora-ruby-0.2.0 | lib/zuora/serializers/attribute.rb |