master_data_tool 0.22.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/exe/master_data_tool +3 -65
  3. data/lib/master_data_tool/act_as_master_data.rb +13 -0
  4. data/lib/master_data_tool/command/dump.rb +43 -0
  5. data/lib/master_data_tool/command/import.rb +86 -0
  6. data/lib/master_data_tool/command/verify.rb +64 -0
  7. data/lib/master_data_tool/command.rb +5 -0
  8. data/lib/master_data_tool/config.rb +1 -1
  9. data/lib/master_data_tool/dump/config.rb +42 -0
  10. data/lib/master_data_tool/dump/executor.rb +9 -15
  11. data/lib/master_data_tool/dump.rb +1 -0
  12. data/lib/master_data_tool/import/config.rb +35 -0
  13. data/lib/master_data_tool/import/executor.rb +49 -76
  14. data/lib/master_data_tool/import.rb +1 -0
  15. data/lib/master_data_tool/master_data.rb +48 -36
  16. data/lib/master_data_tool/master_data_collection.rb +1 -1
  17. data/lib/master_data_tool/master_data_file.rb +4 -4
  18. data/lib/master_data_tool/master_data_file_collection.rb +10 -8
  19. data/lib/master_data_tool/master_data_status.rb +18 -9
  20. data/lib/master_data_tool/report/core.rb +2 -2
  21. data/lib/master_data_tool/report/default_printer.rb +1 -1
  22. data/lib/master_data_tool/report/import_report.rb +13 -15
  23. data/lib/master_data_tool/report/print_affected_table_report.rb +2 -2
  24. data/lib/master_data_tool/report/printer.rb +2 -2
  25. data/lib/master_data_tool/report/verify_report.rb +8 -8
  26. data/lib/master_data_tool/spec_config.rb +8 -10
  27. data/lib/master_data_tool/verify/config.rb +39 -0
  28. data/lib/master_data_tool/verify/executor.rb +39 -0
  29. data/lib/master_data_tool/verify.rb +4 -0
  30. data/lib/master_data_tool/version.rb +1 -1
  31. data/lib/master_data_tool.rb +21 -3
  32. data/sig/master_data_tool.rbs +323 -171
  33. metadata +38 -15
  34. data/LICENSE +0 -21
  35. data/README.md +0 -242
@@ -7,24 +7,24 @@ module MasterDataTool
7
7
 
8
8
  attr_reader :reports
9
9
 
10
- def initialize(master_data)
11
- super(master_data)
10
+ def initialize(master_data:)
11
+ super(master_data: master_data)
12
12
  @reports = []
13
13
  end
14
14
 
15
- def append(verify_record_report)
16
- @reports << verify_record_report
15
+ def append(report:)
16
+ @reports << report
17
17
  end
18
18
 
19
- def print(printer)
19
+ def print(printer:)
20
20
  @reports.each do |report|
21
- printer.print(convert_to_ltsv(report))
21
+ printer.print(message: convert_to_ltsv(report))
22
22
  end
23
23
  end
24
24
 
25
25
  class << self
26
- def build_verify_record_report(master_data, record, valid)
27
- {operation: :verify, table_name: master_data.table_name, valid: valid, id: record.id}
26
+ def build_verify_record_report(master_data:, record:, valid:)
27
+ { operation: :verify, table_name: master_data.table_name, valid: valid, id: record.id }
28
28
  end
29
29
  end
30
30
  end
@@ -1,21 +1,19 @@
1
1
  module MasterDataTool
2
2
  class SpecConfig
3
- attr_reader :spec_name, :application_record_class, :dump_ignore_tables, :dump_ignore_columns,
4
- :default_import_options, :logger, :preload_associations, :eager_load_associations
3
+ attr_accessor :spec_name, :application_record_class, :import_config, :verify_config, :dump_config, :logger
5
4
 
6
- def initialize(spec_name:, application_record_class:, dump_ignore_tables: [], dump_ignore_columns: [],
7
- default_import_options: {}, logger: Logger.new(nil), preload_associations: {}, eager_load_associations: {})
5
+ def initialize(spec_name:, application_record_class:, import_config: nil, verify_config: nil, dump_config: nil, logger: Logger.new(nil))
8
6
 
9
7
  @spec_name = spec_name.presence || ''
10
8
  @application_record_class = application_record_class
11
- @dump_ignore_tables = dump_ignore_tables
12
- @dump_ignore_columns = dump_ignore_columns
13
- @default_import_options = default_import_options
9
+ @import_config = import_config
10
+ @verify_config = verify_config
11
+ @dump_config = dump_config
14
12
  @logger = logger
15
- @preload_associations = preload_associations # key: Class, value: associations
16
- @eager_load_associations = eager_load_associations # key: Class, value: associations
13
+ end
17
14
 
18
- freeze
15
+ def configure
16
+ yield self
19
17
  end
20
18
  end
21
19
  end
