Class: MasterDataTool::Dump::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/master_data_tool/dump/executor.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

DEFAULT_IGNORE_TABLES =
%w[ar_internal_metadata schema_migrations master_data_statuses]
DEFAULT_IGNORE_COLUMNS =
%w[created_at updated_at]

Instance Method Summary collapse

Constructor Details

#initialize(spec_config:, ignore_empty_table: true, ignore_tables: [], ignore_column_names: [], only_tables: [], verbose: false) ⇒ Executor

Returns a new instance of Executor.



11
12
13
14
15
16
17
18
# File 'lib/master_data_tool/dump/executor.rb', line 11

def initialize(spec_config:, ignore_empty_table: true, ignore_tables: [], ignore_column_names: [], only_tables: [], verbose: false)
  @spec_config = spec_config
  @ignore_empty_table = ignore_empty_table
  @ignore_tables = DEFAULT_IGNORE_TABLES + Array(spec_config.dump_ignore_tables) + ignore_tables
  @ignore_column_names = DEFAULT_IGNORE_COLUMNS + Array(spec_config.dump_ignore_columns) + ignore_column_names
  @only_tables = Array(only_tables)
  @verbose = verbose
end

Instance Method Details

#executeObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/master_data_tool/dump/executor.rb', line 20

def execute
  [].tap do |errors|
    spec_config.application_record_class.connection.tables.each do |table|
      if ignore_tables.include?(table)
        print_message "[ignore] #{table}"

        next
      end

      if only_tables.any? && !only_tables.include?(table)
        print_message "[skip] #{table}"
        next
      end

      dump_to_csv(table)
    rescue => e
      errors << Error.new(table, e)
    end
  end
end