Class: DBPurger::Plan
- Inherits:
-
Object
- Object
- DBPurger::Plan
- Defined in:
- lib/db-purger/plan.rb
Overview
DBPurger::Plan is used to describe the relationship between tables
Instance Attribute Summary collapse
-
#base_table ⇒ Object
Returns the value of attribute base_table.
-
#child_tables ⇒ Object
readonly
Returns the value of attribute child_tables.
-
#ignore_tables ⇒ Object
readonly
Returns the value of attribute ignore_tables.
-
#parent_tables ⇒ Object
readonly
Returns the value of attribute parent_tables.
-
#search_tables ⇒ Object
readonly
Returns the value of attribute search_tables.
Instance Method Summary collapse
- #empty? ⇒ Boolean
- #ignore_table?(table_name) ⇒ Boolean
-
#initialize ⇒ Plan
constructor
A new instance of Plan.
- #purge!(database, purge_value) ⇒ Object
- #table_names ⇒ Object
- #tables ⇒ Object
Constructor Details
#initialize ⇒ Plan
Returns a new instance of Plan.
13 14 15 16 17 18 |
# File 'lib/db-purger/plan.rb', line 13 def initialize @parent_tables = [] @child_tables = [] @ignore_tables = [] @search_tables = [] end |
Instance Attribute Details
#base_table ⇒ Object
Returns the value of attribute base_table.
6 7 8 |
# File 'lib/db-purger/plan.rb', line 6 def base_table @base_table end |
#child_tables ⇒ Object (readonly)
Returns the value of attribute child_tables.
8 9 10 |
# File 'lib/db-purger/plan.rb', line 8 def child_tables @child_tables end |
#ignore_tables ⇒ Object (readonly)
Returns the value of attribute ignore_tables.
8 9 10 |
# File 'lib/db-purger/plan.rb', line 8 def ignore_tables @ignore_tables end |
#parent_tables ⇒ Object (readonly)
Returns the value of attribute parent_tables.
8 9 10 |
# File 'lib/db-purger/plan.rb', line 8 def parent_tables @parent_tables end |
#search_tables ⇒ Object (readonly)
Returns the value of attribute search_tables.
8 9 10 |
# File 'lib/db-purger/plan.rb', line 8 def search_tables @search_tables end |
Instance Method Details
#empty? ⇒ Boolean
39 40 41 42 43 44 |
# File 'lib/db-purger/plan.rb', line 39 def empty? @base_table.nil? && @parent_tables.empty? && @child_tables.empty? && @search_tables.empty? end |
#ignore_table?(table_name) ⇒ Boolean
46 47 48 49 50 51 52 53 54 |
# File 'lib/db-purger/plan.rb', line 46 def ignore_table?(table_name) @ignore_tables.any? do |ignore_table_name| if ignore_table_name.is_a?(Regexp) ignore_table_name.match(table_name) else ignore_table_name.to_s == table_name end end end |
#purge!(database, purge_value) ⇒ Object
20 21 22 23 |
# File 'lib/db-purger/plan.rb', line 20 def purge!(database, purge_value) MetricSubscriber.reset! PurgeTable.new(database, @base_table, @base_table.field, purge_value).purge! end |
#table_names ⇒ Object
35 36 37 |
# File 'lib/db-purger/plan.rb', line 35 def table_names tables.map(&:name) end |
#tables ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/db-purger/plan.rb', line 25 def tables all_tables = @base_table ? [@base_table] + @base_table.tables : [] all_tables += @parent_tables + @parent_tables.map(&:tables) + @child_tables + @child_tables.map(&:tables) + @search_tables + @search_tables.map(&:tables) all_tables.flatten! all_tables.compact! all_tables end |