Class: Dotenv::Environment

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

Overview

A ‘.env` file that will be read and parsed into a Hash

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, overwrite: false) ⇒ Environment

Create a new Environment

Parameters:

  • filename (String)

    the path to the file to read

  • overwrite (Boolean) (defaults to: false)

    whether the parser should assume existing values will be overwritten



10
11
12
13
14
15
# File 'lib/dotenv/environment.rb', line 10

def initialize(filename, overwrite: false)
  super()
  @filename = filename
  @overwrite = overwrite
  load
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



4
5
6
# File 'lib/dotenv/environment.rb', line 4

def filename
  @filename
end

#overwriteObject (readonly)

Returns the value of attribute overwrite.



4
5
6
# File 'lib/dotenv/environment.rb', line 4

def overwrite
  @overwrite
end

Instance Method Details

#loadObject



17
18
19
# File 'lib/dotenv/environment.rb', line 17

def load
  update Parser.call(read, overwrite: overwrite)
end

#readObject



21
22
23
# File 'lib/dotenv/environment.rb', line 21

def read
  File.open(@filename, "rb:bom|utf-8", &:read)
end