Class: PlatformSH

Inherits:
Object
  • Object
show all
Defined in:
lib/platform_sh.rb,
lib/platform_sh/version.rb

Constant Summary collapse

VERSION =
"0.2.8"

Class Method Summary collapse

Class Method Details

.configObject

Reads Platform.sh configuration from environment and returns a single object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/platform_sh.rb', line 13

def self.config
  if on_platform?
    conf = {}
    conf["application"] = read_base64_json('PLATFORM_APPLICATION')
    conf["routes"] = read_base64_json('PLATFORM_ROUTES')
    conf["application_name"] =ENV["PLATFORM_APPLICATION_NAME"] || nil
    conf["app_dir"] =ENV["PLATFORM_APP_DIR"] || nil
    conf["project"] =ENV["PLATFORM_PROJECT"] || nil
    conf["document_root"] =ENV["PLATFORM_DOCUMENT_ROOT"] || nil
    if !is_build_environment?
      conf["environment"] =ENV["PLATFORM_ENVIRONMENT"] || nil
      conf["project_entropy"] =ENV["PLATFORM_PROJECT_ENTROPY"] || nil
      conf["port"] =ENV["PORT"] || nil
      conf["socket"] =ENV["SOCKET"] || nil
      conf["relationships"] = read_base64_json('PLATFORM_RELATIONSHIPS')
      conf["variables"] = read_base64_json('PLATFORM_VARIABLES')
    end
  else
    $logger.warn "This is not running on platform.sh"
    return nil
  end
  conf
end

.is_build_environment?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/platform_sh.rb', line 41

def self.is_build_environment?
  (!ENV.has_key?('PLATFORM_ENVIRONMENT') && ENV.has_key?('PLATFORM_PROJECT'))
end

.on_platform?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/platform_sh.rb', line 37

def self.on_platform?
  ENV.has_key? 'PLATFORM_PROJECT'
end

.relationship(rel_name, attr) ⇒ Object



45
46
47
# File 'lib/platform_sh.rb', line 45

def self.relationship rel_name, attr
  on_platform? ? config["relationships"][rel_name].first[attr] : nil
end