Class: Forematter::Commands::Add
- Inherits:
-
Forematter::CommandRunner
- Object
- Cri::CommandRunner
- Forematter::CommandRunner
- Forematter::Commands::Add
- Defined in:
- lib/forematter/commands/add.rb
Instance Method Summary collapse
Methods inherited from Forematter::CommandRunner
Instance Method Details
#run ⇒ Object
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 = [:'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 |