Class: Dotenvious::ValueReplacer

Inherits:
Object
  • Object
show all
Defined in:
lib/dotenvious/value_replacer.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ ValueReplacer

Returns a new instance of ValueReplacer.



3
4
5
# File 'lib/dotenvious/value_replacer.rb', line 3

def initialize(filename)
  @filename = filename
end

Instance Method Details

#replace(key) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/dotenvious/value_replacer.rb', line 7

def replace(key)
  line_number = base_env.find_index do |line|
    line.match(/^#{key}=/)
  end
  updated_env = base_env.dup
  updated_env[line_number] = "#{key}=#{ENV_EXAMPLE[key]}"
  env_writer.write(updated_env.join("\n") + "\n")
  env_writer.close
end