Sha256: 0fc16c8de1eddcf542426b411fb27ba611cf0380d21825a822f42bc3017f2e38

Contents?: true

Size: 686 Bytes

Versions: 6

Compression:

Stored size: 686 Bytes

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|
            env_template.puts template_line(line)
          end
        end
      end
    end

    def template_line(line)
      var, value = line.split("=")
      template = var.gsub(EXPORT_COMMAND, "")
      is_a_comment = var.strip[0].eql?("#")
      (value.nil? || is_a_comment) ? line : "#{var}=#{template}"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dotenv-3.1.0 lib/dotenv/template.rb
dotenv-3.0.3 lib/dotenv/template.rb
dotenv-3.0.2 lib/dotenv/template.rb
dotenv-3.0.1 lib/dotenv/template.rb
dotenv-3.0.0 lib/dotenv/template.rb
dotenv-3.0.0.beta lib/dotenv/template.rb