Class: VagrantWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-wrapper.rb,
lib/vagrant-wrapper/version.rb,
lib/vagrant-wrapper/exceptions.rb

Overview

Author

BinaryBabel OSS (<[email protected]>)

Homepage

www.binarybabel.org

License

MIT

For bugs, docs, updates:

http://code.binbab.org

Copyright 2013 sha1(OWNER) = df334a7237f10846a0ca302bd323e35ee1463931

See LICENSE file for more details.

Defined Under Namespace

Classes: Exceptions

Constant Summary collapse

VERSION =
'1.2.1.1'
RELEASE_DATE =
'2013-05-20'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ VagrantWrapper

Returns a new instance of VagrantWrapper.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vagrant-wrapper.rb', line 25

def initialize(*args)
  @vagrant_name = "vagrant"
  @vagrant_path = nil
  @search_paths = default_paths + env_paths
  @wrapper_mark = "END VAGRANT WRAPPER"

  # Optional first parameter sets required version.
  unless args.length < 1 or args[0].nil?
    require_version args[0]
  end
end

Class Method Details

.install_instructionsObject



108
109
110
# File 'lib/vagrant-wrapper.rb', line 108

def self.install_instructions
  "See http://www.vagrantup.com for instructions.\n"
end

.require_or_help_install(version) ⇒ Object



112
113
114
115
116
117
118
119
120
121
# File 'lib/vagrant-wrapper.rb', line 112

def self.require_or_help_install(version)
  begin
    vw = VagrantWrapper.new(version)
  rescue Exceptions::Version => e
    $stderr.print e.message + "\n"
    $stderr.print install_instructions
    exit(1)
  end
  vw
end

Instance Method Details

#default_pathsObject

Default paths to search for the packaged version of Vagrant.

/opt/vagrant/bin
/usr/local/bin
/usr/bin
/bin


92
93
94
95
96
97
98
99
# File 'lib/vagrant-wrapper.rb', line 92

def default_paths
  %w{
    /opt/vagrant/bin
    /usr/local/bin
    /usr/bin
    /bin
  }
end

#env_pathsObject

Environment search paths to be used as low priority search.



102
103
104
105
106
# File 'lib/vagrant-wrapper.rb', line 102

def env_paths
  path = ENV['PATH'].to_s.strip
  return [] if path.empty?
  path.split(':')
end

#execute(*args) ⇒ Object

Execute the discovered version of Vagrant. The given arguments (if any) are passed along to the command line.

The vagrant process will replace this process entirely, operating and outputting in an unmodified state.



65
66
67
68
69
70
71
# File 'lib/vagrant-wrapper.rb', line 65

def execute(*args)
  if args.length > 0 && args[0].is_a?(Array)
    send("exec_vagrant", *args[0])
  else
    send("exec_vagrant", *args)
  end
end

#get_output(*args) ⇒ Object

Call the discovered version of Vagrant. The given arguments (if any) are passed along to the command line.

The output will be returned.



52
53
54
55
56
57
58
# File 'lib/vagrant-wrapper.rb', line 52

def get_output(*args)
  if args.length > 0 && args[0].is_a?(Array)
    send("call_vagrant", *args[0])
  else
    send("call_vagrant", *args)
  end
end

#require_version(version) ⇒ Object

Require a specific version (or range of versions). Ex. “>= 1.1”



39
40
41
42
43
44
45
46
# File 'lib/vagrant-wrapper.rb', line 39

def require_version(version)
  version_req = Gem::Requirement.new(version)
  vagrant_ver = vagrant_version
  raise Exceptions::NotInstalled, "Vagrant is not installed." if vagrant_ver.nil?
  unless version_req.satisfied_by?(Gem::Version.new(vagrant_ver))
    raise Exceptions::Version, "Vagrant #{version} is required. You have #{vagrant_ver}."
  end
end

#vagrant_locationObject

Return the filesystem location of the discovered Vagrant install.



74
75
76
# File 'lib/vagrant-wrapper.rb', line 74

def vagrant_location
  find_vagrant
end

#vagrant_versionObject

Return the version of the discovered Vagrant install.



79
80
81
82
83
84
85
# File 'lib/vagrant-wrapper.rb', line 79

def vagrant_version
  ver = call_vagrant "-v"
  unless ver.nil?
    ver = ver[/(\.?[0-9]+)+/]
  end
  ver
end