class Hashie::IUTrash

Public Instance Methods

inverse_attributes() click to toggle source
# File lib/braspag-rest/hashie/iutrash.rb, line 7
def inverse_attributes
  self.class.translations.each_with_object({}) do |(from, property), attributes|
    value = nested_inverse(self.send(property))

    unless value.nil?
      attributes[from] = value
    end
  end
end

Private Instance Methods

attributes_for(value) click to toggle source
# File lib/braspag-rest/hashie/iutrash.rb, line 27
def attributes_for(value)
  value.respond_to?(:inverse_attributes) ? value.inverse_attributes : value
end
nested_inverse(value) click to toggle source
# File lib/braspag-rest/hashie/iutrash.rb, line 19
def nested_inverse(value)
  if [Array, Set].include?(value.class)
    value.map { |item| attributes_for(item) }
  else
    attributes_for(value)
  end
end