Sha256: 0f99e6a78e97b2108283a238f6173dce676d4c29a5ab6671c88726107310e05e
Contents?: true
Size: 1.03 KB
Versions: 3
Compression:
Stored size: 1.03 KB
Contents
module Dotenv EXPORT_COMMAND = "export ".freeze # Class for creating a template from a env file class EnvTemplate def initialize(env_file) @env_file = env_file end def create_template File.open(@env_file, "r") do |env_file| File.open("#{@env_file}.template", "w") do |env_template| env_file.each do |line| if is_comment?(line) env_template.puts line elsif (var = var_defined?(line)) if line.match(EXPORT_COMMAND) env_template.puts "export #{var}=#{var}" else env_template.puts "#{var}=#{var}" end elsif line_blank?(line) env_template.puts end end end end end private def is_comment?(line) line.strip.start_with?("#") end def var_defined?(line) match = Dotenv::Parser::LINE.match(line) match && match[:key] end def line_blank?(line) line.strip.length.zero? end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
dotenv-3.1.7 | lib/dotenv/template.rb |
dotenv-3.1.6 | lib/dotenv/template.rb |
dotenv-3.1.5 | lib/dotenv/template.rb |