auto-gemsets 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Changelog.md CHANGED
@@ -1,5 +1,10 @@
1
1
  #Changelog
2
2
 
3
+ ## Version 0.2.0
4
+ - init command to copy script to /usr/local/share/auto_gemsets
5
+ - utility to install gems in the default gemset from anywhere
6
+ - utility to remove gems from the default gemset from anywhere
7
+
3
8
  ## Version 0.1.7
4
9
  - Fixed a bug where calling gemset with -v would error
5
10
  - Set appropriate gem bin directories in PATH
data/HELP.md ADDED
@@ -0,0 +1,61 @@
1
+ When the gemset command is called with no arguments,
2
+ it simply displays the current gemset in use.
3
+ Note that the GEM environment includes both
4
+ the current and default gemset's gems.
5
+
6
+ gemset -h/--help
7
+ gemset -v/--version
8
+ gemset [command] [arguments...]
9
+
10
+ Examples:
11
+ ---------
12
+ gemset list
13
+ gemset remove mygemset
14
+ gemset create mygemset
15
+ gemset rename mygemset awesome-gemset
16
+ gemset edit mygemset
17
+ gemset help
18
+ gemset version
19
+
20
+ Commands:
21
+ ========
22
+
23
+ ls, list
24
+ --------
25
+ gemset ls
26
+ gemset list
27
+
28
+ List all gemsets in your `GEMSET_ROOT`.
29
+ The gemset with the -> at the begining is the current gemset.
30
+ The gemset with the * at the end is the default gemset.
31
+ Note that the GEM environment includes both the current and default gemset's gems.
32
+
33
+ rm, remove
34
+ ----------
35
+ gemset rm (gemset)
36
+ gemset remove (gemset)
37
+
38
+ Removes the given gemset from the `GEMSET_ROOT`.
39
+ To prevent unwanted deletions, a confirmation dialog will ask if you wish to continue.
40
+
41
+ touch, create
42
+ -------------
43
+ gemset touch (gemset)
44
+ gemset create (gemset)
45
+
46
+ Create a new gemset in the `GEMSET_ROOT` with the given name
47
+
48
+ mv, rename
49
+ ----------
50
+ gemset mv (gemset) (name)
51
+ gemset rename (gemset) (name)
52
+
53
+ Renames the given gemset with the given name within the `GEMSET_ROOT`.
54
+ If the new gemset name conflicts with an existing gemset,
55
+ a confirmation dialog will ask if you wish to continue
56
+
57
+ edit
58
+ ----
59
+ gemset edit (gemset)
60
+
61
+ Opens the gemset's Gemfile in your default `EDITOR` or `TERM_EDITOR`
data/README.md CHANGED
@@ -1,4 +1,55 @@
1
1
  auto-gemsets
2
2
  ==============
3
3
 
