Module: ImportManager::Conflicts

Included in:
ImportManager
Defined in:
lib/import_manager/conflicts.rb

Overview

Methods to deal with conflicts with existing cards

Instance Method Summary collapse

Instance Method Details

#check_for_duplicates(name) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/import_manager/conflicts.rb', line 8

def check_for_duplicates name
  key = name.to_name.key
  if @imported_keys.include? key
    report :duplicate_in_file, name
    throw :skip_row, :skipped
  else
    @imported_keys << key
  end
end

#duplicate(name) ⇒ Object



46
47
48
# File 'lib/import_manager/conflicts.rb', line 46

def duplicate name
  Card[name]
end

#handle_conflict(name, strategy: nil) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/import_manager/conflicts.rb', line 26

def handle_conflict name, strategy: nil
  with_conflict_strategy strategy do
    with_conflict_resolution name do |duplicate|
      yield duplicate
    end
  end
end

#override?Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/import_manager/conflicts.rb', line 4

def override?
  @conflict_strategy == :override
end

#with_conflict_resolution(name) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/import_manager/conflicts.rb', line 34

def with_conflict_resolution name
  return yield unless (dup = duplicate(name))

  case @conflict_strategy
  when :skip      then throw :skip_row, :skipped
  when :skip_card then dup
  else
    @status = :overridden
    yield dup
  end
end

#with_conflict_strategy(strategy) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/import_manager/conflicts.rb', line 18

def with_conflict_strategy strategy
  tmp_cs = @conflict_strategy
  @conflict_strategy = strategy if strategy
  yield
ensure
  @conflict_strategy = tmp_cs
end