Class: FlossFunding::ContraIndications
- Inherits:
-
Object
- Object
- FlossFunding::ContraIndications
- 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
-
.at_exit_contraindicated? ⇒ Boolean
Determines whether at-exit (END hook) output should be suppressed based on per-library configuration.
-
.poke_contraindicated? ⇒ Boolean
Returns true if we should short-circuit and do nothing for poke/setup.
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.
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 94 95 96 97 98 99 100 |
# File 'lib/floss_funding/contra_indications.rb', line 56 def at_exit_contraindicated? # Honor global flags first # Only contraindicate when there is an actual unhandled exception present. # $ERROR_INFO is an alias for $! and is always defined, even when nil, # so we must check its value. # Prior to any errors it will likely not be defined at all, # which will result in interpreter warnings, # so we also have to check if it is defined. return true if defined?($ERROR_INFO) && !$ERROR_INFO.nil? 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.
NOTE: contraindications do not prevent wedge: true.
- In CI: ENV[“CI”] case-insensitively equals “true”.
- If Dir.pwd raises (defensive check for incompatible runtime env).
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 44 |
# File 'lib/floss_funding/contra_indications.rb', line 14 def poke_contraindicated? # If global inert/silence flags are set, become inert immediately return true if ::FlossFunding.errored? return true if ::FlossFunding.silenced # CI environments may prefer to suppress poke/setup side effects 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 # Environment sanity check: if Dir.pwd raises, become inert 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 |