Class: DBPurger::PlanBuilder
- Inherits:
-
Object
- Object
- DBPurger::PlanBuilder
- Defined in:
- lib/db-purger/plan_builder.rb
Overview
DBPurger::PlanBuilder is used to build the relationships between tables in a convenient way
Class Method Summary collapse
Instance Method Summary collapse
- #base_table(table_name, field, options = {}, &block) ⇒ Object
- #build_nested_plan(table, &block) ⇒ Object
- #child_table(table_name, field, options = {}, &block) ⇒ Object
- #ignore_table(table_name) ⇒ Object
-
#initialize(plan) ⇒ PlanBuilder
constructor
A new instance of PlanBuilder.
- #load_plan_file(file) ⇒ Object
- #parent_table(table_name, field, options = {}, &block) ⇒ Object
- #purge_table_search(table_name, field, options = {}, &block) ⇒ Object
Constructor Details
#initialize(plan) ⇒ PlanBuilder
Returns a new instance of PlanBuilder.
6 7 8 |
# File 'lib/db-purger/plan_builder.rb', line 6 def initialize(plan) @plan = plan end |
Class Method Details
.build(&block) ⇒ Object
49 50 51 52 53 54 |
# 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 |
Instance Method Details
#base_table(table_name, field, options = {}, &block) ⇒ Object
10 11 12 |
# File 'lib/db-purger/plan_builder.rb', line 10 def base_table(table_name, field, = {}, &block) @plan.base_table = create_table(table_name, field, , &block) end |
#build_nested_plan(table, &block) ⇒ Object
56 57 58 59 |
# 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) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/db-purger/plan_builder.rb', line 24 def child_table(table_name, field, = {}, &block) table = create_table(table_name, field, , &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) ⇒ Object
34 35 36 |
# File 'lib/db-purger/plan_builder.rb', line 34 def ignore_table(table_name) @plan.ignore_tables << table_name end |
#load_plan_file(file) ⇒ Object
61 62 63 64 |
# 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) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/db-purger/plan_builder.rb', line 14 def parent_table(table_name, field, = {}, &block) table = create_table(table_name, field, , &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) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/db-purger/plan_builder.rb', line 38 def purge_table_search(table_name, field, = {}, &block) table = create_table(table_name, field, ) 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 |