Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

extract repeating code to one method

  • Loading branch information...
commit 884370e0dba351d93e43c20d40a9e5810146433a 1 parent 4713972
@mpapis authored
Showing with 12 additions and 10 deletions.
  1. +12 −10 lib/veewee/provider/virtualbox/box/helper/status.rb
View
22 lib/veewee/provider/virtualbox/box/helper/status.rb
@@ -4,23 +4,25 @@ module Virtualbox
module BoxCommand
def exists?
- command="#{@vboxcmd} list vms"
- shell_results=shell_exec("#{command}",{:mute => true})
- exists=shell_results.stdout.split(/\n/).grep(/\"#{name.gsub(/\+/,'\\\+')}\"/).size!=0
-
- env.logger.info("Vm exists? #{exists}")
- return exists
+ return check?(:exists)
end
def running?
- command="#{@vboxcmd} list runningvms"
+ return check?(:running)
+ end
+
+ private
+
+ def check? type
+ command = COMMANDS[type] % @vboxcmd
shell_results=shell_exec("#{command}",{:mute => true})
- running=shell_results.stdout.split(/\n/).grep(/\"#{name.gsub(/\+/,'\\\+')}\"/).size!=0
+ status=shell_results.stdout.split(/\n/).grep(/\"#{name.gsub(/\+/,'\\\+')}\"/).size!=0
- env.logger.info("Vm running? #{running}")
- return running
+ env.logger.info("Vm #{type}? #{status}")
+ return status
end
+ COMMANDS = { :running => "%s list runningvms", :exists => "%s list vms" }
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.