Class: Envs::EnvFile
- Inherits:
-
Hash
- Object
- Hash
- Envs::EnvFile
- Defined in:
- lib/envs/env_file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #[]=(key, value) ⇒ Object
-
#initialize(path) ⇒ EnvFile
constructor
A new instance of EnvFile.
- #parse ⇒ Object
Constructor Details
#initialize(path) ⇒ EnvFile
Returns a new instance of EnvFile.
5 6 7 8 |
# File 'lib/envs/env_file.rb', line 5 def initialize(path) @path = path parse if exist? end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
3 4 5 |
# File 'lib/envs/env_file.rb', line 3 def path @path end |
Instance Method Details
#[]=(key, value) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/envs/env_file.rb', line 24 def []=(key, value) super(key, value) File.open(@path, "a") do |f| f << "#{key}=#{value}\n" end end |
#parse ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/envs/env_file.rb', line 10 def parse new_hash = {} File.open(@path).each_line do |line| case line when /^\s*$/, /^#/ # ignore else line.chomp key, value = line.split('=', 2) new_hash[key] = value.strip end end update(new_hash) end |