module Easy module ReferenceData def self.refresh(clazz, unique_attribute_symbol, unique_attribute_value, attributes) record = clazz.where(unique_attribute_symbol => unique_attribute_value).first if record.nil? record = clazz.new(unique_attribute_symbol => unique_attribute_value) end attributes.each_pair do |key, value| record.send "#{key}=", value end begin record.save! rescue puts "Save failed for #{record.class}[#{unique_attribute_symbol}: #{unique_attribute_value}] with attributes #{attributes.inspect}" raise end record end end end