Class: BaseEnvironmentVariables

Inherits:
Object
  • Object
show all
Defined in:
lib/autosparkle/environment/variables/base_environment_variables.rb

Overview

The base envrionment variables class

Instance Method Summary collapse

Constructor Details

#initialize(variables) ⇒ BaseEnvironmentVariables

Returns a new instance of BaseEnvironmentVariables.



7
8
9
# File 'lib/autosparkle/environment/variables/base_environment_variables.rb', line 7

def initialize(variables)
  @variables = variables
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *arguments, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/autosparkle/environment/variables/base_environment_variables.rb', line 11

def method_missing(method_name, *arguments, &block)
  key = method_name.to_sym
  if @variables.key?(key)
    value = ENV.fetch(@variables[key], nil)
    raise "#{@variables[key]} is not defined in the environment variables" if value.nil? || value.empty?

    value
  else
    super
  end
end

Instance Method Details

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

Returns:

  • (Boolean)


23
24
25
# File 'lib/autosparkle/environment/variables/base_environment_variables.rb', line 23

def respond_to_missing?(method_name, include_private = false)
  @variables.key?(method_name.to_sym) || super
end