Class: Dotenv::EnvTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/dotenv/template.rb

Overview

Class for creating a template from a env file

Instance Method Summary collapse

Constructor Details

#initialize(env_file) ⇒ EnvTemplate

Returns a new instance of EnvTemplate.



5
6
7
# File 'lib/dotenv/template.rb', line 5

def initialize(env_file)
  @env_file = env_file
end

Instance Method Details

#create_templateObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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