Module: A2::Approved
- Included in:
- Subcommand::NodeMgmt::BulkDeleteByFilter, Subcommand::NodeMgmt::BulkDeleteById, Subcommand::NodeMgmt::Delete, Subcommand::Team::Delete, Subcommand::User::Delete
- Defined in:
- lib/a2/mixins/approved.rb
Instance Method Summary collapse
- #ask_for_approval(message) ⇒ Object
- #initialize(name, opts = {}) ⇒ Object
- #with_approval(message, &block) ⇒ Object
Instance Method Details
#ask_for_approval(message) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/a2/mixins/approved.rb', line 11 def ask_for_approval() puts "Are you sure you want to #{}?" puts "Only 'yes' will be accepted to proceed:" answer = $stdin.gets.chomp abort('Operation cancelled') unless answer.eql?('yes') answer end |
#initialize(name, opts = {}) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/a2/mixins/approved.rb', line 3 def initialize(name, opts = {}) super(name, takes_commands: false) @opt = {} .on('-y', '--yes', 'Auto approve the deletion prompt.') do @opt[:yes] = true end end |
#with_approval(message, &block) ⇒ Object
19 20 21 22 23 |
# File 'lib/a2/mixins/approved.rb', line 19 def with_approval(, &block) answer = 'yes' answer = ask_for_approval() unless @opt[:yes] block.call if answer.eql?('yes') end |