Project

derelict_m

0.0
No commit activity in last 3 years
No release in over 3 years
Provides a Ruby API to control Vagrant where Vagrant is installed via the Installer package on Mac OS X. Vagrant was historically available as a gem, naturally providing a Ruby API to control Vagrant in other Ruby libraries and applications. However, since version 1.1.0, Vagrant is distributed exclusively using an Installer package. To control Vagrant when it's installed this way, other Ruby libraries and applications typically need to invoke the Vagrant binary, which requires forking a new process and parsing its output using string manipulation.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0
>= 0
< 11.0
< 3.0

Runtime

!= 1.1.11, ~> 1.1.0
>= 0
 Project Readme

Derelict

Gem Version Build Status Coverage Status Code Climate Dependency Status

Provides a Ruby API to control Vagrant where Vagrant is installed via the Installer package on Mac OS X.

Currently a work-in-progress.

Why?

Vagrant was historically available as a gem, naturally providing a Ruby API to control Vagrant in other Ruby libraries and applications. However, since version 1.1.0, Vagrant is distributed exclusively using an Installer package. Derelict is a Ruby library that wraps the Vagrant binary, shelling out and parsing the results of each command.

Installation

Add this line to your application's Gemfile:

gem "derelict"

And then execute:

$ bundle

Or install it yourself as:

$ gem install derelict

Usage

Some examples of common operations using Derelict:

require "derelict"

# Determine if there's a "default" VM defined in /path/to/project
Derelict.instance.connect("/path/to/project").vm(:default).exists?

Advanced

require "derelict"

# Create an instance (represents a Vagrant installation)
instance = Derelict.instance("/path/to/vagrant")
instance = Derelict.instance # Defaults to /Applications/Vagrant

# Issue commands to the instance directly (not usually necessary)
result = instance.execute('--version') # Derelict::Executer object
print "success" if result.success?     # if Vagrant's exit status was 0
print result.stdout                    # "Vagrant 1.3.3\n"

# Connect to a Vagrant project (containing a Vagrantfile)
connection = instance.connect("/path/to/project")

# Issue commands to the connection directly (runs from the project dir)
result = connection.execute(:up) # runs "vagrant up" in project dir
result.success?                  # Derelict::Executer object again

# Retrieve a particular VM from a connection (multi-machine support)
vm = connection.vm(:web) # "vm" is a Derelict::VirtualMachine
vm.exists?               # does the connection define a "web" VM?
vm.state                 # current VM state (:running, :not_created...)
vm.running?              # whether the VM is currently running or not
vm.up!                   # runs "vagrant up" for this VM only
vm.halt!                 # runs "vagrant halt" for this VM only
vm.destroy!              # runs "vagrant destroy --force" for this VM
vm.reload!               # runs "vagrant reload" for this VM only
vm.suspend!              # runs "vagrant suspend" for this VM only
vm.resume!               # runs "vagrant resume" for this VM only

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am "Add some feature")
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request