Class: DBPurger::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/db-purger/table.rb

Overview

DBPurger::Table is an entity to keep track of basic table data

Constant Summary collapse

DEFAULT_BATCH_SIZE =
10_000

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, field) ⇒ Table

Returns a new instance of Table.



19
20
21
22
23
# File 'lib/db-purger/table.rb', line 19

def initialize(name, field)
  @name = name
  @field = field
  @batch_size = DEFAULT_BATCH_SIZE
end

Instance Attribute Details

#batch_sizeObject

Returns the value of attribute batch_size.



8
9
10
# File 'lib/db-purger/table.rb', line 8

def batch_size
  @batch_size
end

#conditionsObject

Returns the value of attribute conditions.



8
9
10
# File 'lib/db-purger/table.rb', line 8

def conditions
  @conditions
end

#fieldObject (readonly)

Returns the value of attribute field.



16
17
18
# File 'lib/db-purger/table.rb', line 16

def field
  @field
end

#foreign_keyObject

Returns the value of attribute foreign_key.



8
9
10
# File 'lib/db-purger/table.rb', line 8

def foreign_key
  @foreign_key
end

#mark_deleted_fieldObject

Returns the value of attribute mark_deleted_field.



8
9
10
# File 'lib/db-purger/table.rb', line 8

def mark_deleted_field
  @mark_deleted_field
end

#mark_deleted_valueObject



47
48
49
# File 'lib/db-purger/table.rb', line 47

def mark_deleted_value
  @mark_deleted_value || 1
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/db-purger/table.rb', line 16

def name
  @name
end

#search_procObject

Returns the value of attribute search_proc.



8
9
10
# File 'lib/db-purger/table.rb', line 8

def search_proc
  @search_proc
end

Instance Method Details

#fieldsObject



43
44
45
# File 'lib/db-purger/table.rb', line 43

def fields
  [@field] + foreign_keys
end

#foreign_keysObject



39
40
41
# File 'lib/db-purger/table.rb', line 39

def foreign_keys
  @nested_plan ? @nested_plan.foreign_tables.map(&:foreign_key).compact : []
end

#nested_plan(&block) ⇒ Object



25
26
27
28
29
# File 'lib/db-purger/table.rb', line 25

def nested_plan(&block)
  @nested_plan ||= Plan.new
  PlanBuilder.new(@nested_plan).build_nested_plan(self, &block) if block
  @nested_plan
end

#nested_tables?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/db-purger/table.rb', line 31

def nested_tables?
  @nested_plan != nil
end

#tablesObject



35
36
37
# File 'lib/db-purger/table.rb', line 35

def tables
  @nested_plan ? @nested_plan.tables : []
end