auto-gemsets 0.3.0 → 0.4.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.
@@ -1,5 +1,18 @@
1
1
  #Changelog
2
2
 
3
+ ## Version 0.4.0 (unreleased)
4
+ - Create default gemset if one does not exist
5
+ - Complete shunit2 test suite coverage (and subsequent refactor/overhall)
6
+ - Default gemset is now simply called default
7
+ - Renamed `/usr/local/share/auto_gemsets` to `/usr/local/share/auto-gemsets`
8
+ - Added configuration file `~/.auto-gemsets` to turn on/off reporting
9
+ - `gemset init` creates `auto-gemsets.sh`, `default-gems.sh`, and `.auto-gemsets`
10
+ - `gemset init` creates the default gemset
11
+
12
+ ## Version 0.3.0
13
+ - No longer setting the auto_gemsets.sh file as executable
14
+ - Change `default-gemsets` to `default-gems`
15
+
3
16
  ## Version 0.2.1
4
17
  - add `init` command
5
18
 
data/HELP.md CHANGED
@@ -22,7 +22,7 @@ Commands:
22
22
 
23
23
  init
24
24
  ----
25
- This command will copy the auto_gemsets.sh script into the `/usr/local/share/auto_gemsets` folder. This is the small shell script that does the automatic switching for you. Once this file is in place, simply `source` it somewhere in your profile and auto-gemsets will be activated.
25
+ This command will copy the auto-gemsets.sh script into the `/usr/local/share/auto-gemsets` folder. This is the small shell script that does the automatic switching for you. Once this file is in place, simply `source` it somewhere in your profile and auto-gemsets will be activated.
26
26
 
27
27
  ls, list
28
28
  --------
data/README.md CHANGED
@@ -14,22 +14,31 @@ Any `Gemfile` you encounter will cause auto-gemsets to automatically create and
14
14
 
15
15
  ### Configuration:
16
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.
17
+ The `gemset init` command will create a copy of `auto-gemsets.sh` and `default-gems.sh` into `/usr/local/share/auto-gemsets` To use auto-gemsets, you will need to source these files in your `~/.bashrc` (`~/.bash_profile` on OSX) or `~/.zshrc` file.
18
18
 
19
- source /usr/local/share/auto_gemsets/auto_gemsets.sh
19
+ source /usr/local/share/auto-gemsets/auto-gemsets.sh
20
+ source /usr/local/share/auto-gemsets/default-gems.sh
21
+
22
+ In addition to these two scripts, `init` also creates a `~/.auto-gemsets` config file to allow for customization of `auto-gemsets`.
23
+
24
+ Once you source `.bashrc`, `.bash_profile`, or `~/.zshrc` (`source ~/.bashrc`) or open a new terminal auto-gemsets will now be active and managing your ruby gems.
20
25
 
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.
26
+ Since, `auto-gemsets` creates a new default gemset, you will need to reinstall `auto-gemsets` to use the `gemset` command.
22
27
 
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
28
+ gem install auto-gemsets
29
+
30
+ A NOTE ON UPGRADING: 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
31
 
25
32
  ### Default Gemset:
26
33
 
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):
34
+ A default gemset will be created for you when you run `gemset init` in `~/.gemsets/default`.
35
+
36
+ If you wish to override this location simply set the `DEFAULT_GEMSET` variable somewhere in your `.bashrc`, `.bash_profile`, or `.zshrc` depending on your environment:
28
37
 
29
38
  # auto-gemsets
30
- export DEFAULT_GEMSET="$HOME/.gemsets/$USER"
39
+ export DEFAULT_GEMSET="/custom/path/to/default_gemset"
31
40
 
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.
41
+ 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
42
 
34
43
  ## Command Line
35
44
 
@@ -37,19 +46,27 @@ Although auto-gemsets focuses on automatic management of your gemsets, there are
37
46
 
38
47
  See the [HELP](https://github.com/daytonn/auto-gemsets/blob/master/HELP.md) file for `gemset`'s Documentation.
39
48
 
49
+ There is also a utility that allows you to isolate your `default` gemset when running gem commands named `default-gems`
50
+
51
+ For more documentation simply type
52
+
53
+ default-gems
54
+
40
55
  ## default-gems
41
- The defalt-gemset command is an auto-gems utility to manage gems
56
+ The defalt-gems command is an auto-gemsets utility to manage gems
42
57
  in the default* gemset from within other gemsets.
43
58
 
44
- ### Usage:
59
+ Usage:
60
+ ------
45
61
 
46
- default-gems (command) [options]
62
+ default-gems (command) [options]
47
63
 
48
- ### Examples:
64
+ Examples:
65
+ ---------
49
66
 
50
- default-gems install rake
51
- default-gems uninstall rake -v=10.0.1
52
- default-gems list --local
67
+ default-gems install mygem
68
+ default-gems uninstall mygem
69
+ default-gems list
53
70
 
54
- `default-gems` 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.
71
+ default-gems accepts any valid gem command, with any valid arguments and options.
72
+ It is simply a pass-through to the gem command with the context of the default gemset.
data/Rakefile CHANGED
@@ -47,3 +47,12 @@ Rake::RDocTask.new do |rdoc|
47
47
  rdoc.rdoc_files.include('README*')
48
48
  rdoc.rdoc_files.include('lib/**/*.rb')
49
49
  end
50
+
51
+
52
+ namespace :sh do
53
+
54
+ task :test do
55
+ puts %x{sh test/runner}
56
+ end
57
+
58
+ end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.4.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "auto-gemsets"
8
- s.version = "0.3.0"
8
+ s.version = "0.4.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 = "2013-01-05"
12
+ s.date = "2013-01-07"
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"]
@@ -29,11 +29,22 @@ Gem::Specification.new do |s|
29
29
  "auto-gemsets.gemspec",
30
30
  "bin/gemset",
31
31
  "lib/auto-gemsets.rb",
32
+ "lib/auto-gemsets/.auto-gemsets",
32
33
  "lib/auto-gemsets/application.rb",
33
- "lib/auto-gemsets/auto_gemsets.sh",
34
+ "lib/auto-gemsets/auto-gemsets.sh",
35
+ "lib/auto-gemsets/default-gems.sh",
34
36
  "spec/application_spec.rb",
35
37
  "spec/auto-gemsets_spec.rb",
36
38
  "spec/spec_helper.rb",
39
+ "test/ag_add_path_test.sh",
40
+ "test/ag_init_test.sh",
41
+ "test/ag_parent_dir_test.sh",
42
+ "test/ag_remove_path_test.sh",
43
+ "test/ag_set_gemset_test.sh",
44
+ "test/auto_gemsets_test.sh",
45
+ "test/helper.sh",
46
+ "test/project/Gemfile",
47
+ "test/runner",
37
48
  "travis.yml"
38
49
  ]
