Browse Source

env: fix scripts env loading

develop
Arthur POULET 9 months ago
parent
commit
f2ad52586f
Signed by: Sceptique GPG Key ID: C108A668349EE601
  1. 6
      init/load_env.rb
  2. 14
      src/app.rb
  3. 11
      src/utils/env.rb

6
init/load_env.rb

@ -1,10 +1,10 @@
require "sequel"
require "colorize"
require "dotenv"
Dotenv.load(".env.local", ".env")
require_relative "../src/utils/semver.rb"
require_relative "../src/utils/env"
require_relative "../src/utils/semver"
load_dotenv
DB = Sequel.connect ENV["LIFEPEX_DB"]
if ENV["environment"] == "debug"

14
src/app.rb

@ -18,16 +18,15 @@ require "active_support"
require "active_support/core_ext"
require "pry" # debug
# Load environment variables
require_relative "./utils/env"
module LifePex
APP_ENV = ENV.fetch("LIFEPEX_ENV") { "development" }
APP_ENV = load_dotenv
end
require "dotenv"
Dotenv.load(".env.#{LifePex::APP_ENV}.local", ".env.local", ".env")
# Initialize framework
require_relative "./utils/url.rb"
require_relative "./utils/boot_framework"
LifePex::BootFramework.boot_application do
harshly_need_env "LIFEPEX_DB"
kindly_ask_env "LIFEPEX_BASE_URL"
@ -40,6 +39,7 @@ LifePex::BootFramework.boot_application do
end
end.finish!
# Setup module variables
module LifePex
DB = Sequel.connect ENV["LIFEPEX_DB"]
BASE_URL = ENV["LIFEPEX_BASE_URL"] || "http://localhost:4567"
@ -53,6 +53,8 @@ module LifePex
end
end
# Then we load all the systems
Dir[File.join(__dir__, 'utils', '*.rb')].each { |file| require file }
require_relative "./achievements/dsl.rb"
@ -61,10 +63,12 @@ require_relative "./achievements/achievement.rb"
Dir[File.join(__dir__, 'models', '*.rb')].each { |file| require file }
Dir[File.join(__dir__, 'systems', '*.rb')].each { |file| require file }
# Static file serving in this file because it is overkill to create a file for this
class LifePex::Systems::PublicSystem < Sinatra::Base
set :public_folder, "public"
end
# Main app
class LifePex::App < Sinatra::Base
DocMyRoutes.configure do |config|
config.title = "LifePex"

11
src/utils/env.rb

@ -0,0 +1,11 @@
require "dotenv"
def get_env
ENV.fetch("LIFEPEX_ENV") { "development" }
end
def load_dotenv(app_env = nil)
app_env ||= get_env
Dotenv.load(".env.#{app_env}.local", ".env.local", ".env")
app_env
end
Loading…
Cancel
Save