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



61
62
63
64
65
# File 'lib/cmdx/settings.rb', line 61

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_idString?

Returns correlation id or the global configuration’s correlation id.

Returns:

  • (String, nil)

    correlation id or the global configuration’s correlation id



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 logging.

Returns:

  • (Array<Symbol>)

    keys to exclude from logging



54
55
56
57
58
# File 'lib/cmdx/settings.rb', line 54

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:



80
81
82
83
84
# File 'lib/cmdx/settings.rb', line 80

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

#tagsArray<Symbol, String>

Returns a fresh array each call so callers can mutate the result without affecting other tasks (or hitting ‘FrozenError` on the shared sentinel).

Returns:

  • (Array<Symbol, String>)

    task tags, surfaced on result hashes



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

def tags
  tags = @options[:tags]
  tags ? tags.dup : []
end