Sha256: e86ed905d59b686de47150d798ba8f43222eff669b1fc3c13b4f4b99b46aafae

Contents?: true

Size: 1.09 KB

Versions: 9

Compression:

Stored size: 1.09 KB

Contents

module Cardio
  class Migration
    class Import
      # executes the card import
      class Merger
        def initialize data_path, opts={}
          @data_path = data_path
          @output_path = File.join data_path, "unmerged"
          @data = ImportData.load @data_path, opts
        end

        def merge
          puts("nothing to merge") && return if @data.empty?

          without_mail_deliveries do
            Card::Auth.as_bot do
              Card.merge_list @data, output_file: @output_path
            end

            update_import_data
          end
        end

        private

        def without_mail_deliveries
          m = Card::Mailer
          prior = m.perform_deliveries
          m.perform_deliveries = false
          yield
        ensure
          m.perform_deliveries = prior
        end

        def update_import_data
          update_time = Time.zone.now.to_s
          ImportData.update(@data_path) do |import_data|
            @data.each do |card_data|
              import_data.merged card_data, update_time
            end
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
card-1.104.2 lib/cardio/migration/import/merger.rb
card-1.104.1 lib/cardio/migration/import/merger.rb
card-1.104.0 lib/cardio/migration/import/merger.rb
card-1.103.4 lib/cardio/migration/import/merger.rb
card-1.103.3 lib/cardio/migration/import/merger.rb
card-1.103.2 lib/cardio/migration/import/merger.rb
card-1.103.1 lib/cardio/migration/import/merger.rb
card-1.103.0 lib/cardio/migration/import/merger.rb
card-1.102.0 lib/cardio/migration/import/merger.rb