class DBPurger::PlanBuilder
DBPurger::PlanBuilder
is used to build the relationships between tables in a convenient way
Public Class Methods
build(&block)
click to toggle source
# File lib/db-purger/plan_builder.rb, line 49 def self.build(&block) plan = Plan.new helper = new(plan) helper.instance_eval(&block) plan end
new(plan)
click to toggle source
# File lib/db-purger/plan_builder.rb, line 6 def initialize(plan) @plan = plan end
Public Instance Methods
base_table(table_name, field, options = {}, &block)
click to toggle source
# File lib/db-purger/plan_builder.rb, line 10 def base_table(table_name, field, options = {}, &block) @plan.base_table = create_table(table_name, field, options, &block) end
build_nested_plan(table, &block)
click to toggle source
# File lib/db-purger/plan_builder.rb, line 56 def build_nested_plan(table, &block) helper = self.class.new(table.nested_plan) helper.instance_eval(&block) end
child_table(table_name, field, options = {}, &block)
click to toggle source
# File lib/db-purger/plan_builder.rb, line 24 def child_table(table_name, field, options = {}, &block) table = create_table(table_name, field, options, &block) if @plan.base_table @plan.base_table.nested_plan.child_tables << table else @plan.child_tables << table end table end
ignore_table(table_name)
click to toggle source
# File lib/db-purger/plan_builder.rb, line 34 def ignore_table(table_name) @plan.ignore_tables << table_name end
load_plan_file(file)
click to toggle source
# File lib/db-purger/plan_builder.rb, line 61 def load_plan_file(file) instance_eval(File.read(file)) @plan end
parent_table(table_name, field, options = {}, &block)
click to toggle source
# File lib/db-purger/plan_builder.rb, line 14 def parent_table(table_name, field, options = {}, &block) table = create_table(table_name, field, options, &block) if @plan.base_table @plan.base_table.nested_plan.parent_tables << table else @plan.parent_tables << table end table end
purge_table_search(table_name, field, options = {}, &block)
click to toggle source
# File lib/db-purger/plan_builder.rb, line 38 def purge_table_search(table_name, field, options = {}, &block) table = create_table(table_name, field, options) table.search_proc = block || raise('no block given for search_proc') if @plan.base_table @plan.base_table.nested_plan.search_tables << table else @plan.search_tables << table end table end
Private Instance Methods
create_table(table_name, field, options, &block)
click to toggle source
# File lib/db-purger/plan_builder.rb, line 68 def create_table(table_name, field, options, &block) table = Table.new(table_name, field) table.foreign_key = options[:foreign_key] table.batch_size = options[:batch_size] if options[:batch_size] table.conditions = options[:conditions] table.mark_deleted_field = options[:mark_deleted_field] table.mark_deleted_value = options[:mark_deleted_value] build_nested_plan(table, &block) if block table end