class DBPurger::Executor

DBPurger::Executor used to execute a purge plan with verification

Attributes

error_io[W]

Public Class Methods

new(database, plan, options = {}) click to toggle source
# File lib/db-purger/executor.rb, line 8
def initialize(database, plan, options = {})
  @database = database
  @plan = plan.is_a?(Plan) ? plan : load_plan(plan)
  setup_config(options)
  @error_io = $stderr
end

Public Instance Methods

purge!(purge_value) click to toggle source
# File lib/db-purger/executor.rb, line 15
def purge!(purge_value)
  raise('purge_value is nil') if purge_value.nil?

  @plan.purge!(@database, purge_value)
end
verify!() click to toggle source
# File lib/db-purger/executor.rb, line 21
def verify!
  return if plan_validator.valid?

  output_plan_errors
  raise('purge plan failed verification')
end

Private Instance Methods

load_plan(file) click to toggle source
# File lib/db-purger/executor.rb, line 40
def load_plan(file)
  PlanBuilder
    .new(Plan.new)
    .load_plan_file(file)
end
output_plan_errors() click to toggle source
# File lib/db-purger/executor.rb, line 46
def output_plan_errors
  plan_validator.errors.each do |field, error_msg|
    @error_io.puts "#{field}: #{error_msg}"
  end
end
plan_validator() click to toggle source
# File lib/db-purger/executor.rb, line 30
def plan_validator
  @plan_validator ||= PlanValidator.new(@database, @plan)
end
setup_config(options) click to toggle source
# File lib/db-purger/executor.rb, line 34
def setup_config(options)
  ::DBPurger.config.explain = options[:explain]
  ::DBPurger.config.explain_file = options[:explain_file]
  ::DBPurger.config.datetime_format = options[:datetime_format]
end