Module: Sideload

Extended by:
Sideload
Included in:
Sideload
Defined in:
lib/sideload.rb,
lib/sideload/path.rb,
lib/sideload/redis.rb,
lib/sideload/config.rb,
lib/sideload/github.rb,
lib/sideload/version.rb,
lib/sideload/validation_error.rb

Defined Under Namespace

Modules: Github, Path, Redis Classes: Config, ValidationError

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Instance Method Details

#init {|c| ... } ⇒ Object

Yields:

  • (c)


15
16
17
18
19
# File 'lib/sideload.rb', line 15

def init
  c = Config.new
  yield(c)
  return c
end

#logger=(logger) ⇒ Object



11
12
13
# File 'lib/sideload.rb', line 11

def logger=(logger)
  @logger = logger
end

#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