Class: Tzispa::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/tzispa/env.rb

Instance Method Summary collapse

Constructor Details

#initialize(env: ENV) ⇒ Env

Returns a new instance of Env.



8
9
10
# File 'lib/tzispa/env.rb', line 8

def initialize(env: ENV)
  @env = env
end

Instance Method Details

#[](key) ⇒ Object



12
13
14
# File 'lib/tzispa/env.rb', line 12

def [](key)
  @env[key]
end

#[]=(key, value) ⇒ Object



16
17
18
# File 'lib/tzispa/env.rb', line 16

def []=(key, value)
  @env[key] = value
end

#load!(path) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tzispa/env.rb', line 20

def load!(path)
  return unless defined?(Dotenv)

  contents = ::File.open(path, 'rb:bom|utf-8', &:read)
  parsed   = Dotenv::Parser.call(contents)

  parsed.each do |k, v|
    next if @env.key?(k)
    @env[k] = v
  end
  nil
end