Class: ConsoleThinkTwice::Configuration
- Inherits:
-
Object
- Object
- ConsoleThinkTwice::Configuration
- Defined in:
- lib/console_think_twice/configuration.rb
Constant Summary collapse
- DISABLING_ENV_VALUES =
%w[0 false no off].freeze
Instance Attribute Summary collapse
-
#affirmative_answers ⇒ Object
Answers accepted as a confirmation; anything else aborts.
-
#enabled ⇒ Object
writeonly
Sets the attribute enabled.
- #input ⇒ Object
-
#interactive ⇒ Object
writeonly
Sets the attribute interactive.
-
#label ⇒ Object
Shown in the prompt to make the stakes obvious, e.g.
- #output ⇒ Object
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#interactive? ⇒ Boolean
Whether there is a human on the other end who can answer the prompt.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
12 13 14 |
# File 'lib/console_think_twice/configuration.rb', line 12 def initialize @affirmative_answers = %w[y yes] end |
Instance Attribute Details
#affirmative_answers ⇒ Object
Answers accepted as a confirmation; anything else aborts.
10 11 12 |
# File 'lib/console_think_twice/configuration.rb', line 10 def affirmative_answers @affirmative_answers end |
#enabled=(value) ⇒ Object (writeonly)
Sets the attribute enabled
7 8 9 |
# File 'lib/console_think_twice/configuration.rb', line 7 def enabled=(value) @enabled = value end |
#input ⇒ Object
16 17 18 |
# File 'lib/console_think_twice/configuration.rb', line 16 def input @input || $stdin end |
#interactive=(value) ⇒ Object (writeonly)
Sets the attribute interactive
7 8 9 |
# File 'lib/console_think_twice/configuration.rb', line 7 def interactive=(value) @interactive = value end |
#label ⇒ Object
Shown in the prompt to make the stakes obvious, e.g. "in production". Defaults to the Rails environment; assigning any value at all — nil and false included — wins over that, so the label can be turned off as well as changed.
41 42 43 44 45 |
# File 'lib/console_think_twice/configuration.rb', line 41 def label return @label if defined?(@label) ::Rails.env.to_s if defined?(::Rails) && ::Rails.respond_to?(:env) end |
#output ⇒ Object
20 21 22 |
# File 'lib/console_think_twice/configuration.rb', line 20 def output @output || $stdout end |
Instance Method Details
#enabled? ⇒ Boolean
24 25 26 27 28 |
# File 'lib/console_think_twice/configuration.rb', line 24 def enabled? return @enabled unless @enabled.nil? !DISABLING_ENV_VALUES.include?(ENV["CONSOLE_THINK_TWICE"].to_s.strip.downcase) end |
#interactive? ⇒ Boolean
Whether there is a human on the other end who can answer the prompt. Auto-detected from the input stream unless set, so piped input aborts instead of destroying unattended.
32 33 34 35 36 |
# File 'lib/console_think_twice/configuration.rb', line 32 def interactive? return @interactive unless @interactive.nil? input.respond_to?(:tty?) && input.tty? end |