Class: Forematter::Commands::Add

Inherits:
Forematter::CommandRunner show all
Defined in:
lib/forematter/commands/add.rb

Instance Method Summary collapse

Methods inherited from Forematter::CommandRunner

#call

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
# 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