Repository URL to install this package:
|
Version:
7.3.3 ▾
|
# frozen_string_literal: true
require_relative 'database_helper'
module Faculty
# Generic helper for fluent database interfaces
class FluentHelper
include DatabaseHelper
def initialize
@cleanup = []
end
def insert(helper, fields, **defaults)
helper.insert(**defaults, **fields)
.tap { |record| add_record_to_cleanup record }
end
def maybe_insert(helper, **fields)
insert(helper, fields) unless helper.include?(**fields)
end
def add_record_to_cleanup(record)
@cleanup << record
end
def cleanup
@cleanup.reverse_each(&:cleanup)
@cleanup = []
end
end
end