Method: UltraSettings::Field#initialize

Defined in:
lib/ultra_settings/field.rb

#initialize(name:, type: :string, description: nil, default: nil, default_if: nil, env_var: nil, runtime_setting: nil, yaml_key: nil, static: false, secret: false) ⇒ Field

Returns a new instance of Field.

Parameters:

  • name (String, Symbol)

    The name of the field.

  • type (Symbol) (defaults to: :string)

    The type of the field.

  • description (String) (defaults to: nil)

    The description of the field.

  • default (Object) (defaults to: nil)

    The default value of the field.

  • default_if (Proc, Symbol) (defaults to: nil)

    A proc that returns true if the default value should be used.

  • env_var (String, Symbol) (defaults to: nil)

    The name of the environment variable to use for the field.

  • runtime_setting (String, Symbol) (defaults to: nil)

    The name of the setting to use for the field.

  • yaml_key (String, Symbol) (defaults to: nil)

    The name of the YAML key to use for the field.

  • static (Boolean) (defaults to: false)

    Whether or not the field is static and cannot be changed at runtime.

  • secret (Boolean, Proc) (defaults to: false)

    Whether or not the field contains a value that should be kept secret.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/ultra_settings/field.rb', line 25

def initialize(
  name:,
  type: :string,
  description: nil,
  default: nil,
  default_if: nil,
  env_var: nil,
  runtime_setting: nil,
  yaml_key: nil,
  static: false,
  secret: false
)
  @name = name.to_s.freeze
  @type = type.to_sym
  @description = description&.to_s&.freeze
  @default = Coerce.coerce_value(default, @type).freeze
  @default_if = default_if
  @env_var = env_var&.to_s&.freeze
  @runtime_setting = runtime_setting&.to_s&.freeze
  @yaml_key = yaml_key&.to_s&.freeze
  @static = !!static
  @secret = (secret.respond_to?(:call) ? secret : !!secret)
end