39
50
  s.homepage = "http://github.com/daytonn/auto-gemsets"
@@ -1,7 +1,7 @@
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
+ INSTALL_ROOT = File.join('/', 'usr', 'local', 'share', 'auto-gemsets')
5
5
  VERSION = File.read "#{ROOT}/VERSION"
6
6
  HELP = File.read "#{ROOT}/HELP.md"
7
7
 
@@ -0,0 +1 @@
1
+ export AUTO_GEMSETS_REPORTING=on
@@ -117,22 +117,32 @@ module AutoGemsets
117
117
  end
118
118
 
119
119
  def init
120
- if File.exists? "/usr/local/share/auto_gemsets/auto_gemsets.sh"
120
+ if File.exists? script_file
121
121
  @output.puts "auto-gemsets is already installed!"
122
122
  confirm("Do you wish overwrite this installation?", {
123
123
  accept: -> {
124
- create_script
124
+ install_auto_gemsets
125
125
  },
126
126
  deny: -> {
127
127
  @output.puts "Existing installation preserved."
128
128
  }
129
129
  })
130
130
  else
131
- create_script
131
+ install_auto_gemsets
132
132
  end
133
133
  end
134
134
 
135
135
  private
136
+ def install_auto_gemsets
137
+ create_script 'auto-gemsets.sh'
138
+ create_script 'default-gems.sh'
139
+ config_file = File.join(ENV['HOME'], '.auto-gemsets')
140
+ default_gemset_dir = File.join(AutoGemsets::GEMSET_ROOT, 'default')
141
+ FileUtils.cp(File.join(AutoGemsets::ROOT, 'lib', 'auto-gemsets', '.auto-gemsets'), config_file) unless File.exists? config_file
142
+ FileUtils.mkdir_p(AutoGemsets::GEMSET_ROOT) unless File.exists?(AutoGemsets::GEMSET_ROOT)
143
+ FileUtils.mkdir_p(default_gemset_dir) unless File.exists?(default_gemset_dir)
144
+ end
145
+
136
146
  def parse_options
137
147
  @options = {}
138
148
  OptionParser.new do |opts|
@@ -189,12 +199,16 @@ module AutoGemsets
189
199
  end
190
200
 
191
201
  def script_file
192
- File.join(AutoGemsets::INSTALL_ROOT, "auto_gemsets.sh")
202
+ File.join(AutoGemsets::INSTALL_ROOT, "auto-gemsets.sh")
203
+ end
204
+
205
+ def default_gems_file
206
+ File.join(AutoGemsets::INSTALL_ROOT, "default-gems.sh")
193
207
  end
194
208
 
195
- def create_script
209
+ def create_script(script)
196
210
  FileUtils.mkdir_p(AutoGemsets::INSTALL_ROOT) unless File.exists? AutoGemsets::INSTALL_ROOT
197
- FileUtils.cp(File.join(AutoGemsets::ROOT, 'lib', 'auto-gemsets', 'auto_gemsets.sh'), AutoGemsets::INSTALL_ROOT)
211
+ FileUtils.cp(File.join(AutoGemsets::ROOT, 'lib', 'auto-gemsets', script), AutoGemsets::INSTALL_ROOT)
198
212
  end
199
213
  end
200
214
 
