Class: DbBlaster::SourceTableConfigurationBuilder

Inherits:
Object
  • Object
show all
Includes:
AvailableTables
Defined in:
lib/db_blaster/source_table_configuration_builder.rb

Overview

Builds source-table configurations based off the tables in the current database and the provided DbBlaster::Configuration

Constant Summary

Constants included from AvailableTables

AvailableTables::SYSTEM_TABLES

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AvailableTables

#available_tables

Constructor Details

#initialize(configuration) ⇒ SourceTableConfigurationBuilder

Returns a new instance of SourceTableConfigurationBuilder.



10
11
12
13
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 10

def initialize(configuration)
  @configuration = configuration
  @source_table_configurations = []
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



8
9
10
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 8

def configuration
  @configuration
end

#source_table_configurationsObject (readonly)

Returns the value of attribute source_table_configurations.



8
9
10
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 8

def source_table_configurations
  @source_table_configurations
end

Class Method Details

.build_all(configuration) ⇒ Object



15
16
17
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 15

def self.build_all(configuration)
  new(configuration).build_all
end

Instance Method Details

#batch_size(source_table_name) ⇒ Object



30
31
32
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 30

def batch_size(source_table_name)
  overridden_value_or_global(source_table_name, :batch_size) || configuration.class::DEFAULT_BATCH_SIZE
end

#build_allObject



19
20
21
22
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 19

def build_all
  @build_all ||= table_names_for_configuration
                 .collect(&method(:build_configuration))
end

#build_configuration(source_table_name) ⇒ Object



24
25
26
27
28
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 24

def build_configuration(source_table_name)
  SourceTableConfiguration.new(source_table_name: source_table_name,
                               batch_size: batch_size(source_table_name),
                               ignored_column_names: ignored_column_names(source_table_name))
end

#find_source_table_options(source_table_name) ⇒ Object



42
43
44
45
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 42

def find_source_table_options(source_table_name)
  (configuration.source_table_options || [])
    .detect { |option| option[:source_table_name] == source_table_name }
end

#ignored_column_names(source_table_name) ⇒ Object



34
35
36
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 34

def ignored_column_names(source_table_name)
  overridden_value_or_global(source_table_name, :ignored_column_names) || []
end

#overridden_value_or_global(source_table_name, field_name) ⇒ Object



38
39
40
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 38

def overridden_value_or_global(source_table_name, field_name)
  find_source_table_options(source_table_name)&.send(:[], field_name) || configuration.send(field_name)
end

#table_names_for_configurationObject



47
48
49
50
51
52
53
54
# File 'lib/db_blaster/source_table_configuration_builder.rb', line 47

def table_names_for_configuration
  table_names = if configuration.only_source_tables&.length&.positive?
                  available_tables & configuration.only_source_tables
                else
                  available_tables
                end
  table_names - (configuration.ignore_source_tables || [])
end