@@ -0,0 +1,39 @@
1
+ module MasterDataTool
2
+ module Verify
3
+ class Config
4
+ DEFAULT_VALUES = {
5
+ only_tables: [],
6
+ except_tables: [],
7
+ preload_belongs_to_associations: true,
8
+ preload_associations: {},
9
+ eager_load_associations: {}
10
+ }
11
+
12
+ attr_accessor :only_tables, :except_tables, :preload_belongs_to_associations,
13
+ :preload_associations, # key: Class, value: associations
14
+ :eager_load_associations # key: Class, value: associations
15
+
16
+ def initialize(only_tables:, except_tables:, preload_belongs_to_associations:, preload_associations:, eager_load_associations:)
17
+ @only_tables = only_tables
18
+ @except_tables = except_tables
19
+ @preload_belongs_to_associations = preload_belongs_to_associations
20
+ @preload_associations = preload_associations
21
+ @eager_load_associations = eager_load_associations
22
+ end
23
+
24
+ def skip_table?(table_name)
25
+ MasterDataTool.need_skip_table?(table_name, only_tables, except_tables)
26
+ end
27
+
28
+ def configure
29
+ yield self
30
+ end
31
+
32
+ class << self
33
+ def default_config
34
+ new(**DEFAULT_VALUES)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MasterDataTool
4
+ module Verify
5
+ class Executor
6
+ def initialize(spec_config:, verify_config: nil, silent: false, override_identifier: nil, report_printer: nil)
7
+ @spec_config = spec_config
8
+ @verify_config = verify_config || MasterDataTool::Verify::Config.default_config
9
+ @silent = silent
10
+ @override_identifier = override_identifier
11
+ @report_printer = report_printer || MasterDataTool::Report::DefaultPrinter.new(spec_config: spec_config)
12
+ @report_printer.silent = silent
13
+ end
14
+
15
+ def execute
16
+ master_data_collection = build_master_data_collection
17
+ master_data_collection.each do |master_data|
18
+ next if verify_config.skip_table?(master_data.table_name)
19
+
20
+ report = master_data.verify!(verify_config: verify_config, ignore_fail: false)
21
+ report.print(printer: report_printer)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ attr_reader :spec_config, :verify_config, :silent, :override_identifier, :report_printer
28
+
29
+ def build_master_data_collection
30
+ MasterDataCollection.new.tap do |collection|
31
+ MasterDataTool::MasterDataFileCollection.new(spec_name: spec_config.spec_name, override_identifier: override_identifier).each do |master_data_file|
32
+ master_data = MasterData.build(spec_config: spec_config, master_data_file: master_data_file, load: true)
33
+ collection.append(master_data: master_data)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "verify/config"
4
+ require_relative "verify/executor"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MasterDataTool
4
- VERSION = "0.22.0"
4
+ VERSION = "0.23.0"
5
5
  end
@@ -3,6 +3,7 @@
3
3
  require 'csv'
4
4
  require 'socket'
5
5
  require_relative "master_data_tool/version"
6
+ require_relative "master_data_tool/act_as_master_data"
6
7
  require_relative "master_data_tool/config"
7
8
  require_relative "master_data_tool/spec_config"
8
9
  require_relative "master_data_tool/master_data_status"
@@ -11,8 +12,10 @@ require_relative "master_data_tool/master_data_file_collection"
11
12
  require_relative "master_data_tool/master_data"
12
13
  require_relative "master_data_tool/master_data_collection"
13
14
  require_relative "master_data_tool/report"
14
- require_relative "master_data_tool/dump/executor"
15
+ require_relative "master_data_tool/dump"
15
16
  require_relative "master_data_tool/import"
17
+ require_relative "master_data_tool/verify"
18
+ require_relative "master_data_tool/command"
16
19
 
17
20
  module MasterDataTool
18
21
  class Error < StandardError; end
@@ -33,10 +36,25 @@ module MasterDataTool
33
36
  yield config
34
37
  end
35
38
 
36
- def resolve_table_name(spec_name, csv_path, override_identifier)
39
+ def resolve_table_name(spec_name:, csv_path:, override_identifier:)
37
40
  # 0001_table_nameのように投入順序を制御可能にする
38
- relative_path = MasterDataTool.config.csv_dir_for(spec_name, override_identifier)
41
+ relative_path = MasterDataTool.config.csv_dir_for(spec_name: spec_name, override_identifier: override_identifier)
39
42
  csv_path.relative_path_from(relative_path).to_s.gsub(/^\d+_/, '').delete_suffix('.csv')
40
43
  end
44
+
45
+ # 1. onlyを指定した時点でそのリストに含まれるものだけになるべき
46
+ # 2. exceptのリストはどんな状況でも除外されるべき
47
+ # 3. それ以外はすべて実行する
48
+ def need_skip_table?(table_name, only, except)
49
+ only_result = only.presence&.include?(table_name)
50
+ except_result = except.presence&.include?(table_name)
51
+
52
+ # onlyが指定された時点でデフォルトはskipとする
53
+ default = only_result.nil? ? false : true
54
+ return true if except_result == true
55
+ return false if only_result == true
56
+
57
+ default
58
+ end
41
59
  end
42
60
  end