module ReplayApi::CompactAttributes

Public Instance Methods

compact_attributes() click to toggle source
# File lib/replay_api/compact_attributes.rb, line 3
def compact_attributes
  compact(attributes)
end

Private Instance Methods

compact(input) click to toggle source
# File lib/replay_api/compact_attributes.rb, line 9
def compact(input)
  input.each_with_object({}) do |(key, value), hash|
    next if value.nil?
    if value.is_a? Hash
      new_value = compact(value)
      next if new_value.empty?
      hash[key] = new_value
    elsif value.is_a? Model
      new_value = value.compact_attributes
      next if new_value.empty?
      hash[key] = new_value
    else
      hash[key] = value
    end
  end
end