Class: Hanami::Env Private
- Inherits:
-
Object
- Object
- Hanami::Env
- Defined in:
- lib/hanami/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.
Encapsulate access to ENV
Instance Method Summary collapse
-
#[](key) ⇒ String, NilClass
private
Return a value, if found.
-
#[]=(key, value) ⇒ Object
private
Sets a value.
-
#initialize(env: ENV) ⇒ Hanami::Env
constructor
private
Create a new instance.
-
#load!(path) ⇒ Object
private
Loads a dotenv file and updates self.
Constructor Details
#initialize(env: ENV) ⇒ Hanami::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
20 21 22 |
# File 'lib/hanami/env.rb', line 20 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
32 33 34 |
# File 'lib/hanami/env.rb', line 32 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.
Sets a value
43 44 45 |
# File 'lib/hanami/env.rb', line 43 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.
Loads a dotenv file and updates self
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hanami/env.rb', line 55 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.has_key?(k) @env[k] = v end nil end |