Method: Sideload#update!

Defined in:
lib/sideload.rb

#update!(sources) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sideload.rb', line 21

def update!(sources)
  scope, arg, _config, validate = sources.shift
  mod = const_get(scope.to_s.capitalize)
  contents = mod.read(*arg)
  unless sources.empty?
    next_layer = update!(sources)
    unless next_layer.nil?
      (contents.keys | next_layer.keys).each do |key|
        if !next_layer.has_key?(key)
          mod.with(arg, key) do |fp, t|
            mod.delete(fp, t)
          end
        else
          mod.with(arg, key) do |fp, t|
            mod.write(fp, t, next_layer[key], &validate)
          end
        end
      end
      contents = mod.read(arg)
    end
  end
  contents.each(&Proc.new) if block_given?
  return contents
rescue ValidationError => e
  if @logger
    @logger.error { [e.class, e.message].inspect }
    @logger.debug { e.backtrace.join("\n") }
  end
  return nil
end