Class: CMDx::Settings

Inherits:
Object
  • Object
show all
Defined in:
lib/cmdx/settings.rb

Overview

Per-task configuration overrides. Options are frozen on construction; #build returns a new instance rather than mutating. Every getter falls back to #configuration when the option wasn’t set on the task.

Instance Method Summary collapse

Constructor Details

#initialize(options = EMPTY_HASH) ⇒ Settings

Returns a new instance of Settings.

Parameters:

  • options (Hash{Symbol => Object}) (defaults to: EMPTY_HASH)

    task-specific overrides

Options Hash (options):

  • :logger (Logger)
  • :log_formatter (#call)
  • :log_level (Integer)
  • :backtrace_cleaner (#call)
  • :log_exclusions (Array<Symbol>)
  • :tags (Array<Symbol, String>)
  • :strict_context (Boolean)


17
18
19
# File 'lib/cmdx/settings.rb', line 17

def initialize(options = EMPTY_HASH)
  @options = options.freeze
end

Instance Method Details

#backtrace_cleaner#call?

Returns callable that cleans fault backtrace frames.

Returns:

  • (#call, nil)

    callable that cleans fault backtrace frames



64
65
66
67
68
# File 'lib/cmdx/settings.rb', line 64

def backtrace_cleaner
  @options.fetch(:backtrace_cleaner) do
    CMDx.configuration.backtrace_cleaner
  end
end

#build(new_options) ⇒ Settings

Returns a new Settings with ‘new_options` merged on top. Returns `self` unchanged when `new_options` is empty (used by Task inheritance).

Parameters:

  • new_options (Hash{Symbol => Object})

    overrides to layer on top

Returns:

  • (Settings)

    merged instance (or ‘self` when no changes)



26
27
28
29
30
# File 'lib/cmdx/settings.rb', line 26

def build(new_options)
  return self if new_options.empty?

  self.class.new(@options.merge(new_options))
end

#correlation_id#call?

Returns callable that produces a correlation id when invoked by Runtime at root-chain construction. Resolution order: task-level setting → Configuration#correlation_id → nil.

Returns:

  • (#call, nil)

    callable that produces a correlation id when invoked by Runtime at root-chain construction. Resolution order: task-level setting → Configuration#correlation_id → nil.



87
88
89
90
91
# File 'lib/cmdx/settings.rb', line 87

def correlation_id
  @options.fetch(:correlation_id) do
    CMDx.configuration.correlation_id
  end
end

#log_exclusionsArray<Symbol>

Returns keys to exclude from ‘Runtime` log output. Matched against Result#to_h keys. Common values for redaction: `:context` (may contain secrets / PII), `:cause` (raw exception), `:reason` (may embed exception messages from unhandled errors).

Returns:

  • (Array<Symbol>)

    keys to exclude from ‘Runtime` log output. Matched against Result#to_h keys. Common values for redaction: `:context` (may contain secrets / PII), `:cause` (raw exception), `:reason` (may embed exception messages from unhandled errors).



57
58
59
60
61
# File 'lib/cmdx/settings.rb', line 57

def log_exclusions
  @options.fetch(:log_exclusions) do
    CMDx.configuration.log_exclusions
  end
end

#log_formatter#call

Returns Logger formatter used when logging task results.

Returns:

  • (#call)

    Logger formatter used when logging task results



40
41
42
43
44
# File 'lib/cmdx/settings.rb', line 40

def log_formatter
  @options.fetch(:log_formatter) do
    CMDx.configuration.log_formatter
  end
end

#log_levelInteger

Returns ‘Logger` severity level.

Returns:

  • (Integer)

    ‘Logger` severity level



47
48
49
50
51
# File 'lib/cmdx/settings.rb', line 47

def log_level
  @options.fetch(:log_level) do
    CMDx.configuration.log_level
  end
end

#loggerLogger

Returns task-level logger or the global configuration’s logger.

Returns:

  • (Logger)

    task-level logger or the global configuration’s logger



33
34
35
36
37
# File 'lib/cmdx/settings.rb', line 33

def logger
  @options.fetch(:logger) do
    CMDx.configuration.logger
  end
end

#strict_contextBoolean

Returns whether this task’s Context should raise on unknown dynamic reads; falls back to Configuration#strict_context.

Returns:



78
79
80
81
82
# File 'lib/cmdx/settings.rb', line 78

def strict_context
  @options.fetch(:strict_context) do
    CMDx.configuration.strict_context
  end
end

#tagsArray<Symbol, String>

Returns task tags.

Returns:

  • (Array<Symbol, String>)

    task tags



71
72
73
# File 'lib/cmdx/settings.rb', line 71

def tags
  @options[:tags] || EMPTY_ARRAY
end