Sha256: f6e2a785628d9c799ef48efa5874aa5f14c5b77030e3eb50a13278255763033a

Contents?: true

Size: 1.19 KB

Versions: 4

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

require 'active_record'
require 'activerecord-import'
require 'openssl'

module MasterDataTool
  class MasterDataStatus < ::ActiveRecord::Base
    self.table_name = 'master_data_statuses'

    validates :name,
              presence: true

    validates :version,
              presence: true

    def will_change?(master_data_file)
      raise unless name == master_data_file.table_name

      version != self.class.decide_version(master_data_file.path)
    end

    class << self
      def fetch_all
        all.index_by(&:name)
      end

      def build(spec_name, master_data_file)
        version = decide_version(master_data_file.path)
        new(spec_name: spec_name, name: MasterDataTool.resolve_table_name(spec_name, master_data_file.path, master_data_file.override_identifier), version: version)
      end

      def import_records!(records, dry_run: true)
        if dry_run
          pp records
          return
        end

        import!(records, validate: true, on_duplicate_key_update: %w[name version], timestamps: true)
      end

      def decide_version(csv_path)
        OpenSSL::Digest::SHA256.hexdigest(File.open(csv_path).read)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
master_data_tool-0.22.0 lib/master_data_tool/master_data_status.rb
master_data_tool-0.21.1 lib/master_data_tool/master_data_status.rb
master_data_tool-0.21.0 lib/master_data_tool/master_data_status.rb
master_data_tool-0.20.0 lib/master_data_tool/master_data_status.rb