class Forematter::Commands::Add

Public Instance Methods

run() click to toggle source
# File lib/forematter/commands/add.rb, line 19
def run
  files.each do |file|
    old = file.key?(field) ? file[field].to_ruby : []
    log_skip(file, "#{field} is not an array, unable to add") && next unless old.is_a?(Array)
    add = options[:'allow-dupes'] ? values : values.select { |v| !old.include?(v) }
    next if add.empty?
    add.each { |v| old << v }
    file[field] = old
    file.write
  end
end