Module: SecureKeys::Core::Console::Argument::Fetchable

Included in:
Handler, Validation::Console::Argument::Scan::Handler
Defined in:
lib/core/console/arguments/fetchable.rb

Overview

Shared fetch/set behaviour for argument handler classes. Include this module inside class << self so the methods become class-level accessors that check the handler’s own arguments hash before falling back to environment variables.

The including class must expose arguments as a class-level reader (via attr_reader :arguments inside class << self).

Instance Method Summary collapse

Instance Method Details

#fetch(key:, default: nil) ⇒ Object

Fetch an argument value, falling back to SECURE_KEYS_<KEY>, then the bare <KEY> environment variable, then default.

Parameters:

  • key (Symbol, Array<Symbol>)

    The argument key (or nested key path)

  • default (Object) (defaults to: nil)

    The value to return when nothing is found

Returns:

  • (Object)

    The resolved value



21
22
23
24
25
# File 'lib/core/console/arguments/fetchable.rb', line 21

def fetch(key:, default: nil)
  keys = Array(key).map(&:to_sym)
  joined_keys = keys.join('_').upcase
  arguments.dig(*keys) || ENV["SECURE_KEYS_#{joined_keys}"] || ENV[joined_keys] || default
end

#set(key:, value:) ⇒ void

This method returns an undefined value.

Update a single argument value

Parameters:

  • key (Symbol)

    The argument key to update

  • value (Object)

    The new value



31
32
33
# File 'lib/core/console/arguments/fetchable.rb', line 31

def set(key:, value:)
  arguments[key.to_sym] = value
end