Class: Jets::Dotenv
- Inherits:
-
Object
- Object
- Jets::Dotenv
- Defined in:
- lib/jets/dotenv.rb,
lib/jets/dotenv/ssm.rb,
lib/jets/dotenv/show.rb
Defined Under Namespace
Class Method Summary collapse
Instance Method Summary collapse
-
#dotenv_files ⇒ Object
dotenv files with the following precedence:.
-
#initialize(remote = false) ⇒ Dotenv
constructor
A new instance of Dotenv.
- #load! ⇒ Object
- #on_aws? ⇒ Boolean
- #root ⇒ Object
Constructor Details
#initialize(remote = false) ⇒ Dotenv
Returns a new instance of Dotenv.
8 9 10 |
# File 'lib/jets/dotenv.rb', line 8 def initialize(remote=false) @remote = ENV['JETS_ENV_REMOTE'] || remote end |
Class Method Details
.load!(remote = false) ⇒ Object
4 5 6 |
# File 'lib/jets/dotenv.rb', line 4 def self.load!(remote=false) new(remote).load! end |
Instance Method Details
#dotenv_files ⇒ Object
dotenv files with the following precedence:
-
.env.development.jets_env_extra (highest)
-
.env.development.remote (2nd highest, only if JETS_ENV_REMOTE=1)
-
.env.development.local (unless JETS_ENV_REMOTE=1)
-
.env.development
-
.env.local - This file is loaded for all environments except ‘test` or unless JETS_ENV_REMOTE=1
-
.env - The original (lowest)
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/jets/dotenv.rb', line 31 def dotenv_files files = [ root.join(".env"), (root.join(".env.local") unless (Jets.env.test? || @remote)), root.join(".env.#{Jets.env}"), (root.join(".env.#{Jets.env}.local") unless @remote), ] files << root.join(".env.#{Jets.env}.remote") if @remote if ENV["JETS_ENV_EXTRA"] files << root.join(".env.#{Jets.env}.#{ENV["JETS_ENV_EXTRA"]}") end files.compact end |
#load! ⇒ Object
12 13 14 15 16 |
# File 'lib/jets/dotenv.rb', line 12 def load! return if on_aws? # this prevents ssm calls if used in dotenv files vars = ::Dotenv.load(*dotenv_files) Ssm.new(vars).interpolate! end |
#on_aws? ⇒ Boolean
18 19 20 |
# File 'lib/jets/dotenv.rb', line 18 def on_aws? !!ENV['_HANDLER'] # https://docs.aws.amazon.com/lambda/latest/dg/lambda-environment-variables.html end |