Class: Dotenv::EnvTemplate
- Inherits:
-
Object
- Object
- Dotenv::EnvTemplate
- Defined in:
- lib/dotenv/template.rb
Overview
Class for creating a template from a env file
Instance Method Summary collapse
- #create_template ⇒ Object
-
#initialize(env_file) ⇒ EnvTemplate
constructor
A new instance of EnvTemplate.
- #template_line(line) ⇒ Object
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_template ⇒ Object
9 10 11 12 13 14 15 16 17 |
# 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| env_template.puts template_line(line) end end end end |
#template_line(line) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/dotenv/template.rb', line 19 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 |