class Forematter::Commands::Merge

Public Instance Methods

run() click to toggle source
# File lib/forematter/commands/merge.rb, line 14
def run
  dups      = values.dup
  canonical = dups.shift

  files_with(field).each do |file|
    old = file[field].to_ruby
    log_skip(file, "#{field} is not an array") && next unless old.is_a?(Array)

    # Continue unless unless field had one of the values to remove
    next if (old & dups).empty?
    dups.each { |v| file[field].delete(v) }

    # Save the original canonical for later
    file[field] << canonical unless file[field].include?(canonical)
    file.write
  end
end