Class: SecretConfig::SettingInterpolator

Inherits:
StringInterpolator show all
Defined in:
lib/secret_config/setting_interpolator.rb

Instance Method Summary collapse

Methods inherited from StringInterpolator

#initialize, #parse

Constructor Details

This class inherits a constructor from SecretConfig::StringInterpolator

Instance Method Details

#date(format = "%Y%m%d") ⇒ Object



22
23
24
# File 'lib/secret_config/setting_interpolator.rb', line 22

def date(format = "%Y%m%d")
  Date.today.strftime(format)
end

#env(name, default = :no_default_supplied) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/secret_config/setting_interpolator.rb', line 30

def env(name, default = :no_default_supplied)
  return ENV[name] if ENV.key?(name)

  return default unless default == :no_default_supplied

  raise(MissingEnvironmentVariable, "Missing mandatory environment variable: #{name}")
end

#hostname(format = nil) ⇒ Object



38
39
40
41
42
# File 'lib/secret_config/setting_interpolator.rb', line 38

def hostname(format = nil)
  name = Socket.gethostname
  name = name.split(".")[0] if format == "short"
  name
end

#pidObject



44
45
46
# File 'lib/secret_config/setting_interpolator.rb', line 44

def pid
  $$
end

#random(size = 32) ⇒ Object



48
49
50
# File 'lib/secret_config/setting_interpolator.rb', line 48

def random(size = 32)
  SecureRandom.urlsafe_base64(size)
end

#time(format = "%Y%m%d%H%M%S%L") ⇒ Object



26
27
28
# File 'lib/secret_config/setting_interpolator.rb', line 26

def time(format = "%Y%m%d%H%M%S%L")
  Time.now.strftime(format)
end