template.rb 686 B

1234567891011121314151617181920212223242526
  1. module Dotenv
  2. EXPORT_COMMAND = "export ".freeze
  3. # Class for creating a template from a env file
  4. class EnvTemplate
  5. def initialize(env_file)
  6. @env_file = env_file
  7. end
  8. def create_template
  9. File.open(@env_file, "r") do |env_file|
  10. File.open("#{@env_file}.template", "w") do |env_template|
  11. env_file.each do |line|
  12. env_template.puts template_line(line)
  13. end
  14. end
  15. end
  16. end
  17. def template_line(line)
  18. var, value = line.split("=")
  19. template = var.gsub(EXPORT_COMMAND, "")
  20. is_a_comment = var.strip[0].eql?("#")
  21. (value.nil? || is_a_comment) ? line : "#{var}=#{template}"
  22. end
  23. end
  24. end