4
- Automatic, shimless, bundler-managed gemsets for chruby
4
+ Tired of typing `rbenv-rehash`, `rvm gemset use`, and `rvm gemset create` for every project? `auto-gemsets` is for you.
5
+
6
+ Any `Gemfile` you encounter will cause auto-gemsets to automatically create and switch to a gemset based on the Gemfile's parent folder. Given a `Gemfile` in a directory named `my-project`, auto-gemsets will create a `~/.gemsets/my-project` directory (if one does not exist), and set all the GEM environment variables appropriate to that gemset. This means that you can enjoy sandboxed gem environments without having to micro-manage your GEM environment.
7
+
8
+ ## Installation
9
+
10
+ ### Using RubyGems:
11
+
12
+ gem install auto-gemsets
13
+ gemset init
14
+
15
+ ### Configuration:
16
+
17
+ The `gemset init` command will create a copy of `auto_gemsets.sh` into `/usr/local/share/auto_gemsets` To use auto-gemsets, you will need to source this file in your `~/.bashrc` (`~/.bash_profile` on OSX) or `~/.zshrc` file.
18
+
19
+ source /usr/local/share/auto_gemsets/auto_gemsets.sh
20
+
21
+ That's it, reload your `.bashrc` (`source ~/.bashrc`) or open a new terminal and auto-gemsets will now be managing your ruby gems environment.
22
+
23
+ NOTE: If you've already installed `auto-gemsets` you will receive a warning asking you if you wish to overwrite this installation. You may want to do this after updating your `auto-gemsets` version
24
+
25
+ ### Default Gemset:
26
+
27
+ If you wish to have certain gems available globally no matter what project you're in, you may set a `DEFAULT_GEMSET` variable that points to a gemset directory that will be available no matter what specific project gemset is currently in use. To set a default gemset simply add the `DEFAULT_GEMSET` variable in your `.bashrc` or `.zshrc` file (it must be a valid path):
28
+
29
+ # auto-gemsets
30
+ export DEFAULT_GEMSET="$HOME/.gemsets/$USER"
31
+
32
+ auto-gemsets will add this gemset to your `GEM_PATH` and add it's bin directory to your `PATH`. This gemset will always be active. When another gemset is also active, installed gems will automatically belong to that gemset. When _ONLY_ the default gemset is active, installed gems will belong to the default gemset.
33
+
34
+ ## Command Line
35
+
36
+ Although auto-gemsets focuses on automatic management of your gemsets, there are times when interaction is necessary. For these occaisions, auto-gemsets comes with a command line application named `gemset`.
37
+
38
+ See the [HELP](https://github.com/daytonn/auto-gemsets/blob/master/HELP.md) file for `gemset`'s Documentation.
39
+
40
+ ## default-gemset
41
+ The defalt-gemset command is an auto-gems utility to manage gems
42
+ in the default* gemset from within other gemsets.
43
+
44
+ ### Usage:
45
+
46
+ default-gemset (command) [options]
47
+
48
+ ### Examples:
49
+
50
+ default-gemset install rake
51
+ default-gemset uninstall rake -v=10.0.1
52
+ default-gemset list --local
53
+
54
+ `default-gemset` accepts any valid `gem` command, with any valid arguments and options.
55
+ It is simply a pass-through to the `gem` command with the context of the default gemset.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.7
1
+ 0.2.0
data/auto-gemsets.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "auto-gemsets"
8
- s.version = "0.1.7"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Dayton Nolan"]
12
- s.date = "2012-12-22"
12
+ s.date = "2012-12-23"
13
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
14
  s.email = "dnolan@gmail.com"
15
15
  s.executables = ["gemset"]
@@ -21,16 +21,16 @@ Gem::Specification.new do |s|
21
21
  "Changelog.md",
22
22
  "Gemfile",
23
23
  "Gemfile.lock",
24
- "HELP",
24
+ "HELP.md",
25
25
  "LICENSE",
26
26
  "README.md",
27
27
  "Rakefile",
28
28
  "VERSION",
29
29
  "auto-gemsets.gemspec",
30
- "auto_gemsets.sh",
31
30
  "bin/gemset",
32
31
  "lib/auto-gemsets.rb",
33
32
  "lib/auto-gemsets/application.rb",
33
+ "lib/auto-gemsets/auto_gemsets.sh",
34
34
  "spec/application_spec.rb",
35
35
  "spec/auto-gemsets_spec.rb",
36
36
  "spec/spec_helper.rb"
data/lib/auto-gemsets.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module AutoGemsets
2
2
  ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
3
  GEMSET_ROOT = ENV['GEMSET_ROOT'] || File.join(ENV['HOME'], '.gemsets')
4
+ INSTALL_ROOT = File.join('/', 'usr', 'local', 'share', 'auto_gemsets')
4
5
  VERSION = File.read "#{ROOT}/VERSION"
5
- HELP = File.read "#{ROOT}/HELP"
6
+ HELP = File.read "#{ROOT}/HELP.md"
6
7
 
7
8
  def self.on_windows?
8
9
  (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
@@ -86,7 +86,7 @@ module AutoGemsets
86
86
  @output.puts "#{new_gemset} already exists!"
87
87
  @output.puts "Do you really wish to replace #{new_gemset} with #{gemset}? y/n"
88
88
 
89
- confirmation = @input.gets.chomp
89
+ confirmation = @input.gets
90
90
  if confirmation =~ /^y/i
91
91
  FileUtils.rm_rf(gemset_path(new_gemset))
92
92
  if FileUtils.mv(gemset_path(gemset), gemset_path(new_gemset))
@@ -104,7 +104,7 @@ module AutoGemsets
104
104
 
105
105
  def rm(gemset)
106
106
  @output.puts "Are you sure you wish to delete the #{gemset} gemset? y/n"
107
- confirmation = @input.gets.chomp
107
+ confirmation = @input.gets
108
108
  if confirmation =~ /^y/i
109
109
  if File.exists?(gemset_path(gemset)) && FileUtils.rm_rf(gemset_path(gemset))
110
110
  @output.puts "#{gemset} gemset removed!"
@@ -139,6 +139,23 @@ module AutoGemsets
139
139
  %x{#{ENV['EDITOR'] || ENV['TERM_EDITOR']} #{ENV['GEMFILE']}} if File.exists ENV['GEMFILE']
140
140
  end
141
141
 
142
+ def init
143
+ FileUtils.mkdir_p(AutoGemsets::INSTALL_ROOT) unless File.exists? AutoGemsets::INSTALL_ROOT
144
+ script_file = File.join(AutoGemsets::ROOT, 'lib', 'auto-gemsets', 'auto_gemsets.sh')
145
+ if File.exists? script_file
146
+ @output.puts "auto-gemsets is already installed!"
147
+ @output.puts "Do you wish overwrite this installation? y/n"
148
+ confirmation = @input.gets
149
+ if confirmation =~ /^y/i
150
+
151
+ else
152
+ @output.puts "Existing installation preserved."
153
+ end
154
+ end
155
+ FileUtils.cp(script_file, AutoGemsets::INSTALL_ROOT)
156
+ FileUtils.chmod("a+x", "#{AutoGemsets::INSTALL_ROOT}/auto_gemsets.sh")
157
+ end
158
+
142
159
  private
143
160
  def parse_options
144
161
  @options = {}
@@ -1,3 +1,14 @@
1
+ SILENT="off"
2
+
3
+ ag_silent() {
4
+ if [ -n "$1" ] && [ "$1" == "on" ]; then
5
+ SILENT="on"
6
+ else
7
+ SILENT="off"
8
+ fi
9
+
10
+ }
11
+
1
12
  ag_set_default_gemset() {
2
13
  if [ -n "${DEFAULT_GEMSET}" ]; then
3
14
  if [ ! "$GEM_PATH" == "${DEFAULT_GEMSET}" ]; then
@@ -22,7 +33,9 @@ ag_set_default_gemset() {
22
33
  }
23
34
 
24
35
  ag_using_gemset_via() {
25
- echo "Now using $GEMSET gemset via $1"
36
+ if [ "$SILENT" == "off" ]; then
37
+ echo "Now using $GEMSET gemset via $1"
38
+ fi
26
39
  }
27
40
 
28
41
  ag_remove_path() {
@@ -105,6 +118,38 @@ ag_create_gemset_if_missing() {
105
118
  fi
106
119
  }
107
120
 
121
+ default-gemset() {
122
+ if [ -n "$1" ]; then
123
+ ag_silent "on"
124
+ G="$GEMSET"
125
+ ag_set_default_gemset
126
+ gem "$@"
127
+ ag_set_gemset "$G"
128
+ ag_silent "off"
129
+ else
130
+ cat <<EOF
131
+ The defalt-gemset command is an auto-gems utility to manage gems
132
+ in the default* gemset from within other gemsets.
133
+
134
+ Usage:
135
+ ------
136
+
137
+ default-gemset (command) [options]
138
+
139
+ Examples:
140
+ ---------
141
+
142
+ default-gemset install mygem
143
+ default-gemset uninstall mygem
144
+ default-gemset list
145
+
146
+ `default-gemset` accepts any valid `gem` command, with any valid arguments and options.
147
+ It is simply a pass-through to the `gem` command with the context of the default gemset.
148
+ EOF
149
+
150
+ fi
151
+ }
152
+
108
153
  # Create a GEMSET_ROOT if none is set
109
154
  if [ ! -n "$GEMSET_ROOT" ]; then
110
155
  export GEMSET_ROOT="${HOME}/.gemsets"
@@ -126,4 +171,6 @@ else
126
171
  fi
127
172
 
128
173
  # Set default when sourced
129
- ag_set_default_gemset
174
+ ag_silent "on"
175
+ ag_set_default_gemset
176
+ ag_silent "off"
@@ -130,4 +130,42 @@ describe AutoGemsets::Application do
130
130
 
131
131
  end
132
132
 
133
+ describe 'init' do
134
+
135
+ before do
136
+ @script_file = File.join('/', 'usr', 'local', 'share', 'auto_gemsets', 'auto_gemsets.sh')
137
+ FileUtils.mv(@script_file, "#{@script_file}.bak") if File.exists?(@script_file)
138
+ end
139
+
140
+ after do
141
+ FileUtils.rm_rf(@script_file) if File.exists?(@script_file)
142
+ FileUtils.mv("#{@script_file}.bak", @script_file) if File.exists?("#{@script_file}.bak")
143
+ end
144
+
145
+ it "copies the auto_gemsets script in the share directory" do
146
+ @app.init
147
+ script_file = File.join(AutoGemsets::ROOT, 'lib', 'auto-gemsets', 'auto_gemsets.sh')
148
+ expect(File.read(@script_file)).to eq(File.read(script_file))
149
+ end
150
+
151
+ it "warns if the script is already loaded and does nothing when y is not pressed" do
152
+ FileUtils.touch @script_file
153
+ @output.should_receive(:puts).once.with("auto-gemsets is already installed!")
154
+ @output.should_receive(:puts).once.with("Do you wish overwrite this installation? y/n")
155
+ @output.should_receive(:puts).once.with("Existing installation preserved.")
156
+ @input.stub!(:gets).and_return("n")
157
+ @app.init
158
+ end
159
+
160
+ it "warns if the script is already loaded and overwrites it when y is pressed" do
161
+ FileUtils.touch @script_file
162
+ @output.should_receive(:puts).once.with("auto-gemsets is already installed!")
163
+ @output.should_receive(:puts).once.with("Do you wish overwrite this installation? y/n")
164
+ @input.stub!(:gets).and_return("y")
165
+ @app.init
166
+ expect(File.read(@script_file)).to eq(File.read(File.join(AutoGemsets::INSTALL_ROOT, 'auto_gemsets.sh')))
167
+ end
168
+
169
+ end
170
+
133
171
  end
@@ -14,6 +14,10 @@ describe AutoGemsets do
14
14
  expect(AutoGemsets::GEMSET_ROOT).to eq(File.join(ENV['HOME'], '.gemsets'))
15
15
  end
16
16
 
17
+ it "has an INSTALL_ROOT" do
18
+ expect(AutoGemsets::INSTALL_ROOT).to eq('/usr/local/share/auto_gemsets')
19
+ end
20
+
17
21
  it "has a VERSION" do
18
22
  expect(AutoGemsets::VERSION).to match(/\d+\.\d+\.\d+/)
19
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: auto-gemsets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-22 00:00:00.000000000 Z
12
+ date: 2012-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -121,16 +121,16 @@ files:
121
121
  - Changelog.md
122
122
  - Gemfile
123
123
  - Gemfile.lock
124
- - HELP
124
+ - HELP.md
125
125
  - LICENSE
126
126
  - README.md
127
127
  - Rakefile
128
128
  - VERSION
129
129
  - auto-gemsets.gemspec
130
- - auto_gemsets.sh
131
130
  - bin/gemset
132
131
  - lib/auto-gemsets.rb
133
132
  - lib/auto-gemsets/application.rb
133
+ - lib/auto-gemsets/auto_gemsets.sh
134
134
  - spec/application_spec.rb
135
135
  - spec/auto-gemsets_spec.rb
136
136
  - spec/spec_helper.rb
@@ -149,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
149
  version: '0'
150
150
  segments:
151
151
  - 0
152
- hash: -185994835984614763
152
+ hash: 3895543352290661910
153
153
  required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  none: false
155
155
  requirements:
data/HELP DELETED
@@ -1,41 +0,0 @@
1
- gemset [command]
2
-
3
- When the gemset command is called with no arguments,
4
- it simply displays the current gemset in use.
5
- Note that the GEM environment includes both
6
- the current and default gemset's gems.
7
-
8
- Commands
9
- ========
10
-
11
- ls, list
12
- List all gemsets in your GEMSET_ROOT.
13
- The gemset with the -> at the begining is the current gemset.
14
- The gemset with the * at the end is the default gemset.
15
- Note that the GEM environment includes both the current and default gemset's gems.
16
-
17
- rm, remove
18
- gemset rm (gemset)
19
- gemset remove (gemset)
20
-
21
- Removes the given gemset from the GEMSET_ROOT.
22
- To prevent unwanted deletions, a confirmation dialog will ask if you wish to continue.
23
-
24
- touch, create
25
- gemset touch (gemset)
26
- gemset create (gemset)
27
-
28
- Create a new gemset in the GESET_ROOT with the given name
29
-
30
- mv, rename
31
- gemset mv (gemset) (name)
32
- gemset rename (gemset) (name)
33
-
34
- Renames the given gemset with the given name within the GESET_ROOT.
35
- If the new gemset name conflicts with an existing gemset,
36
- a confirmation dialog will ask if you wish to continue
37
-
38
- edit
39
- gemset edit (gemset)
40
-
41
- Opens the gemset's Gemfile in your default EDITOR or TERM_EDITOR