module Dunlop::LastAttributeChangeHelper
  def last_changed_info(target, attr)
    if target.is_a?(RecordCollection::Base)
      changes = target.map{|r| r.last_changed[attr] }.compact.uniq
    else # must be a ActiveRecord::Base
      changes = [target.last_changed[attr]].compact
    end
    return nil if changes.empty?
    return t('collection.last_changed.mixed_values') if changes.size > 1
    changes.map{|c| I18n.localize(c, format: '%-e %b %-k:%M') }.join(', ')
  end
end
