Skip to content

Instantly share code, notes, and snippets.

@0x1eef
Created March 16, 2023 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0x1eef/1e573560cad7dd98cb355df44f0a2c42 to your computer and use it in GitHub Desktop.
Save 0x1eef/1e573560cad7dd98cb355df44f0a2c42 to your computer and use it in GitHub Desktop.
read_options = ->(env:) do
path = File.join(Dir.getwd, "srv", env, "options.yml")
Ryo.from(YAML.load_file(path))
end
task "config:build", :env do |task, args|
options = read_options.call(**args)
b = binding.tap { |b| Ryo.each(options) { |k,v| b.local_variable_set(k, v) } }
glob = File.join(Dir.getwd, "srv", args[:env], "etc", "*.conf.erb")
etc_files = Dir.glob(glob)
etc_files.each do |file|
File.binwrite File.join(File.dirname(file), File.basename(file, ".erb")),
ERB.new(File.binread(file), trim_mode: "-").result(b)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment