Sha256: 6b7e15591fd7b58bbbddf994d2fb619f93e8b41fa2a2d52dfbf8a19657dcaaa3

Contents?: true

Size: 1.04 KB

Versions: 9

Compression:

Stored size: 1.04 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

    class << self
      def build(csv_path)
        version = decide_version(csv_path)
        new(name: MasterDataTool.resolve_table_name(csv_path), version: version)
      end

      def import_records!(records, dry_run: true)
        if dry_run
          pp records
        else
          import!(records, validate: true, on_duplicate_key_update: %w[name version], timestamps: true)
        end
      end

      def master_data_will_change?(csv_path)
        new_version = decide_version(csv_path)
        !where(name: MasterDataTool.resolve_table_name(csv_path), version: new_version).exists?
      end

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
master_data_tool-0.15.0 lib/master_data_tool/master_data_status.rb
master_data_tool-0.14.0 lib/master_data_tool/master_data_status.rb
master_data_tool-0.13.0 lib/master_data_tool/master_data_status.rb
master_data_tool-0.12.0 lib/master_data_tool/master_data_status.rb
master_data_tool-0.11.0 lib/master_data_tool/master_data_status.rb
master_data_tool-0.10.0 lib/master_data_tool/master_data_status.rb
master_data_tool-0.9.0 lib/master_data_tool/master_data_status.rb
master_data_tool-0.8.0 lib/master_data_tool/master_data_status.rb
master_data_tool-0.7.0 lib/master_data_tool/master_data_status.rb