Class: MasterDataTool::MasterDataStatus
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MasterDataTool::MasterDataStatus
- Defined in:
- lib/master_data_tool/master_data_status.rb
Class Method Summary collapse
- .build(spec_name:, master_data_file:) ⇒ Object
- .decide_version(csv_path) ⇒ Object
- .import_records!(records:, dry_run: true) ⇒ Object
Instance Method Summary collapse
Class Method Details
.build(spec_name:, master_data_file:) ⇒ Object
27 28 29 30 31 |
# File 'lib/master_data_tool/master_data_status.rb', line 27 def build(spec_name:, master_data_file:) version = decide_version(master_data_file.path) name = MasterDataTool.resolve_table_name(spec_name: spec_name, csv_path: master_data_file.path, override_identifier: master_data_file.override_identifier) new(spec_name: spec_name, name: name, version: version) end |
.decide_version(csv_path) ⇒ Object
45 46 47 |
# File 'lib/master_data_tool/master_data_status.rb', line 45 def decide_version(csv_path) OpenSSL::Digest::SHA256.hexdigest(File.open(csv_path).read) end |
.import_records!(records:, dry_run: true) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/master_data_tool/master_data_status.rb', line 33 def import_records!(records:, dry_run: true) if dry_run pp records return end return if records.empty? import_records = records.map { |obj| obj.attributes.slice(*import_columns) } upsert_all(import_records, update_only: %w[version]) end |
Instance Method Details
#model_klass ⇒ Object
22 23 24 |
# File 'lib/master_data_tool/master_data_status.rb', line 22 def model_klass Object.const_get(name.classify) end |
#will_change?(master_data_file) ⇒ Boolean
16 17 18 19 20 |
# File 'lib/master_data_tool/master_data_status.rb', line 16 def will_change?(master_data_file) raise unless name == master_data_file.table_name version != self.class.decide_version(master_data_file.path) end |