Class: Dotenv::Environment
- Inherits:
-
Hash
- Object
- Hash
- Dotenv::Environment
- 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
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #apply ⇒ Object
- #apply! ⇒ Object
-
#initialize(filename, is_load = false) ⇒ Environment
constructor
A new instance of Environment.
- #load(is_load = false) ⇒ Object
- #read ⇒ Object
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
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/dotenv/environment.rb', line 5 def filename @filename end |
Instance Method Details
#apply ⇒ Object
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 |
#read ⇒ Object
16 17 18 |
# File 'lib/dotenv/environment.rb', line 16 def read File.open(@filename, "rb:bom|utf-8", &:read) end |