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
- #add_approval_option!(options, opt = {}) ⇒ Object
- #ask_for_approval(message = '') ⇒ Object
- #with_approval(opts, &block) ⇒ Object
Instance Method Details
#add_approval_option!(options, opt = {}) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/a2/mixins/approved.rb', line 3 def add_approval_option!(, opt = {}) .on('-y', '--yes', 'Auto approve the deletion prompt.') do opt[:auto_approved] = true end opt end |
#ask_for_approval(message = '') ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/a2/mixins/approved.rb', line 10 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 |
#with_approval(opts, &block) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/a2/mixins/approved.rb', line 18 def with_approval(opts, &block) opts[:auto_approved] = opts[:auto_approved] || false answer = 'yes' answer = ask_for_approval(opts[:message]) unless opts[:auto_approved] block.call if answer.eql?('yes') end |