Class: Karafka::Env

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

Overview

Env management class to get and set environment for Karafka

Instance Method Summary collapse

Constructor Details

#initializeKarafka::Env

Note:

Will load appropriate environment automatically

Returns env object.



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

def initialize
  super('')

  LOOKUP_ENV_KEYS
    .map { |key| ENV[key] }
    .compact
    .first
    .then { |env| env || DEFAULT_ENV }
    .then { |env| replace(env) }
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments) ⇒ Object

Reacts to missing methods, from which some might be the env checks. If the method ends with ‘?’ we assume, that it is an env check

Parameters:

  • method_name (String)

    method name for missing or env name with question mark

  • arguments (Array)

    any arguments that we pass to the method



42
43
44
# File 'lib/karafka/env.rb', line 42

def method_missing(method_name, *arguments)
  method_name[-1] == '?' ? self == method_name[0..-2] : super
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns true if we respond to a given missing method, otherwise false.

Parameters:

  • method_name (String)

    method name

  • include_private (Boolean) (defaults to: false)

    should we include private methods as well

Returns:

  • (Boolean)

    true if we respond to a given missing method, otherwise false



34
35
36
# File 'lib/karafka/env.rb', line 34

def respond_to_missing?(method_name, include_private = false)
  (method_name[-1] == '?') || super
end