module Hydroponics module Actions # Dupe # # Change the total rows of a table to target_count, either by duplicating # the first row or deleting rows from the end. def dupe(table, data) table = table.to_sym current_count = @db[table].count target_count = data['count'] || current_count if target_count > current_count first_row = @db[table].first first_row.delete(:id) @db[table].multi_insert([first_row] * (target_count - current_count)) elsif current_count > target_count cutoff_id = @db[table].map(:id)[target_count-1] @db[table].filter("id > #{cutoff_id}").delete end @db[table].count.to_s end end end