auto-gemsets 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.2
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "auto-gemsets"
8
- s.version = "0.1.0"
8
+ s.version = "0.1.2"
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"]
@@ -26,8 +26,8 @@ Gem::Specification.new do |s|
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "auto-gemsets.gemspec",
29
+ "auto_gemsets.sh",
29
30
  "bin/gemset",
30
- "gemsets.sh",
31
31
  "lib/auto-gemsets.rb",
32
32
  "lib/auto-gemsets/application.rb",
33
33
  "spec/application_spec.rb",
@@ -0,0 +1,53 @@
1
+ function create_or_switch_gemset() {
2
+ if [ ! -d "${GEMSET_ROOT}/${GEMSET}" ]; then
3
+ mkdir -p "${GEMSET_ROOT}/${GEMSET}" && echo "${GEMSET} created. run gem install bundler"
4
+ fi
5
+
6
+ switch_gemset
7
+ }
8
+
9
+ function switch_gemset() {
10
+ export GEM_PATH="${GEMSET_PATH}"
11
+ export GEM_HOME="${GEMSET_PATH}"
12
+ export GEM_ROOT="${GEMSET_PATH}"
13
+ echo "Now using ${GEMSET} gemset via ${GEMFILE}"
14
+ break
15
+ }
16
+
17
+ function auto_gemsets() {
18
+ local dir="$PWD"
19
+ local version_file
20
+
21
+ until [[ -z "$dir" ]]; do
22
+ gemfile="$dir/Gemfile"
23
+ IFS='/' read -a gemfile_path_parts <<< "$gemfile"
24
+
25
+ gemset="${gemfile_path_parts[${#gemfile_path_parts[@]}-2]}"
26
+
27
+ if [[ "${GEMSET_PATH//:$DEFAULT_GEMSET}" == "${GEMSET_ROOT}/$gemset" ]]; then return
28
+ elif [[ -f "$gemfile" ]]; then
29
+ export GEMSET_PATH="${GEMSET_ROOT}/$gemset:${DEFAULT_GEMSET}"
30
+ export GEMSET="${gemset}"
31
+ export GEMFILE="${gemfile}"
32
+ create_or_switch_gemset
33
+ fi
34
+
35
+ dir="${dir%/*}"
36
+ done
37
+ }
38
+
39
+ if [ ! -n "$GEMSET_ROOT" ]; then
40
+ export GEMSET_ROOT="${HOME}/.gemsets"
41
+ fi
42
+
43
+ if [[ -n "$ZSH_VERSION" ]]; then
44
+ precmd_functions+=("auto_gemsets")
45
+ else
46
+ if [[ -n "$PROMPT_COMMAND" ]]; then
47
+ if [[ ! "$PROMPT_COMMAND" == *auto_gemsets* ]]; then
48
+ PROMPT_COMMAND="$PROMPT_COMMAND; auto_gemsets"
49
+ fi
50
+ else
51
+ PROMPT_COMMAND="auto_gemsets"
52
+ fi
53
+ fi
@@ -39,7 +39,20 @@ module AutoGemsets
39
39
  end
40
40
 
41
41
  def ls
42
- @output.puts Dir.glob(File.join(ENV['HOME'], '.gemsets', '*')).map { |d| File.basename(d) }.join "\n"
42
+ gemsets = Dir.glob(File.join(ENV['HOME'], '.gemsets', '*')).map do |d|
43
+ gemset = File.basename(d)
44
+ default_gemset = File.basename(ENV['DEFAULT_GEMSET'])
45
+ if gemset == default_gemset
46
+ gemset = " #{gemset}*"
47
+ elsif gemset == ENV['GEMSET']
48
+ gemset = "-> #{gemset}"
49
+ else
50
+ gemset = " #{gemset}"
51
+ end
52
+ gemset
53
+ end
54
+
55
+ @output.puts gemsets.join "\n"
43
56
  end
44
57
 
45
58
  def list
@@ -113,6 +126,11 @@ module AutoGemsets
113
126
  end
114
127
  end
115
128
 
129
+ def edit
130
+ raise "You must set $EDITOR or $TERM_EDITOR to edit Gemfiles" unless ENV['EDITOR'] || ENV['TERM_EDITOR']
131
+ %x{#{ENV['EDITOR'] || ENV['TERM_EDITOR']} #{ENV['GEMFILE']}}
132
+ end
133
+
116
134
  private
117
135
  def parse_options
118
136
  @options = {}
@@ -43,6 +43,18 @@ describe AutoGemsets::Application do
43
43
  @output.should_receive(:puts) { |list| expect(list).to match(/#{@gemset}/) }
44
44
  @app.list
45
45
  end
46
+
47
+ it "puts a star on the default gemset" do
48
+ ENV['DEFAULT_GEMSET'] = @gemset
49
+ @output.should_receive(:puts) { |list| expect(list).to match(/#{@gemset}\*/) }
50
+ @app.list
51
+ end
52
+
53
+ it "puts an arrow on the current gemset" do
54
+ ENV['GEMSET'] = @gemset
55
+ @output.should_receive(:puts) { |list| expect(list).to match(/-> #{@gemset}/) }
56
+ @app.list
57
+ end
46
58
  end
47
59
 
48
60
  describe 'remove' do
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.0
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -126,8 +126,8 @@ files:
126
126
  - Rakefile
127
127
  - VERSION
128
128
  - auto-gemsets.gemspec
129
+ - auto_gemsets.sh
129
130
  - bin/gemset
130
- - gemsets.sh
131
131
  - lib/auto-gemsets.rb
132
132
  - lib/auto-gemsets/application.rb
133
133
  - spec/application_spec.rb
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  version: '0'
149
149
  segments:
150
150
  - 0
151
- hash: -3432436821644449709
151
+ hash: 2639899487419064898
152
152
  required_rubygems_version: !ruby/object:Gem::Requirement
153
153
  none: false
154
154
  requirements:
data/gemsets.sh DELETED
@@ -1,98 +0,0 @@
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