@@ -0,0 +1,120 @@
1
+ ag_init() {
2
+ export GEMSET_ROOT="$HOME/.gemsets"
3
+
4
+ if [ -z "${DEFAULT_GEMSET}" ]; then
5
+ export DEFAULT_GEMSET="default"
6
+ fi
7
+
8
+ if [ -r "${HOME}/.auto-gemsets" ]; then
9
+ source "${HOME}/.auto-gemsets"
10
+ fi
11
+
12
+ # If ZSH add precommand
13
+ if [[ -n "$ZSH_VERSION" ]]; then
14
+ precmd_functions+=("auto_gemsets")
15
+ else
16
+ # If there's already a prompt command,
17
+ if [ -n "$PROMPT_COMMAND" ]; then
18
+ # check if it's already in the PROMPT
19
+ if [ -z "$(echo $PROMPT_COMMAND | grep auto_gemsets)" ] ; then
20
+ PROMPT_COMMAND="$PROMPT_COMMAND; auto_gemsets"
21
+ fi
22
+ else
23
+ PROMPT_COMMAND="auto_gemsets"
24
+ fi
25
+ fi
26
+
27
+ auto_gemsets
28
+ }
29
+
30
+ ag_set_gemset() {
31
+ if [ "$GEMSET" == "$1" ]; then
32
+ return;
33
+ fi
34
+ export GEMSET="${1}"
35
+ export GEM_HOME="${GEMSET_ROOT}/$GEMSET"
36
+ export GEM_ROOT="$GEM_HOME" # for chruby
37
+ export GEM_PATH="$GEM_HOME"
38
+ ag_add_path "${GEM_HOME}/bin"
39
+
40
+ if [ ! "$GEMSET" == 'default' ]; then
41
+ ag_add_path "${GEMSET_ROOT}/default/bin"
42
+ export GEM_PATH="${GEM_PATH}:${GEMSET_ROOT}/default"
43
+ ag_using_gemset_via "$GEMFILE"
44
+ else
45
+ ag_using_gemset_via "*default"
46
+ fi
47
+
48
+ }
49
+
50
+ ag_remove_path() {
51
+ CLEAN_PATH=""
52
+ IFS=':' read -a PATHS <<< "$PATH"
53
+ # Rip through paths and build a new path without the directory
54
+ for p in "${PATHS[@]}"
55
+ do
56
+ if [ ! "$p" == "$1" ]; then
57
+ # first time through, set CLEAN_PATH
58
+ if [ -z "$CLEAN_PATH" ]; then
59
+ CLEAN_PATH="$p"
60
+ else
61
+ # append the path
62
+ CLEAN_PATH="$CLEAN_PATH:$p"
63
+ fi
64
+ fi
65
+ done
66
+ export PATH="$CLEAN_PATH"
67
+ }
68
+
69
+ ag_using_gemset_via() {
70
+ if [ "$AUTO_GEMSETS_REPORTING" == "on" ]; then
71
+ echo "Now using $GEMSET gemset via $1"
72
+ fi
73
+ }
74
+
75
+ ag_add_path() {
76
+ if ! echo $PATH | egrep -q "(^|:)$1($|:)" ; then
77
+ export PATH="$1:$PATH"
78
+ fi
79
+ }
80
+
81
+ ag_parent_dir() {
82
+ if [ ! -z "$1" ]; then
83
+ IFS='/' read -a path_parts <<< "$1"
84
+ echo "${path_parts[${#path_parts[@]}-2]}"
85
+ else
86
+ echo ""
87
+ fi
88
+ }
89
+
90
+ auto_gemsets() {
91
+ local dir="$PWD"
92
+
93
+ until [[ -z "$dir" ]]; do
94
+ if [ "$GEMSET" ] && [ "$GEMSET" == "$(ag_parent_dir ${dir}/Gemfile)" ]; then
95
+ return;
96
+ fi
97
+
98
+ if [ -f "$dir/Gemfile" ]; then
99
+ export GEMFILE="$dir/Gemfile"
100
+ ag_create_gemset_if_missing "$(ag_parent_dir $GEMFILE)"
101
+ ag_set_gemset "$(ag_parent_dir $GEMFILE)"
102
+ return;
103
+ fi
104
+
105
+ if [ -z "${dir%/*}" ]; then
106
+ ag_set_gemset 'default'
107
+ fi
108
+
109
+ dir="${dir%/*}"
110
+ done
111
+ }
112
+
113
+ ag_create_gemset_if_missing() {
114
+ if [ ! -d "${GEMSET_ROOT}/${1}" ]; then
115
+ mkdir -p "${GEMSET_ROOT}/${1}" && echo "${1} gemset created. run gem install bundler"
116
+ fi
117
+ }
118
+
119
+ # Kick it
120
+ ag_init
@@ -0,0 +1,32 @@
1
+ default-gems() {
2
+ if [ -z "$1" ]; then
3
+ cat <<EOF
4
+ The defalt-gems command is an auto-gemsets utility to manage gems
5
+ in the default* gemset from within other gemsets.
6
+
7
+ Usage:
8
+ ------
9
+
10
+ default-gems (command) [options]
11
+
12
+ Examples:
13
+ ---------
14
+
15
+ default-gems install mygem
16
+ default-gems uninstall mygem
17
+ default-gems list
18
+
19
+ default-gems accepts any valid gem command, with any valid arguments and options.
20
+ It is simply a pass-through to the gem command with the context of the default gemset.
21
+ EOF
22
+ else
23
+ if [ ! "$GEMSET" == 'default' ]; then
24
+ G="$GEMSET"
25
+ ag_set_gemset 'default' > /dev/null
26
+ gem "$@"
27
+ ag_set_gemset "$G" > /dev/null
28
+ else
29
+ gem "$@"
30
+ fi
31
+ fi
32
+ }
@@ -130,23 +130,37 @@ describe AutoGemsets::Application do
130
130
  describe 'init' do
131
131
 
132
132
  before do
133
- @script_file = File.join('/', 'usr', 'local', 'share', 'auto_gemsets', 'auto_gemsets.sh')
134
- FileUtils.mv(@script_file, "#{@script_file}.bak") if File.exists?(@script_file)
133
+ @scripts = {
134
+ auto_gemsets: File.join('/', 'usr', 'local', 'share', 'auto-gemsets', 'auto-gemsets.sh'),
135
+ default_gems: File.join('/', 'usr', 'local', 'share', 'auto-gemsets', 'default-gems.sh'),
136
+ config: File.join(ENV['HOME'], '.auto-gemsets')
137
+ }
138
+ FileUtils.mv(@scripts[:auto_gemsets], "#{@scripts[:auto_gemsets]}.bak") if File.exists?(@scripts[:auto_gemsets])
139
+ FileUtils.mv(@scripts[:default_gems], "#{@scripts[:default_gems]}.bak") if File.exists?(@scripts[:default_gems])
140
+ FileUtils.mv(AutoGemsets::GEMSET_ROOT, "#{AutoGemsets::GEMSET_ROOT}.bak") if File.exists? AutoGemsets::GEMSET_ROOT
135
141
  end
