Module: I18n::Backend::Weeler::Dedupe::ClassMethods

Defined in:
lib/i18n/backend/weeler/dedupe.rb

Instance Method Summary collapse

Instance Method Details

#dedupeObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/i18n/backend/weeler/dedupe.rb', line 14

def dedupe
  # find all models and group them on keys which should be common
  grouped = all.group_by{|model| [model.locale,model.key] }
  grouped.values.each do |duplicates|
    # the first one we want to keep right?
    first_one = duplicates.shift # or pop for last one
    # if there are any more left, they are duplicates
    # so delete all of them
    duplicates.each{|double| double.destroy} # duplicates can now be destroyed
  end
end