Class: WarpCore::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/warpcore/config.rb

Overview

Class provides a helper method to load

Class Method Summary collapse

Class Method Details

.load_url!(url = nil) ⇒ Boolean

Applies a remote JSON hash containing the ENV keys and values from a remote URL. Values from the JSON hash are only applied to the current ENV hash ONLY if it does not already have a value. Therefore local ENV values will take precedence over remote ones. By default, it uses the url in value in ENV.

Parameters:

  • url (String) (defaults to: nil)

    the remote url that responds with the JSON body.

Returns:

  • (Boolean)

    true if the JSON hash was found and applied successfully.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/warpcore/config.rb', line 14

def self.load_url!(url = nil)
  url ||= ENV["ENV_URL"]
  if url.present?
    begin
      remote_config = JSON.load open( url )
      remote_config.each do |key,value|
        k = key.upcase
        ENV[k] ||= value.to_s
      end
      return true
    rescue => e
      warn "[WarpCore::Config] Error loading config: #{url} (#{e})"
    end
  end
  false
end