class Dotenv::EnvTemplate
Class for creating a template from a env file
Public Class Methods
new(env_file)
click to toggle source
# File lib/dotenv/template.rb, line 5 def initialize(env_file) @env_file = env_file end
Public Instance Methods
create_template()
click to toggle source
# File lib/dotenv/template.rb, line 9 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 Instance Methods
is_comment?(line)
click to toggle source
# File lib/dotenv/template.rb, line 31 def is_comment?(line) line.strip.start_with?("#") end
line_blank?(line)
click to toggle source
# File lib/dotenv/template.rb, line 40 def line_blank?(line) line.strip.length.zero? end
var_defined?(line)
click to toggle source
# File lib/dotenv/template.rb, line 35 def var_defined?(line) match = Dotenv::Parser::LINE.match(line) match && match[:key] end