Module: RuneRb::Utils::Environment

Included in:
RuneRb
Defined in:
lib/rrb/utils/environment.rb

Overview

A module responsible for loading environmental vars..

Since:

  • 0.0.1

Instance Method Summary collapse

Instance Method Details

#init_env(fetch: false, force: false) ⇒ Object

Loads environmental variables and creates necessary directories.

Since:

  • 0.0.1



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rrb/utils/environment.rb', line 7

def init_env(fetch: false, force: false)
  FileUtils.mkdir_p('data') unless File.exist?('data')
  FileUtils.mkdir_p('data/logs') unless File.exist?('data/logs')
  FileUtils.touch(RuneRb::Utils::Logging::LOG_FILE_PATH) unless File.exist?(RuneRb::Utils::Logging::LOG_FILE_PATH)
  Dir['data/*.env'].each { FileUtils.rm(_1) } if force

  if File.exist?('data/rrb.env') || File.exist?('data/sample-rrb.env')
    Dotenv.load(File.exist?('data/rrb.env') ? 'data/rrb.env' : 'data/sample-rrb.env')
  elsif fetch
    IO.copy_stream(URI.open('https://git.repos.pw/rune.rb/app/-/snippets/1/raw/main/sample-rrb.env'), 'data/sample-rrb.env')
    init_env(fetch: false)
  else
    raise(StandardError, 'No rrb.env file found!')
  end
  nil
end