136
142
 
137
143
  after do
138
- FileUtils.rm_rf(@script_file) if File.exists?(@script_file)
139
- FileUtils.mv("#{@script_file}.bak", @script_file) if File.exists?("#{@script_file}.bak")
144
+ FileUtils.rm_rf(@scripts[:auto_gemsets]) if File.exists?(@scripts[:auto_gemsets])
145
+ FileUtils.mv("#{@scripts[:auto_gemsets]}.bak", @scripts[:auto_gemsets]) if File.exists?("#{@scripts[:auto_gemsets]}.bak")
146
+
147
+ FileUtils.rm_rf(@scripts[:default_gems]) if File.exists?(@scripts[:default_gems])
148
+ FileUtils.mv("#{@scripts[:default_gems]}.bak", @scripts[:default_gems]) if File.exists?("#{@scripts[:default_gems]}.bak")
149
+
150
+ FileUtils.rm_rf(@scripts[:config]) if File.exists?(@scripts[:config])
151
+ FileUtils.mv("#{@scripts[:config]}.bak", @scripts[:config]) if File.exists?("#{@scripts[:config]}.bak")
152
+ FileUtils.rm_rf(AutoGemsets::GEMSET_ROOT) if File.exists? AutoGemsets::GEMSET_ROOT
153
+ FileUtils.mv("#{AutoGemsets::GEMSET_ROOT}.bak", AutoGemsets::GEMSET_ROOT) if File.exists? "#{AutoGemsets::GEMSET_ROOT}.bak"
140
154
  end
141
155
 
142
- it "copies the auto_gemsets script in the share directory" do
156
+ it "copies the auto-gemsets script in the share directory" do
143
157
  @app.init
144
- script_file = File.join(AutoGemsets::ROOT, 'lib', 'auto-gemsets', 'auto_gemsets.sh')
145
- expect(File.read(@script_file)).to eq(File.read(script_file))
158
+ script_file = File.join(AutoGemsets::ROOT, 'lib', 'auto-gemsets', 'auto-gemsets.sh')
159
+ expect(File.read(@scripts[:auto_gemsets])).to eq(File.read(script_file))
146
160
  end
147
161
 
148
162
  it "warns if the script is already loaded and does nothing when y is not pressed" do
149
- FileUtils.touch @script_file
163
+ FileUtils.touch @scripts[:auto_gemsets]
150
164
  @output.should_receive(:puts).once.with("auto-gemsets is already installed!")
151
165
  @output.should_receive(:puts).once.with("Do you wish overwrite this installation? y/n")
152
166
  @output.should_receive(:puts).once.with("Existing installation preserved.")
@@ -155,12 +169,34 @@ describe AutoGemsets::Application do
155
169
  end
156
170
 
157
171
  it "warns if the script is already loaded and overwrites it when y is pressed" do
158
- FileUtils.touch @script_file
172
+ FileUtils.touch @scripts[:auto_gemsets]
159
173
  @output.should_receive(:puts).once.with("auto-gemsets is already installed!")
160
174
  @output.should_receive(:puts).once.with("Do you wish overwrite this installation? y/n")
161
175
  @input.stub!(:gets).and_return("y")
162
176
  @app.init
163
- expect(File.read(@script_file)).to eq(File.read(File.join(AutoGemsets::INSTALL_ROOT, 'auto_gemsets.sh')))
177
+ expect(File.read(@scripts[:auto_gemsets])).to eq(File.read(File.join(AutoGemsets::INSTALL_ROOT, 'auto-gemsets.sh')))
178
+ end
179
+
180
+ it "copies the default-gems script in the share directory" do
181
+ @app.init
182
+ default_gems_file = File.join(AutoGemsets::ROOT, 'lib', 'auto-gemsets', 'default-gems.sh')
183
+ expect(File.read(@scripts[:default_gems])).to eq(File.read(default_gems_file))
184
+ end
185
+
186
+ it "creates a ~/.auto-gemsets file if one does not exist" do
187
+ @app.init
188
+ config_file = File.join(AutoGemsets::ROOT, 'lib', 'auto-gemsets', '.auto-gemsets')
189
+ expect(File.read(@scripts[:config])).to eq(File.read(config_file))
190
+ end
191
+
192
+ it "creates the GEMSET_ROOT directory" do
193
+ @app.init
194
+ expect(File.exists?(AutoGemsets::GEMSET_ROOT)).to be_true
195
+ end
196
+
197
+ it "creates the default gemset folder" do
198
+ @app.init
199
+ expect(File.exists?(File.join(AutoGemsets::GEMSET_ROOT, 'default'))).to be_true
164
200
  end
165
201
 
166
202
  end
@@ -15,7 +15,7 @@ describe AutoGemsets do
15
15
  end
16
16
 
17
17
  it "has an INSTALL_ROOT" do
18
- expect(AutoGemsets::INSTALL_ROOT).to eq('/usr/local/share/auto_gemsets')
18
+ expect(AutoGemsets::INSTALL_ROOT).to eq('/usr/local/share/auto-gemsets')
19
19
  end
20
20
 
21
21
  it "has a VERSION" do
