Class: FlossFunding::ContraIndications

Inherits:
Object
  • Object
show all
Defined in:
lib/floss_funding/contra_indications.rb

Overview

Performs environment checks to determine whether FlossFunding should be silenced
completely early in the include flow (e.g., CI or unsafe runtime conditions),
and whether end-of-process (at_exit) messaging should be suppressed by config.

Class Method Summary collapse

Class Method Details

.at_exit_contraindicated?Boolean

Determines whether at-exit (END hook) output should be suppressed based on
per-library configuration. This migrates the previous Config.silence_requested?
behavior without backward-compatibility.

For each library’s config, examines the “silent” key values. If any value
responds to :call, it will be invoked (with no args) and the truthiness of
its return value is used. Otherwise, the value’s own truthiness is used.
Returns true if any library requests silence; false otherwise.

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/floss_funding/contra_indications.rb', line 55

def at_exit_contraindicated?
  # Honor global flags first
  return true if !$ERROR_INFO.nil? # if not nil the process is exiting with non-zero exit status due to an uncaught error, and we don't want to suppress that, or interfere by raising a different error.
  return true if ::FlossFunding.errored?
  return true if ::FlossFunding.silenced
  return true if ::FlossFunding::Constants::SILENT

  # Non-TTY environments: suppress at-exit output
  begin
    return true unless STDOUT.tty?
  rescue StandardError
    return true
  end

  # Lockfile no longer gates at-exit output globally; per-library gating handled elsewhere

  configurations = ::FlossFunding.configurations
  configurations.any? do |_library, cfgs|
    configs_arr = cfgs.is_a?(Array) ? cfgs : [cfgs]
    configs_arr.any? do |cfg|
      values = if cfg.respond_to?(:to_h)
        Array(cfg.to_h["silent_callables"]) # preferred when available
      elsif cfg.is_a?(Hash)
        Array(cfg["silent_callables"]) # may be nil/array/scalar
      else
        []
      end

      values.any? do |v|
        begin
          v.respond_to?(:call) ? !!v.call : false
        rescue StandardError
          # If callable raises, treat it as contraindicated to avoid unknown global state
          true
        end
      end
    end
  end
end

.poke_contraindicated?Boolean

Returns true if we should short-circuit and do nothing for poke/setup.

  • In CI: ENV[“CI”] case-insensitively equals “true”.
  • If Dir.pwd raises (defensive check for broken runtime env).

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/floss_funding/contra_indications.rb', line 13

def poke_contraindicated?
  # If an internal error occurred, become inert immediately
  return true if ::FlossFunding.errored?
  # Callable silencers do not apply during load; only at-exit.
  # For early short-circuiting we honor the global silenced flag only.
  return true if ::FlossFunding.silenced

  begin
    ci_val = ENV.fetch("CI", "")
    return true if ci_val.respond_to?(:casecmp) && ci_val.casecmp("true") == 0
  rescue StandardError
    # If accessing ENV somehow fails, err on the side of silencing
    return true
  end

  begin
    Dir.pwd
  rescue StandardError
    return true
  end

  # Non-TTY environments: suppress poke/setup side effects (mirror at-exit logic)
  begin
    return true unless STDOUT.tty?
  rescue StandardError
    return true
  end

  # On-load lockfile no longer contraindicates discovery; always allow here
  false
end