derelict 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/derelict.gemspec +37 -0
- data/lib/derelict/exception.rb +5 -0
- data/lib/derelict/instance/already_active.rb +9 -0
- data/lib/derelict/instance/invalid.rb +14 -0
- data/lib/derelict/instance/non_directory.rb +11 -0
- data/lib/derelict/instance/not_found.rb +11 -0
- data/lib/derelict/instance.rb +53 -0
- data/lib/derelict/version.rb +3 -0
- data/lib/derelict.rb +22 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/system_spec.spec +10 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YzA4ZGRlMzg1YWNjOGYzZmI2MzhlZDVlMTNiYjI5MDhmYzAxZjNmOA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
N2RmNTAwOTcwM2VkYTFmNGZmZDQ4NzI2NDhlYTgxNTZlODVjNzU3Mw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTM4NDgzOWUzYjQ0NzI4ODQ5OWFmMzE3MzU4NzFmNjhmMGU3NDM2OGNkZGZm
|
10
|
+
NzAxMmQ0ZGQxNzMyZjljZTc2MWU3MGVkOGU0OTcwMzdhMjBhMmZlZGEzZWQy
|
11
|
+
ZGU2NjAwNDhiNTNlNGFhNTVjMWExNjEyYjAyYjdhMjJiNTQ5MGE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MmFkMmJkMjk1ZWRlNTY2N2IxYTc5ZTU5NWFhZjMxZTQ4MDI4YjQ1MDRlMzg3
|
14
|
+
N2Q5ZDhjZmQxOTYyZDEzNmFiYzE1ZDY5MDhmYzg4N2I0NTY2MzIxYWM1NjEw
|
15
|
+
MDMxNmUwNjRhYTgzM2QyODRkNDljNmM5ZDY2NDA5Mjk5YTMzZGU=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brad Feehan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Derelict
|
2
|
+
|
3
|
+
Provides a Ruby API to control [Vagrant][1] where Vagrant is installed
|
4
|
+
via the Installer package on Mac OS X.
|
5
|
+
|
6
|
+
Currently a work-in-progress.
|
7
|
+
|
8
|
+
[1]: <https://www.vagrantup.com>
|
9
|
+
|
10
|
+
|
11
|
+
## Why?
|
12
|
+
|
13
|
+
Vagrant was historically available as a [gem][2], naturally providing a
|
14
|
+
Ruby API to control Vagrant in other Ruby libraries and applications.
|
15
|
+
However, [since version 1.1.0][3], [Vagrant is distributed exclusively
|
16
|
+
using an Installer package][4]. To control Vagrant when it's installed
|
17
|
+
this way, other Ruby libraries and applications typically need to
|
18
|
+
invoke the Vagrant binary, which requires forking a new process and
|
19
|
+
parsing its output using string manipulation.
|
20
|
+
|
21
|
+
Derelict is a Ruby gem that can control an instance of Vagrant that's
|
22
|
+
installed with the Installer package, which avoids calling the Vagrant
|
23
|
+
binary by interfacing directly with the Ruby source files in the
|
24
|
+
Vagrant installation.
|
25
|
+
|
26
|
+
[2]: <https://rubygems.org>
|
27
|
+
[3]: <https://groups.google.com/forum/#!msg/vagrant-up/kX_wvn7wcds/luwNur4kgDEJ>
|
28
|
+
[4]: <http://mitchellh.com/abandoning-rubygems>
|
29
|
+
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
Add this line to your application's Gemfile:
|
34
|
+
|
35
|
+
gem "derelict"
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
$ bundle
|
40
|
+
|
41
|
+
Or install it yourself as:
|
42
|
+
|
43
|
+
$ gem install derelict
|
44
|
+
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am "Add some feature"`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/derelict.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "derelict/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "derelict"
|
8
|
+
spec.version = Derelict::VERSION
|
9
|
+
spec.authors = ["Brad Feehan"]
|
10
|
+
spec.email = ["git@bradfeehan.com"]
|
11
|
+
spec.description = [
|
12
|
+
"Provides a Ruby API to control Vagrant where Vagrant is ",
|
13
|
+
"installed via the Installer package on Mac OS X.",
|
14
|
+
"\n\n",
|
15
|
+
"Vagrant was historically available as a gem, naturally ",
|
16
|
+
"providing a Ruby API to control Vagrant in other Ruby libraries ",
|
17
|
+
"and applications. However, since version 1.1.0, Vagrant is ",
|
18
|
+
"distributed exclusively using an Installer package. To control ",
|
19
|
+
"Vagrant when it's installed this way, other Ruby libraries and ",
|
20
|
+
"applications typically need to invoke the Vagrant binary, which ",
|
21
|
+
"requires forking a new process and parsing its output using ",
|
22
|
+
"string manipulation.",
|
23
|
+
].join
|
24
|
+
spec.summary =
|
25
|
+
"Ruby API for Vagrant installed via Installer package on Mac OS X."
|
26
|
+
spec.homepage = "https://github.com/bradfeehan/derelict"
|
27
|
+
spec.license = "MIT"
|
28
|
+
|
29
|
+
spec.files = `git ls-files`.split($/)
|
30
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
31
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
35
|
+
spec.add_development_dependency "rake"
|
36
|
+
spec.add_development_dependency "rspec"
|
37
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
class Derelict
|
2
|
+
# The requested Vagrant instance path is not a directory
|
3
|
+
class Instance::AlreadyActive < Exception
|
4
|
+
# Creates an instance of this exception for a particular path
|
5
|
+
def initialize
|
6
|
+
super "Error activating Derelict: an instance is already active"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class Derelict
|
2
|
+
# The requested Vagrant instance can't be used with Derelict
|
3
|
+
class Instance::Invalid < Exception
|
4
|
+
# Initialize with a default message (with optional detailed reason)
|
5
|
+
#
|
6
|
+
# reason: An additional reason to add to the message (optional)
|
7
|
+
def initialize(reason = nil)
|
8
|
+
super [
|
9
|
+
"Derelict can't use the specified Vagrant instance",
|
10
|
+
reason.nil? ? '' : ": #{reason}"
|
11
|
+
].join
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Derelict::Instance
|
2
|
+
# The requested Vagrant instance path is not a directory
|
3
|
+
class NonDirectory < Invalid
|
4
|
+
# Creates an instance of this exception for a particular path
|
5
|
+
#
|
6
|
+
# path: The path that this exception relates to
|
7
|
+
def initialize(path)
|
8
|
+
super "not a directory: #{path}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class Derelict::Instance
|
2
|
+
# The requested Vagrant instance directory doesn't exist
|
3
|
+
class NotFound < Invalid
|
4
|
+
# Creates an instance of this exception for a particular path
|
5
|
+
#
|
6
|
+
# path: The path that this exception relates to
|
7
|
+
def initialize(path)
|
8
|
+
super "directory not found: #{path}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
class Derelict
|
2
|
+
# Represents a connection to an package-installed instance of Vagrant
|
3
|
+
class Instance
|
4
|
+
autoload :AlreadyActive, "derelict/instance/already_active"
|
5
|
+
autoload :NonDirectory, "derelict/instance/non_directory"
|
6
|
+
autoload :NotFound, "derelict/instance/not_found"
|
7
|
+
|
8
|
+
attr_reader :namespace
|
9
|
+
|
10
|
+
# Initializes a new instance
|
11
|
+
#
|
12
|
+
# path: The path to the location of the Vagrant instance
|
13
|
+
def initialize(path)
|
14
|
+
raise NotFound.new unless File.exists? path
|
15
|
+
raise NonDirectory.new unless File.directory? path
|
16
|
+
@path = path.chomp "/"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Loads the Vagrant module into an instance variable
|
20
|
+
def activate!
|
21
|
+
raise AlreadyActive.new if Derelict.active?
|
22
|
+
|
23
|
+
gemspec_files.each {|gemspec_file|
|
24
|
+
Gem::Specification.load(gemspec_file).add_self_to_load_path
|
25
|
+
}
|
26
|
+
|
27
|
+
require vagrant_entrypoint
|
28
|
+
end
|
29
|
+
|
30
|
+
# # Pass through any method calls to the Vagrant module
|
31
|
+
# def method_missing(method, *args)
|
32
|
+
# @module.Vagrant.send method, args
|
33
|
+
# end
|
34
|
+
|
35
|
+
private
|
36
|
+
# Retrieves the path to the directory containing embedded gems
|
37
|
+
def gems_path
|
38
|
+
File.join @path, "embedded", "gems"
|
39
|
+
end
|
40
|
+
|
41
|
+
# Creates a pattern to match all embedded gemspec files
|
42
|
+
def gemspec_files
|
43
|
+
pattern = File.join gems_path, "specifications", "*.gemspec"
|
44
|
+
Dir.glob(pattern).sort
|
45
|
+
end
|
46
|
+
|
47
|
+
# Retrieves the absolute path of the main vagrant.rb in the gem
|
48
|
+
def vagrant_entrypoint
|
49
|
+
file = File.join gems_path, *%w[gems vagrant-* lib vagrant.rb]
|
50
|
+
Dir.glob(file).sort.last
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/derelict.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "derelict/version"
|
3
|
+
|
4
|
+
# Controls a Vagrant instance
|
5
|
+
class Derelict
|
6
|
+
autoload :Instance, "derelict/instance"
|
7
|
+
autoload :Exception, "derelict/exception"
|
8
|
+
|
9
|
+
# Connects to an instance of Vagrant installed via Installer package
|
10
|
+
#
|
11
|
+
# path: The path to the location of the Vagrant instance
|
12
|
+
def self.connect(path)
|
13
|
+
Instance.new path
|
14
|
+
end
|
15
|
+
|
16
|
+
# Determines if an instance is currently active
|
17
|
+
def self.active?
|
18
|
+
Module.const_get("::Vagrant").is_a?(Class)
|
19
|
+
rescue NameError
|
20
|
+
false
|
21
|
+
end
|
22
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Derelict do
|
4
|
+
it "loads Vagrant from /Applications/Vagrant" do
|
5
|
+
instance = Derelict.connect '/Applications/Vagrant'
|
6
|
+
expect(instance).to be_a Derelict::Instance
|
7
|
+
expect(instance.activate!).to be_true
|
8
|
+
expect(Vagrant.class).to be_a(Module)
|
9
|
+
end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: derelict
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Brad Feehan
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: ! 'Provides a Ruby API to control Vagrant where Vagrant is installed
|
56
|
+
via the Installer package on Mac OS X.
|
57
|
+
|
58
|
+
|
59
|
+
Vagrant was historically available as a gem, naturally providing a Ruby API to control
|
60
|
+
Vagrant in other Ruby libraries and applications. However, since version 1.1.0,
|
61
|
+
Vagrant is distributed exclusively using an Installer package. To control Vagrant
|
62
|
+
when it''s installed this way, other Ruby libraries and applications typically need
|
63
|
+
to invoke the Vagrant binary, which requires forking a new process and parsing its
|
64
|
+
output using string manipulation.'
|
65
|
+
email:
|
66
|
+
- git@bradfeehan.com
|
67
|
+
executables: []
|
68
|
+
extensions: []
|
69
|
+
extra_rdoc_files: []
|
70
|
+
files:
|
71
|
+
- .gitignore
|
72
|
+
- Gemfile
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- derelict.gemspec
|
77
|
+
- lib/derelict.rb
|
78
|
+
- lib/derelict/exception.rb
|
79
|
+
- lib/derelict/instance.rb
|
80
|
+
- lib/derelict/instance/already_active.rb
|
81
|
+
- lib/derelict/instance/invalid.rb
|
82
|
+
- lib/derelict/instance/non_directory.rb
|
83
|
+
- lib/derelict/instance/not_found.rb
|
84
|
+
- lib/derelict/version.rb
|
85
|
+
- spec/spec_helper.rb
|
86
|
+
- spec/system_spec.spec
|
87
|
+
homepage: https://github.com/bradfeehan/derelict
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.1.5
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Ruby API for Vagrant installed via Installer package on Mac OS X.
|
111
|
+
test_files:
|
112
|
+
- spec/spec_helper.rb
|
113
|
+
- spec/system_spec.spec
|