class Dock0::Base

Base class for common methods

Attributes

config[R]

Public Class Methods

new(*configs) click to toggle source
# File lib/dock0.rb, line 31
def initialize(*configs)
  @config = configs.each_with_object(default_config) do |path, obj|
    new = YAML.load(File.read(path))
    next unless new
    obj.deep_merge! Cymbal.symbolize(new)
  end
  @paths = @config[:paths]
end

Public Instance Methods

cleanup(list) click to toggle source
# File lib/dock0.rb, line 79
def cleanup(list)
  puts "Removing: #{list.join(', ')}"
  FileUtils.rm_rf list
end
default_config() click to toggle source
# File lib/dock0.rb, line 40
def default_config
  { paths: { scripts: './scripts' } }
end
render_templates(prefix) click to toggle source
# File lib/dock0.rb, line 56
def render_templates(prefix)
  templates.each do |path|
    puts "Templating #{path}"
    template = File.read "#{@paths[:templates]}/#{path}"
    parsed = ERB.new(template, nil, '<>').result(binding)

    target_path = "#{@paths[:build]}/#{prefix}/#{path}"
    FileUtils.mkdir_p File.dirname(target_path)
    File.open(target_path, 'w') { |fh| fh.write parsed }
  end
end
run(cmd) click to toggle source
# File lib/dock0.rb, line 44
def run(cmd)
  results = `#{cmd} 2>&1`
  return results if $CHILD_STATUS.success?
  fail "Failed running #{cmd}:\n#{results}"
end
run_script(script) click to toggle source
# File lib/dock0.rb, line 68
def run_script(script)
  Dir.chdir('.') { instance_eval File.read(script), script, 0 }
end
run_scripts() click to toggle source
# File lib/dock0.rb, line 72
def run_scripts
  Dir.glob(@paths[:scripts] + '/*.rb').sort.each do |script|
    puts "Running #{script}"
    run_script script
  end
end
templates() click to toggle source
# File lib/dock0.rb, line 50
def templates
  Dir.chdir(@paths[:templates]) do
    Dir.glob('**/*').select { |x| File.file? x }
  end
end