Sha256: e8125a742985ba70bea0464648c754505c84241ddc28d498cf7b1f275fdba60b

Contents?: true

Size: 493 Bytes

Versions: 1

Compression:

Stored size: 493 Bytes

Contents

module Hydroponics
  module Actions
    def dupe(table, target_count)
      table = table.to_sym

      first_row = @db[table].first
      first_row.delete(:id)

      current_count = @db[table].count

      time1 = Time.now
      if target_count > current_count
        @db[table].multi_insert([first_row] * (target_count - current_count))
      else
        @db[table].filter("id > #{target_count}").delete
      end
      time2 = Time.now

      (time2 - time1).to_s + 's'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hydroponics-0.3.0 app/actions/dupe.rb