class SecretConfig::SettingInterpolator

Public Instance Methods

date(format = "%Y%m%d") click to toggle source
# File lib/secret_config/setting_interpolator.rb, line 25
def date(format = "%Y%m%d")
  Date.today.strftime(format)
end
env(name, default = :no_default_supplied) click to toggle source
# File lib/secret_config/setting_interpolator.rb, line 33
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) click to toggle source
# File lib/secret_config/setting_interpolator.rb, line 41
def hostname(format = nil)
  name = Socket.gethostname
  name = name.split(".")[0] if format == "short"
  name
end
pid() click to toggle source
# File lib/secret_config/setting_interpolator.rb, line 47
def pid
  $$
end
random(size = 32) click to toggle source
# File lib/secret_config/setting_interpolator.rb, line 51
def random(size = 32)
  SecureRandom.urlsafe_base64(size)
end
select(*values) click to toggle source

Empty values return nil which removes the key entirely from the config

# File lib/secret_config/setting_interpolator.rb, line 56
def select(*values)
  if values.size < 2
    raise(ConfigurationError, "Must supply at least 2 options when using select: #{values.inspect}")
  end

  values[SecureRandom.random_number(values.count)]
end
time(format = "%Y%m%d%H%M%S%L") click to toggle source
# File lib/secret_config/setting_interpolator.rb, line 29
def time(format = "%Y%m%d%H%M%S%L")
  Time.now.strftime(format)
end