Sha256: cb4b290e6a02334133323bf7740aed163e2a9a89c9a77c508b1fa0bf284e0ccb

Contents?: true

Size: 1.23 KB

Versions: 13

Compression:

Stored size: 1.23 KB

Contents

module Vagrant
  module Action
    module Builtin
      # This class asks the user to confirm some sort of question with
      # a "Y/N" question. The only parameter is the text to ask the user.
      # The result is placed in `env[:result]` so that it can be used
      # with the {Call} class.
      class Confirm
        # For documentation, read the description of the {Confirm} class.
        #
        # @param [String] message The message to ask the user.
        # @param [Symbol] force_key The key that if present and true in
        #   the environment hash will skip the confirmation question.
        def initialize(app, env, message, force_key=nil)
          @app      = app
          @message  = message
          @force_key = force_key
        end

        def call(env)
          choice = nil

          # If we have a force key set and we're forcing, then set
          # the result to "Y"
          choice = "Y" if @force_key && env[@force_key]

          # If we haven't chosen yes, then ask the user via TTY
          choice = env[:ui].ask(@message) if !choice

          # The result is only true if the user said "Y"
          env[:result] = choice && choice.upcase == "Y"

          @app.call(env)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 5 rubygems

Version Path
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/lib/vagrant/action/builtin/confirm.rb
tnargav-1.2.3 lib/vagrant/action/builtin/confirm.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/lib/vagrant/action/builtin/confirm.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/lib/vagrant/action/builtin/confirm.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/lib/vagrant/action/builtin/confirm.rb
tnargav-1.2.2 lib/vagrant/action/builtin/confirm.rb
vagrantup-1.1.3 lib/vagrant/action/builtin/confirm.rb
vagrantup-1.1.2 lib/vagrant/action/builtin/confirm.rb
vagrantup-1.1.1 lib/vagrant/action/builtin/confirm.rb
vagrantup-1.1.0 lib/vagrant/action/builtin/confirm.rb
vagrantup-1.1.4 lib/vagrant/action/builtin/confirm.rb
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/lib/vagrant/action/builtin/confirm.rb
vagrant-lxc-0.0.1 vendor/vagrant/lib/vagrant/action/builtin/confirm.rb