class EnvManager::Builder

Public Class Methods

new(file_contents) click to toggle source
# File lib/env_manager/builder.rb, line 5
def initialize(file_contents)
  build(file_contents)
end

Public Instance Methods

build(file_contents) click to toggle source
# File lib/env_manager/builder.rb, line 9
def build(file_contents)
  hash = dynamic_assignment(file_contents)
  hash.each do |key, value|
    instance_variable_set("@#{key}", value)
    self.class.send(:attr_accessor, key)
  end
end
env() click to toggle source
# File lib/env_manager/builder.rb, line 23
def env
  ::ENV['RACK_ENV']
end

Private Instance Methods

dynamic_assignment(content) click to toggle source

Builds a hash of the .env file Assigns values to the ENV global

# File lib/env_manager/builder.rb, line 31
def dynamic_assignment(content)
  return if content.nil? || content == ''
  content.split("\n").inject({}) do |hash, line|
    key, value = line.split('=')
    ::ENV[key] = value.strip

    hash[key.downcase.to_sym] = value.strip
    hash
  end
end