master_data_tool 0.16.0 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09f03f9ca56ad09dd1f511a53248da3ffe917a0e8be0dba68e3bfbb8f61f74bb'
4
- data.tar.gz: 56d9f18f92c96ca4cf2f5bac42edc369d861cbf1cb3ba3e39cb6c8b19eccbdc0
3
+ metadata.gz: 13d917fbfac12aeef06fb5d23478b0b7a72cb7d322307650097cf7b9bbfc2154
4
+ data.tar.gz: 55e5a9eaf6fb6605e3c81db67e416b9b194ba38dd68f7f52646e2d6aed1f4bb4
5
5
  SHA512:
6
- metadata.gz: 229dc35b454ca6adafddc65125042649172d203a87554fbe161cade5ad6f17c9e645c40108cb37a937cbf1bfa496b06f0ad6406e904e706a7945b4a9ffe9bb2f
7
- data.tar.gz: 285b4f485f23c1215b8029af39bac2808a85050506e02cb92e1662ddaf0ccf634f9a8de4b821663f297d78f6e8a74d61a0920af4e2570ebe19200a0d1ec2f121
6
+ metadata.gz: c786f48fffb282a462c5daff7dc238c2021113d79590b6bcfc3a5f9d001a153e0db298b958f99548f12d0f4c09f69ed7b254c3b03e7e29655bc67d3b299c2476
7
+ data.tar.gz: cf6f31dbe36c37e82ac9fbed099b02e93ac721fc31676288cc3f5b2905502a85b2e919517f0bdc60e3a793f5ab525de4bef597c335ac254b53c168eb7f0a12b1
@@ -33,17 +33,17 @@ module MasterDataTool
33
33
  ApplicationRecord.transaction do
34
34
  print_execute_options
35
35
 
36
- master_data_list = build_master_data_list
36
+ master_data_collection = build_master_data_collection
37
37
 
38
- import_all!(master_data_list)
39
- verify_all!(master_data_list) if @verify
40
- save_master_data_statuses!(master_data_list)
38
+ import_all!(master_data_collection)
39
+ verify_all!(master_data_collection) if @verify
40
+ save_master_data_statuses!(master_data_collection)
41
41
 
42
- print_affected_tables(master_data_list)
42
+ print_affected_tables(master_data_collection)
43
43
 
44
44
  raise DryRunError if @dry_run
45
45
 
46
- master_data_list
46
+ master_data_collection
47
47
  end
48
48
  rescue DryRunError
49
49
  puts "[DryRun] end"
@@ -61,22 +61,18 @@ module MasterDataTool
61
61
  puts "================="
62
62
  end
63
63
 
64
- def build_master_data_list
65
- [].tap do |master_data_list|
66
- MasterDataTool::Import::MasterDataFileList.new(override_identifier: @override_identifier).build.each do |master_data_file|
64
+ def build_master_data_collection
65
+ MasterDataCollection.new.tap do |collection|
66
+ MasterDataTool::MasterDataFileCollection.new(override_identifier: @override_identifier).each do |master_data_file|
67
67
  load_skip = load_skip_table?(master_data_file)
68
-
69
- model_klass = Object.const_get(master_data_file.table_name.classify)
70
- master_data = MasterData.new(master_data_file, model_klass)
71
- master_data.load unless load_skip
72
-
73
- master_data_list << master_data
68
+ master_data = MasterData.build(master_data_file, load: !load_skip)
69
+ collection.append(master_data)
74
70
  end
75
- end.sort_by { |m| m.basename } # 外部キー制約などがある場合には先に入れておかないといけないデータなどがある。なので、プレフィックスを付けて順序を指定して貰う
71
+ end
76
72
  end
77
73
 
78
- def import_all!(master_data_list)
79
- master_data_list.each do |master_data|
74
+ def import_all!(master_data_collection)
75
+ master_data_collection.each do |master_data|
80
76
  next unless master_data.loaded?
81
77
  next if import_skip_table?(master_data.table_name)
82
78
 
@@ -85,8 +81,8 @@ module MasterDataTool
85
81
  end
86
82
  end
87
83
 
88
- def verify_all!(master_data_list)
89
- master_data_list.each do |master_data|
84
+ def verify_all!(master_data_collection)
85
+ master_data_collection.each do |master_data|
90
86
  next if verify_skip_table?(master_data.table_name)
91
87
 
92
88
  report = master_data.verify!(ignore_fail: @dry_run)
@@ -94,9 +90,9 @@ module MasterDataTool
94
90
  end
95
91
  end
96
92
 
97
- def save_master_data_statuses!(master_data_list)
93
+ def save_master_data_statuses!(master_data_collection)
98
94
  records = []
99
- master_data_list.each do |master_data|
95
+ master_data_collection.each do |master_data|
100
96
  next unless master_data.loaded?
