Class: Dotenv::Environment

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

Overview

This class inherits from Hash and represents the environment into which Dotenv will load key value pairs from a file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, is_load = false) ⇒ Environment

Returns a new instance of Environment.



7
8
9
10
# File 'lib/dotenv/environment.rb', line 7

def initialize(filename, is_load = false)
  @filename = filename
  load(is_load)
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



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

def filename
  @filename
end

Instance Method Details

#applyObject



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

def apply
  each { |k, v| ENV[k] ||= v }
end

#apply!Object



24
25
26
# File 'lib/dotenv/environment.rb', line 24

def apply!
  each { |k, v| ENV[k] = v }
end

#load(is_load = false) ⇒ Object



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

def load(is_load = false)
  update Parser.call(read, is_load)
end

#readObject



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

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