class Dockerify::Runner
Constants
- DOCKERIFY_CONFIGS
Public Instance Methods
build(path)
click to toggle source
# File lib/dockerify/dockerify.rb, line 36 def build(path) absolute_path = full_path(path) DOCKERIFY_CONFIGS.map do |dockerify_config| file_path = "#{absolute_path}/#{dockerify_config[:filename]}" if File.exists?(file_path) puts "Skipping #{file_path}. File already exists" next end raw_template = load_template(dockerify_config[:filename]) erb_args = dockerify_config[:default_args].merge({}) rendered_template = render_erb(raw_template, erb_args) write_file(file_path, rendered_template) "Creating #{dockerify_config[:filename]} etc in #{file_path}" end end
remove(path)
click to toggle source
# File lib/dockerify/dockerify.rb, line 56 def remove(path) absolute_path = full_path(path) DOCKERIFY_CONFIGS.map do |dockerify_config| file_path = "#{absolute_path}/#{dockerify_config[:filename]}" next unless File.exists?(file_path) File.delete(file_path) "Deleting #{dockerify_config[:filename]} etc in #{file_path}" end end
Private Instance Methods
full_path(relative_path)
click to toggle source
# File lib/dockerify/dockerify.rb, line 85 def full_path(relative_path) File.expand_path(relative_path) end
load_template(template_name)
click to toggle source
# File lib/dockerify/dockerify.rb, line 74 def load_template(template_name) filename = File.dirname(__FILE__) + "/templates/#{template_name}.erb" File.read(filename) end
render_erb(template, vars)
click to toggle source
# File lib/dockerify/dockerify.rb, line 69 def render_erb(template, vars) renderer = ERB.new(template) renderer.result(OpenStruct.new(vars).instance_eval { binding }) end
write_file(filepath, contents)
click to toggle source
# File lib/dockerify/dockerify.rb, line 79 def write_file(filepath, contents) File.open(filepath, 'w') do |f| f.write(contents) end end