auto-gemsets 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec"
5
+ gem "jeweler"
6
+ gem "rformat"
7
+ gem "pry"
8
+ gem "pry-nav"
9
+ gem "pry-doc"
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,67 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ coderay (1.0.8)
5
+ diff-lcs (1.1.3)
6
+ fuubar (1.1.0)
7
+ rspec (~> 2.0)
8
+ rspec-instafail (~> 0.2.0)
9
+ ruby-progressbar (~> 1.0.0)
10
+ git (1.2.5)
11
+ jeweler (1.8.4)
12
+ bundler (~> 1.0)
13
+ git (>= 1.2.5)
14
+ rake
15
+ rdoc
16
+ json (1.7.5)
17
+ method_source (0.8.1)
18
+ nyan-cat-formatter (0.2.0)
19
+ pry (0.9.10)
20
+ coderay (~> 1.0.5)
21
+ method_source (~> 0.8)
22
+ slop (~> 3.3.1)
23
+ pry-doc (0.4.4)
24
+ pry (>= 0.9.9.6)
25
+ yard (~> 0.8.1)
26
+ pry-nav (0.2.2)
27
+ pry (~> 0.9.10)
28
+ rake (10.0.3)
29
+ rdoc (3.12)
30
+ json (~> 1.4)
31
+ rformat (0.1.2)
32
+ fuubar
33
+ nyan-cat-formatter
34
+ rspec-formatter-webkit
35
+ rspec-nc
36
+ unicorn-formatter
37
+ rspec (2.12.0)
38
+ rspec-core (~> 2.12.0)
39
+ rspec-expectations (~> 2.12.0)
40
+ rspec-mocks (~> 2.12.0)
41
+ rspec-core (2.12.2)
42
+ rspec-expectations (2.12.1)
43
+ diff-lcs (~> 1.1.3)
44
+ rspec-formatter-webkit (2.2.0)
45
+ rspec-core (~> 2.7)
46
+ rspec-instafail (0.2.4)
47
+ rspec-mocks (2.12.0)
48
+ rspec-nc (0.0.4)
49
+ rspec (~> 2.9)
50
+ terminal-notifier (~> 1.4.2)
51
+ ruby-progressbar (1.0.2)
52
+ slop (3.3.3)
53
+ terminal-notifier (1.4.2)
54
+ unicorn-formatter (0.1.3)
55
+ rspec
56
+ yard (0.8.3)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ jeweler
63
+ pry
64
+ pry-doc
65
+ pry-nav
66
+ rformat
67
+ rspec
data/HELP ADDED
@@ -0,0 +1,17 @@
1
+ When gemset is called without a sub command, it will display the current gemset.
2
+ The gemset command also has various sub-commands that help you manage your gemset library
3
+
4
+ Usage: gemset [command]
5
+
6
+ gemset - display current gemset
7
+
8
+ commands:
9
+
10
+ list - list all gemsets in your GEMSET_ROOT
11
+
12
+ gemset list
13
+
14
+ rm - completely remove a gemset from your GEMSET_ROOT
15
+
16
+ gemset rm my-gemset
17
+
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2012 Dayton Nolan
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ auto-gemsets
2
+ ==============
3
+
4
+ Automatic, shimless, bundler-managed gemsets for chruby
data/Rakefile ADDED
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "auto-gemsets"
18
+ gem.homepage = "http://github.com/daytonn/auto-gemsets"
19
+ gem.license = "Apache 2.0"
20
+ gem.summary = %Q{Automatic, shimless, gemsets. For use with your ruby-version manager of choice.}
21
+ gem.description = %Q{auto-gemsets creates a gemset named after the parent directory of every Gemfile you encounter. This let's you automatically scope your gems without using shims or creating gemsets. }
22
+ gem.email = "dnolan@gmail.com"
23
+ gem.authors = ["Dayton Nolan"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "auto-gemsets #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,70 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "auto-gemsets"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Dayton Nolan"]
12
+ s.date = "2012-12-21"
13
+ s.description = "auto-gemsets creates a gemset named after the parent directory of every Gemfile you encounter. This let's you automatically scope your gems without using shims or creating gemsets. "
14
+ s.email = "dnolan@gmail.com"
15
+ s.executables = ["gemset"]
16
+ s.extra_rdoc_files = [
17
+ "LICENSE",
18
+ "README.md"
19
+ ]
20
+ s.files = [
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "HELP",
24
+ "LICENSE",
25
+ "README.md",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "auto-gemsets.gemspec",
29
+ "bin/gemset",
30
+ "gemsets.sh",
31
+ "lib/auto-gemsets.rb",
32
+ "lib/auto-gemsets/application.rb",
33
+ "spec/application_spec.rb",
34
+ "spec/auto-gemsets_spec.rb",
35
+ "spec/spec_helper.rb"
36
+ ]
37
+ s.homepage = "http://github.com/daytonn/auto-gemsets"
38
+ s.licenses = ["Apache 2.0"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = "1.8.23"
41
+ s.summary = "Automatic, shimless, gemsets. For use with your ruby-version manager of choice."
42
+
43
+ if s.respond_to? :specification_version then
44
+ s.specification_version = 3
45
+
46
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
+ s.add_development_dependency(%q<rspec>, [">= 0"])
48
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
49
+ s.add_development_dependency(%q<rformat>, [">= 0"])
50
+ s.add_development_dependency(%q<pry>, [">= 0"])
51
+ s.add_development_dependency(%q<pry-nav>, [">= 0"])
52
+ s.add_development_dependency(%q<pry-doc>, [">= 0"])
53
+ else
54
+ s.add_dependency(%q<rspec>, [">= 0"])
55
+ s.add_dependency(%q<jeweler>, [">= 0"])
56
+ s.add_dependency(%q<rformat>, [">= 0"])
57
+ s.add_dependency(%q<pry>, [">= 0"])
58
+ s.add_dependency(%q<pry-nav>, [">= 0"])
59
+ s.add_dependency(%q<pry-doc>, [">= 0"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<rspec>, [">= 0"])
63
+ s.add_dependency(%q<jeweler>, [">= 0"])
64
+ s.add_dependency(%q<rformat>, [">= 0"])
65
+ s.add_dependency(%q<pry>, [">= 0"])
66
+ s.add_dependency(%q<pry-nav>, [">= 0"])
67
+ s.add_dependency(%q<pry-doc>, [">= 0"])
68
+ end
69
+ end
70
+
data/bin/gemset ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path(File.join(File.dirname(__FILE__), "../lib"))
3
+ require 'auto-gemsets'
4
+ AutoGemsets::application.run
data/gemsets.sh ADDED
@@ -0,0 +1,98 @@
1
+ function create_or_switch_gemset() {
2
+ if [ ! -d "${GEMSET_PATH}" ]; then
3
+ mkdir -p "${GEMSET_PATH}"
4
+ echo "${GEMSET} created. run gem install bundler"
5
+ fi
6
+
7
+ switch_gemset
8
+ }
9
+
10
+ function switch_gemset() {
11
+ export GEM_PATH="${GEMSET_PATH}"
12
+ export GEM_HOME="${GEMSET_PATH}"
13
+ export GEM_ROOT="${GEMSET_PATH}"
14
+ echo "Now using ${GEMSET} gemset via ${GEMFILE}"
15
+ break
16
+ }
17
+
18
+ function chruby_gemset() {
19
+ local dir="$PWD"
20
+ local version_file
21
+
22
+ until [[ -z "$dir" ]]; do
23
+ gemfile="$dir/Gemfile"
24
+ IFS='/' read -a gemfile_path_parts <<< "$gemfile"
25
+
26
+ gemset="${gemfile_path_parts[${#gemfile_path_parts[@]}-2]}"
27
+
28
+ if [[ "${GEMSET_ROOT}/$gemset" == "$GEMSET_PATH" ]]; then return
29
+ elif [[ -f "$gemfile" ]]; then
30
+ export GEMSET_PATH="${GEMSET_ROOT}/$gemset"
31
+ export GEMSET="${gemset}"
32
+ export GEMFILE="${gemfile}"
33
+ create_or_switch_gemset
34
+ fi
35
+
36
+ dir="${dir%/*}"
37
+ done
38
+ }
39
+
40
+ function gemplode() {
41
+
42
+ if [ ! -z "$1" ]; then
43
+ echo "${GEMSET_ROOT}/${1}"
44
+ if [ -d "${GEMSET_ROOT}/${1}" ]; then
45
+ echo "Are you sure you want to delete the ${1} gemset? y/n"
46
+ read response
47
+
48
+ if [ "$response" == "y" ]; then
49
+ rm -Rf ${GEMSET_ROOT}/${1}
50
+ chruby_reset
51
+ else
52
+ echo "No gemset removed"
53
+ fi
54
+ else
55
+ echo "No gemset named ${1}"
56
+ fi
57
+
58
+ else
59
+ echo "Usage:"
60
+ echo "gemplode (gemset)"
61
+ fi
62
+ }
63
+
64
+ function gemset() {
65
+ if [ -z "$1" ]; then
66
+ echo "${GEMSET}"
67
+ else
68
+ case "$1" in
69
+ "destroy" )
70
+ if [ ! -z "$2" ]; then
71
+ gemplode $2
72
+ else
73
+ echo "Usage:"
74
+ echo "gemset destroy (gemset)"
75
+ fi
76
+ ;;
77
+ "list" )
78
+ ls -l "${GEMSET_ROOT}"
79
+ ;;
80
+ esac
81
+ fi
82
+ }
83
+
84
+ if [ ! -n "$GEMSET_ROOT" ]; then
85
+ export GEMSET_ROOT="${HOME}/.gemsets"
86
+ fi
87
+
88
+ if [[ -n "$ZSH_VERSION" ]]; then
89
+ precmd_functions+=("chruby_gemset")
90
+ else
91
+ if [[ -n "$PROMPT_COMMAND" ]]; then
92
+ if [[ ! "$PROMPT_COMMAND" == *chruby_gemset* ]]; then
93
+ PROMPT_COMMAND="$PROMPT_COMMAND; chruby_gemset"
94
+ fi
95
+ else
96
+ PROMPT_COMMAND="chruby_gemset"
97
+ fi
98
+ fi
@@ -0,0 +1,24 @@
1
+ module AutoGemsets
2
+ ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+ GEMSET_ROOT = ENV['GEMSET_ROOT'] || File.join(ENV['HOME'], '.gemsets')
4
+ VERSION = File.read "#{ROOT}/VERSION"
5
+ HELP = File.read "#{ROOT}/HELP"
6
+
7
+ def self.on_windows?
8
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
9
+ end
10
+
11
+ def self.on_osx?
12
+ (/darwin/ =~ RUBY_PLATFORM) != nil
13
+ end
14
+
15
+ def self.on_unix?
16
+ !on_windows?
17
+ end
18
+
19
+ def self.on_linux?
20
+ on_unix? and not on_osx?
21
+ end
22
+ end
23
+
24
+ require "auto-gemsets/application"
@@ -0,0 +1,148 @@
1
+ require 'optparse'
2
+ require 'fileutils'
3
+
4
+ module AutoGemsets
5
+
6
+ class << self
7
+
8
+ def application
9
+ @application ||= AutoGemsets::Application.new
10
+ end
11
+
12
+ end
13
+
14
+ class Application
15
+
16
+ attr_reader :args,
17
+ :command,
18
+ :options
19
+
20
+ def initialize(output = $stdout, input = $stdin, args = Array.try_convert(ARGV))
21
+ @output = output
22
+ @input = input
23
+ @args = args
24
+ @command = @args.empty? ? :current : @args.shift.to_sym
25
+
26
+ parse_options
27
+ end
28
+
29
+ def current
30
+ @output.puts ENV['GEMSET']
31
+ end
32
+
33
+ def run
34
+ if @command
35
+ self.send @command, *@args unless @command =~ /^-/
36
+ else
37
+ help
38
+ end
39
+ end
40
+
41
+ def ls
42
+ @output.puts Dir.glob(File.join(ENV['HOME'], '.gemsets', '*')).map { |d| File.basename(d) }.join "\n"
43
+ end
44
+
45
+ def list
46
+ ls
47
+ end
48
+
49
+ def touch(gemset)
50
+ if !File.exists?(gemset_path(gemset)) && FileUtils.mkdir_p(gemset_path(gemset))
51
+ @output.puts "#{gemset} gemset created"
52
+ end
53
+ end
54
+
55
+ def create(gemset)
56
+ touch(gemset)
57
+ end
58
+
59
+ def mv(gemset, new_gemset)
60
+ if !File.exists?(gemset_path(new_gemset))
61
+ if FileUtils.mv(gemset_path(gemset), gemset_path(new_gemset))
62
+ @output.puts "#{gemset} renamed to #{new_gemset}"
63
+ end
64
+ else
65
+ @output.puts "#{new_gemset} already exists!"
66
+ @output.puts "Do you really wish to replace #{new_gemset} with #{gemset}? y/n"
67
+
68
+ confirmation = @input.gets.chomp
69
+ if confirmation =~ /^y/i
70
+ FileUtils.rm_rf(gemset_path(new_gemset))
71
+ if FileUtils.mv(gemset_path(gemset), gemset_path(new_gemset))
72
+ @output.puts "#{gemset} renamed to #{new_gemset}"
73
+ end
74
+ else
75
+ @output.puts "No gemsets were harmed."
76
+ end
77
+ end
78
+ end
79
+
80
+ def rename(gemset, new_gemset)
81
+ mv(gemset, new_gemset)
82
+ end
83
+
84
+ def rm(gemset)
85
+ @output.puts "Are you sure you wish to delete the #{gemset} gemset? y/n"
86
+ confirmation = @input.gets.chomp
87
+ if confirmation =~ /^y/i
88
+ if File.exists?(gemset_path(gemset)) && FileUtils.rm_rf(gemset_path(gemset))
89
+ @output.puts "#{gemset} gemset removed!"
90
+ end
91
+ else
92
+ @output.puts "No gemsets were harmed."
93
+ end
94
+ end
95
+
96
+ def remove(gemset)
97
+ rm(gemset)
98
+ end
99
+
100
+ def open(gemset=nil)
101
+ if AutoGemsets::on_OSX?
102
+ if gemset
103
+ if File.exists?(gemset_path(gemset))
104
+ %x{open #{gemset_path(gemset)}}
105
+ else
106
+ @output.puts "No gemset named #{gemset}!"
107
+ end
108
+ else
109
+ %x{open #{AutoGemsets::GEMSET_ROOT}}
110
+ end
111
+ else
112
+ @output.puts "currently this command is only available for OS X users"
113
+ end
114
+ end
115
+
116
+ private
117
+ def parse_options
118
+ @options = {}
119
+ OptionParser.new do |opts|
120
+ opts.on("-v", "--version", "Version info") do
121
+ @options[:version] = true
122
+ version
123
+ end
124
+
125
+ opts.on('-h', '--help', 'Display help') do
126
+ @options[:help] = true
127
+ help
128
+ end
129
+ end.parse!
130
+ end
131
+
132
+ def help
133
+ puts AutoGemsets::HELP
134
+ end
135
+
136
+ def version
137
+ version = File.read("#{AutoGemsets::base_directory}/VERSION")
138
+ message = "auto-gemsets #{version}\n"
139
+ message << "Copyright (c) #{Time.now.year} Dayton Nolan\n"
140
+ puts message
141
+ end
142
+
143
+ def gemset_path(gemset)
144
+ File.join(AutoGemsets::GEMSET_ROOT, gemset)
145
+ end
146
+ end
147
+
148
+ end
@@ -0,0 +1,121 @@
1
+ require 'auto-gemsets/application'
2
+ require 'securerandom'
3
+
4
+ describe AutoGemsets::Application do
5
+
6
+ before do
7
+ @output = StringIO.new
8
+ @input = StringIO.new
9
+ @app = AutoGemsets::Application.new @output, @input
10
+ @gemset = SecureRandom::hex
11
+ @random_gemset = File.join(ENV['HOME'], '.gemsets', @gemset)
12
+ FileUtils.mkdir_p(@random_gemset)
13
+ end
14
+
15
+ after do
16
+ FileUtils.rm_rf(@random_gemset) if File.exists? @random_gemset
17
+ end
18
+
19
+ describe 'current' do
20
+ before do
21
+ @env_gemset = ENV['GEMSET']
22
+ ENV['GEMSET'] = @gemset
23
+ end
24
+
25
+ after do
26
+ ENV['GEMSET'] = @env_gemset
27
+ end
28
+
29
+ it "shows the current gemset" do
30
+ @output.should_receive(:puts).with(@gemset)
31
+ @app.current
32
+ end
33
+
34
+ it "shows the current gemset when called with no arguments" do
35
+ @output.should_receive(:puts).with(@gemset)
36
+ app = AutoGemsets::Application.new(@output, @input, [])
37
+ app.run
38
+ end
39
+ end
40
+
41
+ describe "list" do
42
+ it "can list all gemsets in the GEMSET_ROOT" do
43
+ @output.should_receive(:puts) { |list| expect(list).to match(/#{@gemset}/) }
44
+ @app.list
45
+ end
46
+ end
47
+
48
+ describe 'remove' do
49
+ it "confirms the rm command and does nothing if the user enters anything but y" do
50
+ @output.should_receive(:puts).once.with("Are you sure you wish to delete the #{@gemset} gemset? y/n")
51
+ @output.should_receive(:puts).once.with("No gemsets were harmed.")
52
+ @input.stub!(:gets) { "n" }
53
+ @app.remove @gemset
54
+ expect(File.exists?(@random_gemset)).to be_true
55
+ end
56
+
57
+ it "removes the gemset if the user enters y" do
58
+ @output.should_receive(:puts).once.with("Are you sure you wish to delete the #{@gemset} gemset? y/n")
59
+ @output.should_receive(:puts).once.with("#{@gemset} gemset removed!")
60
+ @input.stub!(:gets) { "y" }
61
+ @app.remove @gemset
62
+ expect(File.exists?(@random_gemset)).to be_false
63
+ end
64
+ end
65
+
66
+ describe 'create' do
67
+ before do
68
+ @name = SecureRandom::hex
69
+ @expected_path = File.join(ENV['HOME'], '.gemsets', @name)
70
+ end
71
+
72
+ after do
73
+ FileUtils.rm_rf(@expected_path) if File.exists? @expected_path
74
+ end
75
+
76
+ it "creates a gemset" do
77
+ @output.should_receive(:puts).once.with("#{@name} gemset created")
78
+ @app.create(@name)
79
+ expect(File.exists?(@expected_path)).to be_true
80
+ end
81
+ end
82
+
83
+ describe 'rename' do
84
+ before do
85
+ @name_a = SecureRandom::hex
86
+ @name_b = SecureRandom::hex
87
+ @gemset_a = File.join(ENV['HOME'], '.gemsets', @name_a)
88
+ @gemset_b = File.join(ENV['HOME'], '.gemsets', @name_b)
89
+
90
+ FileUtils.mkdir_p(@gemset_a)
91
+ FileUtils.mkdir_p(@gemset_b)
92
+ end
93
+
94
+ after do
95
+ FileUtils.rm_rf(@gemset_a) if File.exists? @gemset_a
96
+ FileUtils.rm_rf(@gemset_b) if File.exists? @gemset_b
97
+ FileUtils.rm_rf(@new_gemset) if @new_gemset && File.exists?(@new_gemset)
98
+ end
99
+
100
+ it "moves a gemset to a new location" do
101
+ new_name = SecureRandom::hex
102
+ @new_gemset = File.join(ENV['HOME'], '.gemsets', new_name)
103
+
104
+ @output.should_receive(:puts).once.with("#{@name_a} renamed to #{new_name}")
105
+ @app.rename(@name_a, "#{new_name}")
106
+ expect(File.exists?(@new_gemset)).to be_true
107
+ expect(File.exists?(@gemset_a)).to be_false
108
+ end
109
+
110
+ it "it asks for permission to remove an existing destination" do
111
+ @output.should_receive(:puts).once.with("#{@name_b} already exists!")
112
+ @output.should_receive(:puts).once.with("Do you really wish to replace #{@name_b} with #{@name_a}? y/n")
113
+ @output.should_receive(:puts).once.with("#{@name_a} renamed to #{@name_b}")
114
+ @input.stub!(:gets) { "y" }
115
+ @app.rename(@name_a, @name_b)
116
+ expect(File.exists?(@gemset_a)).to be_false
117
+ end
118
+
119
+ end
120
+
121
+ end
@@ -0,0 +1,44 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe AutoGemsets do
4
+
5
+ before do
6
+ @root = File.expand_path('../', SPEC_ROOT)
7
+ end
8
+
9
+ it "has a ROOT directory" do
10
+ expect(AutoGemsets::ROOT).to eq(@root)
11
+ end
12
+
13
+ it "has a GEMSET_ROOT" do
14
+ expect(AutoGemsets::GEMSET_ROOT).to eq(File.join(ENV['HOME'], '.gemsets'))
15
+ end
16
+
17
+ it "has a VERSION" do
18
+ expect(AutoGemsets::VERSION).to match(/\d+\.\d+\.\d+/)
19
+ end
20
+
21
+ it "has a HELP file" do
22
+ expect(AutoGemsets::HELP).not_to be_empty
23
+ end
24
+
25
+ it "can tell if it's running on osx" do
26
+ expect(AutoGemsets::on_osx?).to eq(RUBY_PLATFORM[/darwin/] != nil)
27
+ end
28
+
29
+ it "can tell if it's running on windows" do
30
+ expect(AutoGemsets::on_windows?).to eq(RUBY_PLATFORM[/cygwin|mswin|mingw|bccwin|wince|emx/] == true)
31
+ end
32
+
33
+ it "can tell if it's running on linux" do
34
+ expect(AutoGemsets::on_linux?).to eq(
35
+ RUBY_PLATFORM[/cygwin|mswin|mingw|bccwin|wince|emx/] == nil &&
36
+ RUBY_PLATFORM[/darwin/] == nil
37
+ )
38
+ end
39
+
40
+ it "can tell if it's running on unix" do
41
+ expect(AutoGemsets::on_unix?).to eq(RUBY_PLATFORM[/cygwin|mswin|mingw|bccwin|wince|emx/] == nil)
42
+ end
43
+
44
+ end
@@ -0,0 +1,15 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'auto-gemsets'
5
+ require 'pry'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+
13
+ end
14
+
15
+ SPEC_ROOT = File.expand_path(File.join(File.dirname(__FILE__)))
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: auto-gemsets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dayton Nolan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jeweler
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rformat
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: pry
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry-nav
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: pry-doc
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: ! 'auto-gemsets creates a gemset named after the parent directory of
111
+ every Gemfile you encounter. This let''s you automatically scope your gems without
112
+ using shims or creating gemsets. '
113
+ email: dnolan@gmail.com
114
+ executables:
115
+ - gemset
116
+ extensions: []
117
+ extra_rdoc_files:
118
+ - LICENSE
119
+ - README.md
120
+ files:
121
+ - Gemfile
122
+ - Gemfile.lock
123
+ - HELP
124
+ - LICENSE
125
+ - README.md
126
+ - Rakefile
127
+ - VERSION
128
+ - auto-gemsets.gemspec
129
+ - bin/gemset
130
+ - gemsets.sh
131
+ - lib/auto-gemsets.rb
132
+ - lib/auto-gemsets/application.rb
133
+ - spec/application_spec.rb
134
+ - spec/auto-gemsets_spec.rb
135
+ - spec/spec_helper.rb
136
+ homepage: http://github.com/daytonn/auto-gemsets
137
+ licenses:
138
+ - Apache 2.0
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ none: false
145
+ requirements:
146
+ - - ! '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ segments:
150
+ - 0
151
+ hash: -3432436821644449709
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ requirements: []
159
+ rubyforge_project:
160
+ rubygems_version: 1.8.23
161
+ signing_key:
162
+ specification_version: 3
163
+ summary: Automatic, shimless, gemsets. For use with your ruby-version manager of choice.
164
+ test_files: []