101
97
 
102
98
  records << MasterDataTool::MasterDataStatus.build(master_data.master_data_file)
@@ -105,8 +101,8 @@ module MasterDataTool
105
101
  MasterDataTool::MasterDataStatus.import_records!(records, dry_run: @dry_run)
106
102
  end
107
103
 
108
- def print_affected_tables(master_data_list)
109
- master_data_list.each do |master_data|
104
+ def print_affected_tables(master_data_collection)
105
+ master_data_collection.each do |master_data|
110
106
  next unless master_data.loaded?
111
107
  next unless master_data.affected?
112
108
 
@@ -1,4 +1,3 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'import/master_data_file_list'
4
3
  require_relative "import/executor"
@@ -19,6 +19,15 @@ module MasterDataTool
19
19
  @deleted_records = []
20
20
  end
21
21
 
22
+ class << self
23
+ def build(master_data_file, load: false)
24
+ model_klass = Object.const_get(master_data_file.table_name.classify)
25
+ new(master_data_file, model_klass).tap do |record|
26
+ record.load if load
27
+ end
28
+ end
29
+ end
30
+
22
31
  def basename
23
32
  @master_data_file.basename
24
33
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MasterDataTool
4
+ class MasterDataCollection
5
+ def initialize
6
+ @collection = []
7
+ end
8
+
9
+ def append(master_data)
10
+ @collection << master_data
11
+ end
12
+
13
+ def each
14
+ return enum_for(:each) unless block_given?
15
+
16
+ @collection.sort_by(&:basename).each do |master_data|
17
+ yield master_data
18
+ end
19
+ end
20
+
21
+ def to_a
22
+ each.to_a
23
+ end
24
+ end
25
+ end
@@ -1,13 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
  module MasterDataTool
3
- class MasterDataFile < Struct.new(:table_name, :path, :override_identifier)
3
+ class MasterDataFile
4
+ attr_reader :table_name, :path, :override_identifier
5
+
4
6
  def initialize(table_name, path, override_identifier)
5
- super(table_name, path, override_identifier)
7
+ @table_name = table_name
8
+ @path = path
9
+ @override_identifier = override_identifier
6
10
  freeze
7
11
  end
8
12
 
13
+ class << self
14
+ def build(path, override_identifier)
15
+ table_name = MasterDataTool.resolve_table_name(path, override_identifier)
16
+ new(table_name, path, override_identifier)
17
+ end
18
+ end
19
+
9
20
  def basename
10
- self.path.basename
21
+ @path.basename
22
+ end
23
+
24
+ def ==(other)
25
+ other.class === self &&
26
+ other.hash == hash
27
+ end
28
+
29
+ alias eql? ==
30
+
31
+ def hash
32
+ [@table_name, @path, @override_identifier].join.hash
11
33
  end
12
34
  end
13
35
  end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MasterDataTool
4
+ class MasterDataFileCollection
5
+ def initialize(override_identifier: nil)
6
+ @override_identifier = override_identifier
7
+ @collection = build
8
+ freeze
9
+ end
10
+
11
+ def each
12
+ return enum_for(:each) unless block_given?
13
+
14
+ @collection.each do |file|
15
+ yield file
16
+ end
17
+ end
18
+
19
+ def to_a
20
+ each.to_a
21
+ end
22
+
23
+ private
24
+
25
+ def build
26
+ files = extract_master_data_csv_paths.presence&.index_by(&:table_name)
27
+ overridden_files = overridden_master_data_csv_paths.presence&.index_by(&:table_name) || {}
28
+
29
+ table_names = (files.keys + overridden_files.keys).uniq
30
+ table_names.map do |table_name|
31
+ overridden_files[table_name] || files[table_name]
32
+ end
33
+ end
34
+
35
+ def extract_master_data_csv_paths
36
+ pattern = Pathname.new(MasterDataTool.config.master_data_dir).join('*.csv').to_s
37
+ Pathname.glob(pattern).select(&:file?).map do |path|
38
+ MasterDataFile.build(path, nil)
39
+ end
40
+ end
41
+
42
+ def overridden_master_data_csv_paths
43
+ return [] if @override_identifier.blank?
44
+
45
+ pattern = Pathname.new(MasterDataTool.config.master_data_dir).join(@override_identifier).join('*.csv').to_s
46
+ Pathname.glob(pattern).select(&:file?).map do |path|
47
+ MasterDataFile.build(path, @override_identifier)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MasterDataTool
4
- VERSION = "0.16.0"
4
+ VERSION = "0.17.0"
5
5
  end
@@ -5,7 +5,9 @@ require_relative "master_data_tool/version"
5
5
  require_relative "master_data_tool/config"
6
6
  require_relative "master_data_tool/master_data_status"
7
7
  require_relative "master_data_tool/master_data_file"
