Module: Card::Set::All::Utils::ClassMethods

Defined in:
tmpsets/set/mod003-core/all/utils.rb

Instance Method Summary collapse

Instance Method Details

#merge(name, attribs = {}, opts = {}) ⇒ Object



38
39
40
41
42
43
44
45
# File 'tmpsets/set/mod003-core/all/utils.rb', line 38

def merge name, attribs={}, opts={}
  # puts "merging #{name}"
  card = fetch name, new: {}
  return unless mergeable? card, opts[:pristine]

  resolve_file_attributes! attribs
  card.safe_update! attribs
end

#merge_list(attribs, opts = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'tmpsets/set/mod003-core/all/utils.rb', line 9

def merge_list attribs, opts={}
  unmerged = []
  attribs.each do |row|
    if merge row["name"], row, opts
      Rails.logger.info "merged #{row['name']}"
    else
      unmerged.push row
    end
  end

  if unmerged.empty?
    Rails.logger.info "successfully merged all!"
  else
    unmerged_json = JSON.pretty_generate unmerged
    report_unmerged_json unmerged_json, opts[:output_file]
  end
  unmerged
end

#report_unmerged_json(unmerged_json, output_file) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'tmpsets/set/mod003-core/all/utils.rb', line 28

def report_unmerged_json unmerged_json, output_file
  if output_file
    ::File.open output_file, "w" do |f|
      f.write unmerged_json
    end
  else
    Rails.logger.info "failed to merge:\n\n#{unmerged_json}"
  end
end