Class: Hanami::Env Private

Inherits:
Object
  • Object
show all
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

Since:

  • 0.9.0

Instance Method Summary collapse

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

Since:

  • 0.9.0


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

Since:

  • 0.9.0


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

Since:

  • 0.9.0


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

Since:

  • 0.9.0


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hanami/env.rb', line 55

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|
    @env[k] = v
  end
  nil
end