Module: Console::Output::Default
- Defined in:
- lib/console/output/default.rb
Overview
Default output format selection.
Class Method Summary collapse
-
.github_actions?(env = ENV) ⇒ Boolean
Detect if we’re running in GitHub Actions, where human-readable output is preferred.
-
.mail?(env = ENV) ⇒ Boolean
Detect if we’re running in a cron job or mail context where human-readable output is preferred.
-
.new(stream, env: ENV, **options) ⇒ Object
Create a new output format based on the given stream.
Class Method Details
.github_actions?(env = ENV) ⇒ Boolean
Detect if we’re running in GitHub Actions, where human-readable output is preferred. GitHub Actions sets the GITHUB_ACTIONS environment variable to “true”.
46 47 48 |
# File 'lib/console/output/default.rb', line 46 def self.github_actions?(env = ENV) env["GITHUB_ACTIONS"] == "true" end |
.mail?(env = ENV) ⇒ Boolean
Detect if we’re running in a cron job or mail context where human-readable output is preferred. Cron jobs often have MAILTO set and lack TERM, or have minimal TERM values.
40 41 42 |
# File 'lib/console/output/default.rb', line 40 def self.mail?(env = ENV) env.key?("MAILTO") && !env["MAILTO"].empty? end |
.new(stream, env: ENV, **options) ⇒ Object
Create a new output format based on the given stream.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/console/output/default.rb', line 20 def self.new(stream, env: ENV, **) stream ||= $stderr if stream.tty? output = Terminal.new(stream, **) elsif self.mail?(env) output = Text.new(stream, **) elsif self.github_actions?(env) output = XTerm.new(stream, **) else output = Serialized.new(stream, **) end return output end |