Class: Parse::Hyperdrive

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/stack.rb

Overview

Special class to support Modernistik Hyperdrive server.

Class Method Summary collapse

Class Method Details

.config!(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 environment value in 'CONFIG_URL' or 'HYPERDRIVE_URL'.

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.


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/parse/stack.rb', line 25

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