vagrant-bundler 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.mdown ADDED
@@ -0,0 +1,50 @@
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
+ - List bundled gems on the host
26
+
27
+ vagrant bundle list
28
+
29
+ - Show path (on the host) to the named gem bundled on the guest
30
+
31
+ vagrant bundle show <gem_name>
32
+
33
+ ## Caveats
34
+
35
+ You will need to set the bundle path on the guest to be a subdirectory of the
36
+ project so that the host can access it, for example with
37
+
38
+ bundle config path .bundled_gems
39
+
40
+ in the project directory on the guest.
41
+
42
+ ## MIT License
43
+
44
+ (c) Joel Chippindale 2011
45
+
46
+ 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:
47
+
48
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
49
+
50
+ 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,21 @@
1
+ require 'vagrant'
2
+ require 'vagrant_bundler/command/base'
3
+ require 'vagrant_bundler/command/bundle'
4
+ require 'vagrant_bundler/command/bundle_list'
5
+ require 'vagrant_bundler/command/bundle_open'
6
+ require 'vagrant_bundler/command/bundle_show'
7
+ require 'vagrant_bundler/errors'
8
+
9
+ module VagrantBundler
10
+
11
+ # The source root is the path to the root directory of
12
+ # the VagrantBundler gem.
13
+ def self.source_root
14
+ @source_root ||= Pathname.new(File.expand_path('../../', __FILE__))
15
+ end
16
+ end
17
+
18
+ Vagrant.commands.register(:bundle) { VagrantBundler::Command::Bundle }
19
+
20
+ # # Default I18n to load the en locale
21
+ I18n.load_path << File.expand_path("templates/locales/en.yml", VagrantBundler.source_root)
@@ -0,0 +1,37 @@
1
+ module VagrantBundler
2
+ module Command
3
+ class Base < Vagrant::Command::Base
4
+ protected
5
+ def locate_gem(gem_name)
6
+ bundle_show = ssh_execute("cd /vagrant && bundle show #{gem_name}").strip
7
+
8
+ if bundle_show.include?('Could not find gem')
9
+ raise Errors::GemNotFound.new(bundle_show)
10
+ end
11
+
12
+ unless bundle_show.start_with?('/vagrant/')
13
+ raise Errors::BundlePathOutsideVagrantDirectory.new
14
+ end
15
+
16
+ host_path = bundle_show.gsub(%r{^/vagrant/}, '')
17
+ File.expand_path(host_path)
18
+ end
19
+
20
+ def ssh_execute(command)
21
+ output = ''
22
+ with_target_vms(nil, :single_target => true) do |vm|
23
+ # Basic checks that are required for proper SSH
24
+ raise Errors::VMNotCreatedError if !vm.created?
25
+ raise Errors::VMInaccessible if !vm.state == :inaccessible
26
+ raise Errors::VMNotRunningError if vm.state != :running
27
+
28
+ vm.channel.execute(command, :error_check => false) do |type, data|
29
+ output << data.to_s
30
+ end
31
+ end
32
+
33
+ output
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,53 @@
1
+ require 'optparse'
2
+
3
+ module VagrantBundler
4
+ module Command
5
+ class Bundle < Base
6
+ def initialize(argv, env)
7
+ super
8
+
9
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
10
+
11
+ @subcommands = Vagrant::Registry.new
12
+ @subcommands.register(:list) { VagrantBundler::Command::BundleList }
13
+ @subcommands.register(:open) { VagrantBundler::Command::BundleOpen }
14
+ @subcommands.register(:show) { VagrantBundler::Command::BundleShow }
15
+ end
16
+
17
+ def execute
18
+ if @main_args.include?("-h") || @main_args.include?("--help")
19
+ # Print the help for all the box commands.
20
+ return help
21
+ end
22
+
23
+ # If we reached this far then we must have a subcommand. If not,
24
+ # then we also just print the help and exit.
25
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
26
+ return help if !command_class || !@sub_command
27
+
28
+ # Initialize and execute the command class
29
+ command_class.new(@sub_args, @env).execute
30
+ end
31
+
32
+ # Prints the help out for this command
33
+ def help
34
+ opts = OptionParser.new do |opts|
35
+ opts.banner = "Usage: vagrant bundle <command> [<args>]"
36
+ opts.separator ""
37
+ opts.separator "Available subcommands:"
38
+
39
+ # Add the available subcommands as separators in order to print them
40
+ # out as well.
41
+ keys = []
42
+ @subcommands.each { |key, value| keys << key }
43
+
44
+ keys.each do |key|
45
+ opts.separator " #{key}"
46
+ end
47
+ end
48
+
49
+ @env.ui.info(opts.help, :prefix => false)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,11 @@
1
+ require 'optparse'
2
+
3
+ module VagrantBundler
4
+ module Command
5
+ class BundleList < Base
6
+ def execute
7
+ @env.ui.info ssh_execute("cd /vagrant && bundle list")
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,33 @@
1
+ module VagrantBundler
2
+ module Command
3
+ class BundleOpen < Base
4
+ def execute
5
+ opts = OptionParser.new do |opts|
6
+ opts.banner = "Show the path to a bundle gem on the vagrant box"
7
+ opts.separator ""
8
+ opts.separator "Usage: vagrant bundle show <gem_name>"
9
+ end
10
+
11
+ # Parse the options
12
+ argv = parse_options(opts)
13
+
14
+ return if !argv
15
+
16
+ raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1
17
+
18
+ # Method largely copied and pasted from from Bundler::CLI#open
19
+ editor = [ENV['BUNDLER_EDITOR'], ENV['VISUAL'], ENV['EDITOR']].find{|e| !e.nil? && !e.empty? }
20
+ if editor
21
+ gem_path = locate_gem(argv[0])
22
+ Dir.chdir(gem_path) do
23
+ command = "#{editor} #{gem_path}"
24
+ success = system(command)
25
+ @env.ui.info "Could not run '#{command}'" unless success
26
+ end
27
+ else
28
+ @env.ui.info("To open a bundled gem, set $EDITOR or $BUNDLER_EDITOR")
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,24 @@
1
+ require 'optparse'
2
+
3
+ module VagrantBundler
4
+ module Command
5
+ class BundleShow < Base
6
+ def execute
7
+ opts = OptionParser.new do |opts|
8
+ opts.banner = "Show the path to a bundle gem on the vagrant box"
9
+ opts.separator ""
10
+ opts.separator "Usage: vagrant bundle show <gem_name>"
11
+ end
12
+
13
+ # Parse the options
14
+ argv = parse_options(opts)
15
+
16
+ return if !argv
17
+
18
+ raise Vagrant::Errors::CLIInvalidUsage, :help => opts.help.chomp if argv.length < 1
19
+
20
+ @env.ui.info locate_gem(argv[0])
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ module VagrantBundler
2
+ module Errors
3
+ class BundlePathOutsideVagrantDirectory < Vagrant::Errors::VagrantError
4
+ error_key(:bundle_path_outside_vagrant_directory, "vagrant_bundler.errors")
5
+ end
6
+
7
+ class GemNotFound < Vagrant::Errors::VagrantError
8
+ def initialize(message)
9
+ # We inherit from Vagrant::Errors::VagrantError so that Vagrant
10
+ # handles this error like other VagrantErrors but we want to skip
11
+ # VagrantError#initialize to avoid i18n translations, because we are
12
+ # just passing on the message 'bundle show' returns
13
+ #
14
+ # This call effectively calls initialize on VagrantError's superclass
15
+ # StandardError
16
+ StandardError.instance_method(:initialize).bind(self).call(message)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -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'
@@ -0,0 +1,11 @@
1
+ en:
2
+ vagrant_bundler:
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
+
7
+ Run
8
+
9
+ bundle config path .bundled_gems && bundle install
10
+
11
+ On the guest to move the bundle to a location the host can access
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-bundler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joel Chippindale
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vagrant
16
+ requirement: &70333138871860 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70333138871860
25
+ - !ruby/object:Gem::Dependency
26
+ name: i18n
27
+ requirement: &70333138886480 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.5.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70333138886480
36
+ - !ruby/object:Gem::Dependency
37
+ name: rake
38
+ requirement: &70333138885220 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70333138885220
47
+ - !ruby/object:Gem::Dependency
48
+ name: rdoc
49
+ requirement: &70333138882700 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70333138882700
58
+ - !ruby/object:Gem::Dependency
59
+ name: minitest
60
+ requirement: &70333138881780 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70333138881780
69
+ description: ! 'vagrant-bundler is a vagrant plugin to make it possible to interact
70
+
71
+ with the guest''s bundled gems directory from the host.
72
+
73
+ '
74
+ email: joel@joelchippindale.com
75
+ executables: []
76
+ extensions: []
77
+ extra_rdoc_files:
78
+ - README.mdown
79
+ files:
80
+ - README.mdown
81
+ - lib/vagrant_bundler.rb
82
+ - lib/vagrant_bundler/command/base.rb
83
+ - lib/vagrant_bundler/command/bundle.rb
84
+ - lib/vagrant_bundler/command/bundle_list.rb
85
+ - lib/vagrant_bundler/command/bundle_open.rb
86
+ - lib/vagrant_bundler/command/bundle_show.rb
87
+ - lib/vagrant_bundler/errors.rb
88
+ - lib/vagrant_init.rb
89
+ - templates/locales/en.yml
90
+ homepage: http://github.com/mocoso/vagrant-bundler
91
+ licenses: []
92
+ post_install_message:
93
+ rdoc_options:
94
+ - --main
95
+ - README.mdown
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ segments:
105
+ - 0
106
+ hash: -147202364419629032
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.11
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: Vagrant plugin for working with the guest's bundled gems
119
+ test_files: []