Class: Mooncell::Env Private
- Inherits:
-
Object
- Object
- Mooncell::Env
- Defined in:
- lib/mooncell/env.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Environment container
Instance Method Summary collapse
-
#[](key) ⇒ String, NilClass
private
Return a value if found.
-
#[]=(key, value) ⇒ Object
private
Set a value.
-
#initialize(env: ENV) ⇒ Mooncell::Env
constructor
private
Create a new instance.
-
#load!(path) ⇒ Object
private
Load environment from dotenv.
Constructor Details
#initialize(env: ENV) ⇒ Mooncell::Env
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a new instance
19 20 21 |
# File 'lib/mooncell/env.rb', line 19 def initialize(env: ENV) @env = env end |
Instance Method Details
#[](key) ⇒ String, NilClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return a value if found
31 32 33 |
# File 'lib/mooncell/env.rb', line 31 def [](key) @env[key] end |
#[]=(key, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Set a value
42 43 44 |
# File 'lib/mooncell/env.rb', line 42 def []=(key, value) @env[key] = value end |
#load!(path) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load environment from dotenv
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/mooncell/env.rb', line 54 def load!(path) return unless defined?(Dotenv::Parser) 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 end |