8
+ require_relative "master_data_tool/master_data_file_collection"
8
9
  require_relative "master_data_tool/master_data"
10
+ require_relative "master_data_tool/master_data_collection"
9
11
  require_relative "master_data_tool/report"
10
12
  require_relative "master_data_tool/dump/executor"
11
13
  require_relative "master_data_tool/import"
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/master_data_tool/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "master_data_tool"
7
+ spec.version = MasterDataTool::VERSION
8
+ spec.authors = ["Takahiro Ooishi"]
9
+ spec.email = ["taka0125@gmail.com"]
10
+
11
+ spec.summary = "マスタデータの管理ツール"
12
+ spec.description = "システムが稼働する上で最初から必要なデータ(マスタデータ)を管理するツールです。"
13
+ spec.homepage = "https://github.com/taka0125/master_data_tool"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+
19
+ # Specify which files should be added to the gem when it is released.
20
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
21
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
22
+ `git ls-files -z`.split("\x0").reject do |f|
23
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
24
+ end
25
+ end
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency 'rspec'
31
+ spec.add_development_dependency 'mysql2'
32
+ spec.add_development_dependency 'psych', '~> 3.1'
33
+ spec.add_development_dependency 'appraisal'
34
+ spec.add_development_dependency 'ridgepole'
35
+ spec.add_development_dependency 'database_cleaner-active_record'
36
+ spec.add_development_dependency 'standalone_activerecord_boot_loader'
37
+
38
+ spec.add_dependency 'activerecord', '>= 5.1.7'
39
+ spec.add_dependency 'activesupport'
40
+ spec.add_dependency 'thor'
41
+ spec.add_dependency 'activerecord-import'
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: master_data_tool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takahiro Ooishi
@@ -194,9 +194,10 @@ files:
194
194
  - lib/master_data_tool/dump/executor.rb
195
195
  - lib/master_data_tool/import.rb
196
196
  - lib/master_data_tool/import/executor.rb
197
- - lib/master_data_tool/import/master_data_file_list.rb
198
197
  - lib/master_data_tool/master_data.rb
198
+ - lib/master_data_tool/master_data_collection.rb
199
199
  - lib/master_data_tool/master_data_file.rb
200
+ - lib/master_data_tool/master_data_file_collection.rb
200
201
  - lib/master_data_tool/master_data_status.rb
201
202
  - lib/master_data_tool/report.rb
202
203
  - lib/master_data_tool/report/core.rb
@@ -207,6 +208,7 @@ files:
207
208
  - lib/master_data_tool/report/verify_report.rb
208
209
  - lib/master_data_tool/version.rb
209
210
  - log/test.log
211
+ - master_data_tool.gemspec
210
212
  - scripts/setup.sh
211
213
  - sig/master_data_tool.rbs
212
214
  homepage: https://github.com/taka0125/master_data_tool
@@ -229,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
231
  - !ruby/object:Gem::Version
230
232
  version: '0'
231
233
  requirements: []
232
- rubygems_version: 3.0.3
234
+ rubygems_version: 3.2.22
233
235
  signing_key:
234
236
  specification_version: 4
235
237
  summary: マスタデータの管理ツール
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module MasterDataTool
4
- module Import
5
- class MasterDataFileList
6
- Result = Struct.new(:table_name, :path, :override_identifier)
7
-
8
- def initialize(override_identifier: nil)
9
- @override_identifier = override_identifier
10
- end
11
-
12
- def build
13
- files = extract_master_data_csv_paths.presence&.index_by(&:table_name)
14
- overridden_files = overridden_master_data_csv_paths.presence&.index_by(&:table_name) || {}
15
-
16
- table_names = (files.keys + overridden_files.keys).uniq
17
- table_names.map do |table_name|
18
- overridden_files[table_name] || files[table_name]
19
- end
20
- end
21
-
22
- private
23
-
24
- def extract_master_data_csv_paths
25
- pattern = Pathname.new(MasterDataTool.config.master_data_dir).join('*.csv').to_s
26
- Pathname.glob(pattern).select(&:file?).map do |path|
27
- table_name = MasterDataTool.resolve_table_name(path, nil)
28
- MasterDataTool::MasterDataFile.new(table_name, path, nil)
29
- end
30
- end
31
-
32
- def overridden_master_data_csv_paths
33
- return [] if @override_identifier.blank?
34
-
35
- pattern = Pathname.new(MasterDataTool.config.master_data_dir).join(@override_identifier).join('*.csv').to_s
36
- Pathname.glob(pattern).select(&:file?).map do |path|
37
- table_name = MasterDataTool.resolve_table_name(path, @override_identifier)
38
- MasterDataTool::MasterDataFile.new(table_name, path, @override_identifier)
39
- end
40
- end
41
- end
42
- end
43
- end