class DotEnv::Environment

Attributes

cmdline_args[RW]
test_file_words[RW]
test_runner_words[RW]

Public Class Methods

new(parser, command_line_args) click to toggle source
# File lib/dot_env/environment.rb, line 7
def initialize(parser, command_line_args)
  @parser = parser
  @cmdline_args = command_line_args
  @test_runner_words = ['spec', 'rspec', 'cucumber']
  @test_file_words = ['test', 'spec', 'feature']
end

Public Instance Methods

check_if_testing() click to toggle source
# File lib/dot_env/environment.rb, line 39
def check_if_testing
  test_runner = check_test_runner
  test_file = nil
  @cmdline_args.each { |a| test_file = check_test_file(a) if test_file.nil? }
  current_env = test_runner || test_file
end
check_test_file(argword) click to toggle source
# File lib/dot_env/environment.rb, line 31
def check_test_file(argword)
  @test_file_words.each do |word|
    return 'testing' if argword.include? word
  end

  nil
end
check_test_runner() click to toggle source
# File lib/dot_env/environment.rb, line 23
def check_test_runner
  @test_runner_words.each do |word|
    return 'testing' if @cmdline_args.include? word
  end

  nil
end
fetch(key, default=nil) click to toggle source
# File lib/dot_env/environment.rb, line 14
def fetch(key, default=nil)
  value = ENV.fetch(key, default)
  value = @parser.parse(value) unless value.nil?
end
get_current() click to toggle source
# File lib/dot_env/environment.rb, line 50
def get_current
  check_if_testing || fetch('APP_ENV', 'development')
end
set(key, value) click to toggle source
# File lib/dot_env/environment.rb, line 19
def set(key, value)
  ENV[key] = value
end
set_current(env) click to toggle source
# File lib/dot_env/environment.rb, line 46
def set_current(env)
  set('APP_ENV', env)
end