vagrant-bundler-tools 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.mdown ADDED
@@ -0,0 +1,46 @@
1
+ # Vagrant-bundler-tools
2
+
3
+ This gem is a plugin for vagrant that makes it possible to interact with
4
+ bundled gems on the guest directly from the host.
5
+
6
+ For example you can open a gem bundled on your linux guest in your OSX host's
7
+ editor.
8
+
9
+ ## Installation
10
+
11
+ gem install vagrant-bundler-tools
12
+
13
+ ## Usage
14
+
15
+ To open a gem bundled on your guest in your host's editor use
16
+
17
+ vagrant bundle open <gem_name>
18
+
19
+ from the host.
20
+
21
+ ## Other commands
22
+
23
+ You can also use
24
+
25
+ vagrant bundle show <gem_name>
26
+
27
+ On the host to show path (on the host) to the named gem bundled on the guest.
28
+
29
+ ## Caveats
30
+
31
+ You will need to set the bundle path on the guest to be a subdirectory of the
32
+ project so that the host can access it, for example with
33
+
34
+ bundle config path .bundled_gems
35
+
36
+ in the project directory on the guest.
37
+
38
+ ## MIT License
39
+
40
+ (c) Joel Chippindale 2011
41
+
42
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
43
+
44
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
45
+
46
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,56 @@
1
+ module VagrantBundlerTools
2
+ class Command < Vagrant::Command::GroupBase
3
+ register "bundle", "Commands to interact with bundled gems on guest"
4
+
5
+ desc "show GEM_NAME", "Show location of guest's bundled gem on host file system"
6
+ def show(gem_name)
7
+ env.ui.info locate_gem(gem_name)
8
+ end
9
+
10
+ desc "open GEM_NAME", "Open guest's bundled gem with host's editor"
11
+ def open(gem_name)
12
+ # Method largely copied and pasted from from Bundler::CLI#open
13
+ editor = [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
14
+ if editor
15
+ gem_path = locate_gem(gem_name)
16
+ Dir.chdir(gem_path) do
17
+ command = "#{editor} #{gem_path}"
18
+ success = system(command)
19
+ env.ui.info "Could not run '#{command}'" unless success
20
+ end
21
+ else
22
+ env.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR")
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def locate_gem(gem_name)
29
+ guest_path = ssh_execute("cd /vagrant && bundle show #{gem_name}").strip
30
+ unless guest_path.start_with?('/vagrant/')
31
+ raise Errors::BundlePathOutsideVagrantDirectory.new
32
+ end
33
+ host_path = guest_path.gsub(%r{^/vagrant/}, '')
34
+ File.expand_path(host_path)
35
+ end
36
+
37
+ def ssh_execute(command)
38
+ ssh_vm.ssh.execute do |ssh|
39
+ ssh.exec!(command)
40
+ end
41
+ end
42
+
43
+ def ssh_vm
44
+ @ssh_vm ||= begin
45
+ vm = target_vms.first
46
+
47
+ # Basic checks that are required for proper SSH
48
+ raise Vagrant::Errors::VMNotCreatedError if !vm.created?
49
+ raise Vagrant::Errors::VMInaccessible if !vm.vm.accessible?
50
+ raise Vagrant::Errors::VMNotRunningError if !vm.vm.running?
51
+
52
+ vm
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,7 @@
1
+ module VagrantBundlerTools
2
+ module Errors
3
+ class BundlePathOutsideVagrantDirectory < Vagrant::Errors::VagrantError
4
+ error_key(:bundle_path_outside_vagrant_directory, "vagrant_bundler_tools.errors")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ require 'vagrant'
2
+ require 'vagrant_bundler_tools/command'
3
+ require 'vagrant_bundler_tools/errors'
4
+
5
+ module VagrantBundlerTools
6
+
7
+ # The source root is the path to the root directory of
8
+ # the VagrantBundlerTools gem.
9
+ def self.source_root
10
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
11
+ end
12
+ end
13
+
14
+ # # Default I18n to load the en locale
15
+ I18n.load_path << File.expand_path("templates/locales/en.yml", VagrantBundlerTools.source_root)
@@ -0,0 +1,3 @@
1
+ # This file is automatically loaded by Vagrant. We use this to kick-start
2
+ # our plugin.
3
+ require 'vagrant_bundler_tools'
@@ -0,0 +1,8 @@
1
+ en:
2
+ vagrant_bundler_tools:
3
+ errors:
4
+ bundle_path_outside_vagrant_directory: |-
5
+ The guest's bundle path must be a subdirectory of /vagrant to be accessible to the host
6
+ Run
7
+ bundle config .bundler && bundle install
8
+ On the guest to move the bundle to a location the host can access
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-bundler-tools
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Joel Chippindale
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-27 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: vagrant
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ - 7
32
+ - 0
33
+ version: 0.7.0
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: i18n
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 7
45
+ segments:
46
+ - 0
47
+ - 6
48
+ - 0
49
+ version: 0.6.0
50
+ type: :runtime
51
+ version_requirements: *id002
52
+ description: |
53
+ vagrant-bundle-tools in a vagrant plugin to make it possible to interact
54
+ with the guest's bundled gems directory from the host.
55
+
56
+ email: joel@joelchippindale.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - README.mdown
63
+ files:
64
+ - README.mdown
65
+ - lib/vagrant_bundler_tools/command.rb
66
+ - lib/vagrant_bundler_tools/errors.rb
67
+ - lib/vagrant_bundler_tools.rb
68
+ - lib/vagrant_init.rb
69
+ - templates/locales/en.yml
70
+ homepage: http://github.com/mocoso/vagrant-bundler-tools
71
+ licenses: []
72
+
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --main
76
+ - README.mdown
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 3
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.6
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Vagrant plugin for working with the guest's bundled gems
104
+ test_files: []
105
+