@@ -0,0 +1,20 @@
1
+ #!/bin/sh
2
+
3
+ . ./test/helper.sh
4
+
5
+ setUp() {
6
+ clear_env
7
+ export PATH="test:/usr/bin:/bin"
8
+ }
9
+
10
+ tearDown() {
11
+ reset_env
12
+ }
13
+
14
+ test_it_does_not_duplicate_entries() {
15
+ ag_add_path 'test'
16
+ assertEquals " it doesn't duplicate entries" \
17
+ "test:/usr/bin:/bin" "$PATH"
18
+ }
19
+
20
+ SHUNIT_PARENT=$0 . $SHUNIT2
@@ -0,0 +1,81 @@
1
+ #!/bin/sh
2
+
3
+ . ./test/helper.sh
4
+
5
+ setUp() {
6
+ clear_env
7
+ if [ ! -f "${HOME}/.auto-gemsets" ]; then
8
+ touch "${HOME}/.auto-gemsets"; echo "export AUTO_GEMSETS_REPORTING=on" > "${HOME}/.auto-gemsets"
9
+ fi
10
+ }
11
+
12
+ tearDown() {
13
+ reset_env
14
+ }
15
+
16
+ test_it_adds_a_gemset_root_environment_variable() {
17
+ ag_init > /dev/null
18
+ assertEquals " it adds a GEMSET_ROOT environment variable" \
19
+ "$HOME/.gemsets" "$GEMSET_ROOT"
20
+ }
21
+
22
+ test_sets_default_gemset_if_not_defined() {
23
+ ag_init > /dev/null
24
+ assertEquals " it sets the DEFAULT_GEMSET" \
25
+ "default" "$DEFAULT_GEMSET"
26
+ }
27
+
28
+ test_ignores_default_gemset_if_defined() {
29
+ export DEFAULT_GEMSET='test'
30
+ ag_init > /dev/null
31
+ assertEquals " it sets the DEFAULT_GEMSET" \
32
+ "test" "$DEFAULT_GEMSET"
33
+ }
34
+
35
+ test_it_adds_auto_gemsets_to_the_prompt_command() {
36
+ ag_init > /dev/null
37
+ assertEquals " it adds auto_gemsets to the PROMPT_COMMAND" \
38
+ "$PROMPT_COMMAND" "auto_gemsets"
39
+ }
40
+
41
+ test_it_appends_to_the_prompt_command_if_it_already_has_functions() {
42
+ export PROMPT_COMMAND=":"
43
+ ag_init > /dev/null
44
+ assertEquals " it appends to the PROMPT_COMMAND if it already has functions" \
45
+ ":; auto_gemsets" "$PROMPT_COMMAND"
46
+ }
47
+
48
+ test_it_doesnt_duplicate_the_prompt_command() {
49
+ export PROMPT_COMMAND="auto_gemsets"
50
+ ag_init > /dev/null
51
+ assertEquals " it doesn't duplicate the PROMPT_COMMAND" \
52
+ "auto_gemsets" "$PROMPT_COMMAND"
53
+ }
54
+
55
+ test_it_sources_the_auto_gemsets_file() {
56
+ ag_init > /dev/null
57
+ assertEquals " it sources the ~/.auto-gemsets file" \
58
+ "on" "$AUTO_GEMSETS_REPORTING"
59
+ }
60
+
61
+ test_it_calls_auto_gemsets() {
62
+ cd "$HOME"
63
+ ag_init > /dev/null
64
+
65
+ assertEquals " it sets the default when no Gemfile is present" \
66
+ "default" "$GEMSET"
67
+
68
+ assertEquals " it sets the GEM_HOME when no Gemfile is present" \
69
+ "${GEMSET_ROOT}/default" "$GEM_HOME"
70
+
71
+ assertEquals " it sets the GEM_HOME when no Gemfile is present" \
72
+ "${GEMSET_ROOT}/default" "$GEM_ROOT"
73
+
74
+ assertEquals " it sets the GEM_PATH when no Gemfile is present" \
75
+ "${GEMSET_ROOT}/default" "$GEM_PATH"
76
+
77
+ assertNotNull " it adds the gemset's bin directory to the path" \
78
+ "$(echo $PATH | grep "${GEMSET_ROOT}/default/bin")"
79
+ }
80
+
81
+ SHUNIT_PARENT=$0 . $SHUNIT2
@@ -0,0 +1,18 @@
1
+ #!/bin/sh
2
+
3
+ . ./test/helper.sh
4
+
5
+ setUp() {
6
+ clear_env
7
+ }
8
+
9
+ tearDown() {
10
+ reset_env
11
+ }
12
+
13
+ test_it_finds_the_parent_directory_name() {
14
+ assertEquals "it finds the parent directory name" \
15
+ "auto-gemsets" "$(ag_parent_dir ${PWD}/Gemfile)"
16
+ }
17
+
18
+ SHUNIT_PARENT=$0 . $SHUNIT2
@@ -0,0 +1,19 @@
1
+ #!/bin/sh
2
+
3
+ . ./test/helper.sh
4
+
5
+ setUp() {
6
+ clear_env
7
+ }
8
+
9
+ tearDown() {
10
+ reset_env
11
+ }
12
+
13
+ test_it_removes_a_directory_from_the_path() {
14
+ ag_remove_path '/ag/test/path'
15
+ assertNull " it removes a path from the path" \
16
+ "$(echo $PATH | grep "/ag/test/path")"
17
+ }
18
+
19
+ SHUNIT_PARENT=$0 . $SHUNIT2
@@ -0,0 +1,67 @@
1
+ #!/bin/sh
2
+
3
+ . ./test/helper.sh
4
+
5
+ setUp() {
6
+ clear_env
7
+ export AUTO_GEMSETS_REPORTING='off'
8
+ }
9
+
10
+ tearDown() {
11
+ reset_env
12
+ }
13
+
14
+ test_it_sets_gem_home_to_the_gemset_path() {
15
+ ag_set_gemset 'default'
16
+ assertEquals " it sets the GEM_HOME to the default gemset path" \
17
+ "${GEMSET_ROOT}/default" "$GEM_HOME"
18
+ }
19
+
20
+ test_it_sets_gem_path_to_the_default_gemset_path() {
21
+ ag_set_gemset 'default'
22
+ assertEquals " it sets the GEM_PATH to the default gemset path" \
23
+ "${GEMSET_ROOT}/default" "$GEM_PATH"
24
+ }
25
+
26
+ test_it_adds_the_gemset_bin_directory_to_the_path() {
27
+ ag_set_gemset 'default'
28
+ assertNotNull " it adds the gemset's bin directory to the path" \
29
+ "$(echo $PATH | grep "${GEM_HOME}/bin")"
30
+ }
31
+
32
+ test_it_adds_the_default_bin_directory_to_path_when_not_default() {
33
+ ag_set_gemset 'some_gemset'
34
+ assertNotNull " it adds the default gemset's bin directory to the path" \
35
+ "$(echo $PATH | grep "${GEMSET_ROOT}/default/bin")"
36
+ }
37
+
38
+ test_it_adds_the_default_gemset_to_the_gem_path() {
39
+ ag_set_gemset 'some_gemset'
40
+
41
+ assertEquals " it adds the default gemset to the GEM_PATH" \
42
+ "${GEMSET_ROOT}/some_gemset:${GEMSET_ROOT}/default" "$GEM_PATH"
43
+ }
44
+
45
+ test_it_sets_the_gemset_environment_variable() {
46
+ ag_set_gemset 'default'
47
+ assertEquals " it sets the GEMSET environment variable" \
48
+ "default" "$GEMSET"
49
+ }
50
+
51
+ test_it_sets_the_gem_root_variable() {
52
+ ag_set_gemset 'default'
53
+ assertEquals " it sets the GEM_ROOT environment variable" \
54
+ "${GEMSET_ROOT}/default" "$GEM_ROOT"
55
+ }
56
+
57
+ test_it_reports_the_new_gemset_change() {
58
+ export AUTO_GEMSETS_REPORTING='on'
59
+ assertEquals " it reports the new gemset change *default when default" \
60
+ "Now using default gemset via *default" "$(ag_set_gemset 'default')"
61
+
62
+ export GEMFILE="test"
63
+ assertEquals " it reports the new gemset change with the GEMFILE when NOT default" \
64
+ "Now using some_gemset gemset via test" "$(ag_set_gemset 'some_gemset')"
65
+ }
66
+
67
+ SHUNIT_PARENT=$0 . $SHUNIT2
@@ -0,0 +1,83 @@
1
+ #!/bin/sh
2
+
3
+ . ./test/helper.sh
4
+
5
+ PROJECT_DIR="$PWD/test/project"
6
+
7
+ setUp() {
8
+ clear_env
9
+ if [ ! -d "${GEMSET_ROOT}/project" ]; then
10
+ rm -Rf "${GEMSET_ROOT}/project"
11
+ fi
12
+ }
13
+
14
+ tearDown() {
15
+ reset_env
16
+ if [ ! -d "${GEMSET_ROOT}/project" ]; then
17
+ rm -Rf "${GEMSET_ROOT}/project"
18
+ fi
19
+ }
20
+
21
+ test_it_sets_the_gemfile_environment_variable() {
22
+ cd "$PROJECT_DIR"
23
+ auto_gemsets
24
+
25
+ assertEquals " it sets the gemfile environment variable" \
26
+ "${PROJECT_DIR}/Gemfile" "$GEMFILE"
27
+ }
28
+
29
+ test_it_sets_the_default_gemset_when_no_gemfile_is_present() {
30
+ cd "$HOME"
31
+ auto_gemsets
32
+
33
+ assertEquals " it sets the default when no Gemfile is present" \
34
+ "default" "$GEMSET"
35
+
36
+ assertEquals " it sets the GEM_HOME when no Gemfile is present" \
37
+ "${GEMSET_ROOT}/default" "$GEM_HOME"
38
+
39
+ assertEquals " it sets the GEM_HOME when no Gemfile is present" \
40
+ "${GEMSET_ROOT}/default" "$GEM_ROOT"
41
+
42
+ assertEquals " it sets the GEM_PATH when no Gemfile is present" \
43
+ "${GEMSET_ROOT}/default" "$GEM_PATH"
44
+
45
+ assertNotNull " it adds the gemset's bin directory to the path" \
46
+ "$(echo $PATH | grep "${GEMSET_ROOT}/default/bin")"
47
+ }
48
+
49
+ test_it_sets_the_gemset_when_a_gemfile_is_present() {
50
+ cd "$PROJECT_DIR"
51
+ auto_gemsets
52
+
53
+ assertEquals " it sets the gemset when a Gemfile is present" \
54
+ "project" "$GEMSET"
55
+
56
+ assertEquals " it sets the GEM_HOME when no Gemfile is present" \
57
+ "${GEMSET_ROOT}/project" "$GEM_HOME"
58
+
59
+ assertEquals " it sets the GEM_HOME when no Gemfile is present" \
60
+ "${GEMSET_ROOT}/project" "$GEM_ROOT"
61
+
62
+ assertEquals " it sets the GEM_PATH when no Gemfile is present" \
63
+ "${GEMSET_ROOT}/project:${GEMSET_ROOT}/default" "$GEM_PATH"
64
+
65
+ assertNotNull " it adds the gemset's bin directory to the path" \
66
+ "$(echo $PATH | grep "${GEMSET_ROOT}/default/bin")"
67
+ }
68
+
69
+ test_it_doesnt_do_anything_if_the_gemset_is_active() {
70
+ export GEMSET="project"
71
+
72
+ assertNull " it doesnt do anything if the gemset is active" \
73
+ "$(auto_gemsets)"
74
+ }
75
+
76
+ test_it_creates_a_gemset_directory_if_it_does_not_exist() {
77
+ auto_gemsets
78
+
79
+ assertTrue " it creates a gemset directory if it does not exist" \
80
+ "[ -d ${GEMSET_ROOT}/project ]"
81
+ }
82
+
83
+ SHUNIT_PARENT=$0 . $SHUNIT2
@@ -0,0 +1,59 @@
1
+ #!/bin/sh
2
+
3
+ OLD_GEM_HOME=$GEM_HOME
4
+ OLD_GEM_PATH=$GEM_PATH
5
+ OLD_GEM_ROOT=$GEM_ROOT
6
+ OLD_GEMSET=$GEMSET
7
+ OLD_DEFAULT_GEMSET=$DEFAULT_GEMSET
8
+ OLD_GEMFILE=$GEMFILE
9
+ OLD_PATH=$PATH
10
+ OLD_PROMPT_COMMAND=$PROMPT_COMMAND
11
+ OLD_AUTO_GEMSETS_REPORTING=$AUTO_GEMSETS_REPORTING
12
+
13
+ clear_env() {
14
+ unset GEM_HOME
15
+ unset GEM_PATH
16
+ unset GEM_ROOT
17
+ unset GEMSET
18
+ unset DEFAULT_GEMSET
19
+ unset GEMFILE
20
+ unset PROMPT_COMMAND
21
+ unset AUTO_GEMSETS_REPORTING
22
+ mv "/usr/local/share/auto-gemsets" "/usr/local/share/auto-gemsets.bak"
23
+
24
+ if [ -f "${HOME}/.auto-gemsets" ]; then
25
+ mv "${HOME}/.auto-gemsets" "${HOME}/.auto-gemsets.bak"
26
+ fi
27
+ }
28
+
29
+ reset_env() {
30
+ rm -Rf "/usr/local/share/auto-gemsets"
31
+ mv "/usr/local/share/auto-gemsets.bak" "/usr/local/share/auto-gemsets"
32
+ if [ -f "${HOME}/.auto-gemsets.bak" ]; then
33
+ mv "${HOME}/.auto-gemsets.bak" "${HOME}/.auto-gemsets"
34
+ fi
35
+ export GEM_HOME=$OLD_GEM_HOME
36
+ export GEM_PATH=$OLD_GEM_PATH
37
+ export GEM_ROOT=$OLD_GEM_ROOT
38
+ export GEMSET=$OLD_GEMSET
39
+ export DEFAULT_GEMSET=$OLD_DEFAULT_GEMSET
40
+ export GEMFILE=$OLD_GEMFILE
41
+ export PATH=$OLD_PATH
42
+ export PROMPT_COMMAND=$OLD_PROMPT_COMMAND
43
+ export AUTO_GEMSETS_REPORTING=$OLD_AUTO_GEMSETS_REPORTING
44
+ }
45
+
46
+ [[ -z "$SHUNIT2" ]] && SHUNIT2=/usr/share/shunit2/shunit2
47
+
48
+ . ./lib/auto-gemsets/auto-gemsets.sh
49
+
50
+ setUp() { return; }
51
+ tearDown() { return; }
52
+ oneTimeTearDown() {
53
+ if [ "$__shunit_assertsFailed" -gt "0" ]; then
54
+ echo
55
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
56
+ echo "!!------------------------------------------------ FAILURE ------------------------------------------------!!"
57
+ echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
58
+ fi
59
+ }
File without changes
@@ -0,0 +1,13 @@
1
+ #!/bin/sh
2
+
3
+ log() {
4
+ echo
5
+ echo "$1"
6
+ echo
7
+ }
8
+
9
+ for test in $(dirname $0)/*_test.sh; do
10
+ log ">>> Running $test"
11
+ $SHELL $test
12
+ echo '------------------------------------------------------------'
13
+ done
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.3.0
4
+ version: 0.4.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: 2013-01-05 00:00:00.000000000 Z
12
+ date: 2013-01-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -129,11 +129,22 @@ files:
129
129
  - auto-gemsets.gemspec
130
130
  - bin/gemset
131
131
  - lib/auto-gemsets.rb
132
+ - lib/auto-gemsets/.auto-gemsets
132
133
  - lib/auto-gemsets/application.rb
133
- - lib/auto-gemsets/auto_gemsets.sh
134
+ - lib/auto-gemsets/auto-gemsets.sh
135
+ - lib/auto-gemsets/default-gems.sh
134
136
  - spec/application_spec.rb
135
137
  - spec/auto-gemsets_spec.rb
136
138
  - spec/spec_helper.rb
139
+ - test/ag_add_path_test.sh
140
+ - test/ag_init_test.sh
141
+ - test/ag_parent_dir_test.sh
142
+ - test/ag_remove_path_test.sh
143
+ - test/ag_set_gemset_test.sh
144
+ - test/auto_gemsets_test.sh
145
+ - test/helper.sh
146
+ - test/project/Gemfile
147
+ - test/runner
137
148
  - travis.yml
138
149
  homepage: http://github.com/daytonn/auto-gemsets
139
150
  licenses:
@@ -150,7 +161,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
150
161
  version: '0'
151
162
  segments:
152
163
  - 0
153
- hash: -962648630984490021
164
+ hash: 3197001320140692747
154
165
  required_rubygems_version: !ruby/object:Gem::Requirement
155
166
  none: false
156
167
  requirements:
@@ -1,174 +0,0 @@
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
-
12
- ag_set_default_gemset() {
13
- if [ -n "${DEFAULT_GEMSET}" ]; then
14
- if [ ! "$GEM_PATH" == "${DEFAULT_GEMSET}" ]; then
15
- DEFAULT=$( basename $DEFAULT_GEMSET )
16
- fi
17
-
18
- if [ -n "$GEMSET" ] && [ ! "$GEMSET" == "$DEFAULT" ]; then
19
- ag_remove_path "${GEMSET_ROOT}/${GEMSET}/bin"
20
- fi
21
-
22
- DEFAULT_BIN_PATH="${DEFAULT_GEMSET}/bin"
23
-
24
- export GEMSET="${DEFAULT}"
25
- export GEM_HOME="$DEFAULT_GEMSET"
26
- export GEMFILE="$DEFAULT_GEMSET"
27
- export GEM_ROOT="$GEM_HOME"
28
- export GEM_PATH="$GEM_HOME"
29
-
30
- ag_add_path "$DEFAULT_BIN_PATH"
31
- ag_using_gemset_via "*default"
32
- fi
33
- }
34
-
35
- ag_using_gemset_via() {
36
- if [ "$SILENT" == "off" ]; then
37
- echo "Now using $GEMSET gemset via $1"
38
- fi
39
- }
40
-
41
- ag_remove_path() {
42
- NEW_PATH=""
43
- IFS=':' read -a PATHS <<< "$PATH"
44
- for p in "${PATHS[@]}"
45
- do
46
- if [ ! "$p" == "$1" ]; then
47
- if [ -z "$NEW_PATH" ]; then
48
- NEW_PATH="$p"
49
- else
50
- NEW_PATH="$NEW_PATH:$p"
51
- fi
52
- fi
53
- done
54
- export PATH="$NEW_PATH"
55
- }
56
-
57
- ag_add_path () {
58
- if ! echo $PATH | egrep -q "(^|:)$1($|:)" ; then
59
- if [ "$2" = "after" ] ; then
60
- PATH=$PATH:$1
61
- else
62
- PATH=$1:$PATH
63
- fi
64
-
65
- export PATH
66
- fi
67
- }
68
-
69
- auto_gemsets() {
70
- local dir="$PWD"
71
-
72
- until [[ -z "$dir" ]]; do
73
- GEMFILE="$dir/Gemfile"
74
- ag_get_parent_dirname
75
-
76
- if [ "$GEMSET" == "$PARENT_DIR" ]; then
77
- break
78
- fi
79
-
80
- if [ -f "$GEMFILE" ]; then
81
- ag_set_gemset "$PARENT_DIR"
82
- break
83
- fi
84
-
85
- if [ -z "${dir%/*}" ] && [ ! "$GEMSET" == $( basename $DEFAULT_GEMSET ) ]; then
86
- ag_set_default_gemset
87
- break
88
- fi
89
-
90
- dir="${dir%/*}"
91
- done
92
- }
93
-
94
- ag_get_parent_dirname() {
95
- if [ ! -z "$GEMFILE" ]; then
96
- IFS='/' read -a gemfile_path_parts <<< "$GEMFILE"
97
- PARENT_DIR="${gemfile_path_parts[${#gemfile_path_parts[@]}-2]}"
98
- fi
99
- }
100
-
101
- ag_set_gemset() {
102
- NEW_GEMSET="$1"
103
- NEW_GEMSET_PATH="${GEMSET_ROOT}/${1}"
104
- NEW_GEMSET_BIN_PATH="${NEW_GEMSET_PATH}/bin"
105
- ag_remove_path "$GEMSET_BIN_PATH"
106
- ag_create_gemset_if_missing "$NEW_GEMSET"
107
- export GEMSET="$NEW_GEMSET"
108
- export GEM_HOME="$NEW_GEMSET_PATH"
109
- export GEM_ROOT="$NEW_GEMSET_PATH"
110
- export GEM_PATH="$NEW_GEMSET_PATH:$DEFAULT_GEMSET"
111
-
112
- ag_add_path "$DEFAULT_BIN_PATH"
113
- ag_add_path "$NEW_GEMSET_BIN_PATH"
114
-
115
- ag_using_gemset_via "$GEMFILE"
116
- }
117
-
118
- ag_create_gemset_if_missing() {
119
- if [ ! -d "${GEMSET_ROOT}/${1}" ]; then
120
- mkdir -p "${GEMSET_ROOT}/${1}" && echo "${1} created. run gem install bundler"
121
- fi
122
- }
123
-
124
- default-gems() {
125
- if [ -n "$1" ]; then
126
- ag_silent "on"
127
- G="$GEMSET"
128
- ag_set_default_gemset
129
- gem "$@"
130
- ag_set_gemset "$G"
131
- ag_silent "off"
132
- else
133
- cat <<EOF
134
- The defalt-gems command is an auto-gems utility to manage gems
135
- in the default* gemset from within other gemsets.
136
-
137
- Usage:
138
- ------
139
-
140
- default-gems (command) [options]
141
-
142
- Examples:
143
- ---------
144
-
145
- default-gems install mygem
146
- default-gems uninstall mygem
147
- default-gems list
148
-
149
- `default-gems` accepts any valid `gem` command, with any valid arguments and options.
150
- It is simply a pass-through to the `gem` command with the context of the default gemset.
151
- EOF
152
-
153
- fi
154
- }
155
-
156
- # Create a GEMSET_ROOT if none is set
157
- if [ ! -n "$GEMSET_ROOT" ]; then
158
- export GEMSET_ROOT="${HOME}/.gemsets"
159
- fi
160
-
161
- # If ZSH add precommand
162
- if [[ -n "$ZSH_VERSION" ]]; then
163
- precmd_functions+=("auto_gemsets")
164
- else
165
- # If there's already a prompt command,
166
- if [ -n "$PROMPT_COMMAND" ]; then
167
- # check if it's already in the PROMPT
168
- if [ -z "$(echo $PROMPT_COMMAND | grep auto_gemsets)" ] ; then
169
- PROMPT_COMMAND="$PROMPT_COMMAND; auto_gemsets"
170
- fi
171
- else
172
- PROMPT_COMMAND="auto_gemsets"
173
- fi
174
- fi