auto-gemsets 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/HELP.md CHANGED
@@ -20,6 +20,10 @@ Examples:
20
20
  Commands:
21
21
  ========
22
22
 
23
+ init
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.
26
+
23
27
  ls, list
24
28
  --------
25
29
  gemset ls
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "auto-gemsets"
8
- s.version = "0.2.0"
8
+ s.version = "0.2.1"
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-23"
12
+ s.date = "2013-01-01"
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"]
@@ -33,7 +33,8 @@ Gem::Specification.new do |s|
33
33
  "lib/auto-gemsets/auto_gemsets.sh",
34
34
  "spec/application_spec.rb",
35
35
  "spec/auto-gemsets_spec.rb",
36
- "spec/spec_helper.rb"
36
+ "spec/spec_helper.rb",
37
+ "travis.yml"
37
38
  ]
38
39
  s.homepage = "http://github.com/daytonn/auto-gemsets"
39
40
  s.licenses = ["Apache 2.0"]
@@ -21,8 +21,7 @@ module AutoGemsets
21
21
  @output = output
22
22
  @input = input
23
23
  @args = args
24
- @command = @args.shift.to_sym unless @args.empty? || @args.first =~ /^-/
25
-
24
+ @command = @args.empty? ? :current : @args.shift.to_sym unless @args.first =~ /^-/
26
25
  parse_options
27
26
  end
28
27
 
@@ -33,33 +32,11 @@ module AutoGemsets
33
32
  end
34
33
 
35
34
  def run
36
- if @command
37
- self.send @command, *@args
38
- else
39
- if options[:help]
40
- help
41
- elsif options[:version]
42
- version
43
- else
44
- self.send(:current)
45
- end
46
- end
35
+ self.send @command, *@args
47
36
  end
48
37
 
49
38
  def ls
50
- gemsets = Dir.glob(File.join(ENV['HOME'], '.gemsets', '*')).map do |d|
51
- gemset = File.basename(d)
52
- case gemset
53
- when default_gemset
54
- gemset = " #{gemset}*"
55
- when ENV['GEMSET']
56
- gemset = "-> #{gemset}"
57
- else
58
- gemset = " #{gemset}"
59
- end
60
- gemset
61
- end
62
-
39
+ gemsets = Dir.glob(File.join(ENV['HOME'], '.gemsets', '*')).map { |d| display_gemset d }
63
40
  @output.puts gemsets.join "\n"
64
41
  end
65
42
 
@@ -78,23 +55,20 @@ module AutoGemsets
78
55
  end
79
56
 
80
57
  def mv(gemset, new_gemset)
81
- if !File.exists?(gemset_path(new_gemset))
82
- if FileUtils.mv(gemset_path(gemset), gemset_path(new_gemset))
83
- @output.puts "#{gemset} renamed to #{new_gemset}"
84
- end
58
+ if !File.exists?(gemset_path(new_gemset)) && FileUtils.mv(gemset_path(gemset), gemset_path(new_gemset))
59
+ @output.puts "#{gemset} renamed to #{new_gemset}"
85
60
  else
86
61
  @output.puts "#{new_gemset} already exists!"
87
- @output.puts "Do you really wish to replace #{new_gemset} with #{gemset}? y/n"
88
-
89
- confirmation = @input.gets
90
- if confirmation =~ /^y/i
91
- FileUtils.rm_rf(gemset_path(new_gemset))
92
- if FileUtils.mv(gemset_path(gemset), gemset_path(new_gemset))
93
- @output.puts "#{gemset} renamed to #{new_gemset}"
94
- end
95
- else
96
- @output.puts "No gemsets were harmed."
97
- end
62
+ confirm("Do you really wish to replace #{new_gemset} with #{gemset}?", {
63
+ accept: -> {
64
+ if FileUtils.rm_rf(gemset_path(new_gemset)) && FileUtils.mv(gemset_path(gemset), gemset_path(new_gemset))
65
+ @output.puts "#{gemset} renamed to #{new_gemset}"
66
+ end
67
+ },
68
+ deny: -> {
69
+ @output.puts "No gemsets were harmed."
70
+ }
71
+ })
98
72
  end
99
73
  end
100
74
 
@@ -103,34 +77,37 @@ module AutoGemsets
103
77
  end
104
78
 
105
79
  def rm(gemset)
106
- @output.puts "Are you sure you wish to delete the #{gemset} gemset? y/n"
107
- confirmation = @input.gets
108
- if confirmation =~ /^y/i
109
- if File.exists?(gemset_path(gemset)) && FileUtils.rm_rf(gemset_path(gemset))
110
- @output.puts "#{gemset} gemset removed!"
111
- end
112
- else
113
- @output.puts "No gemsets were harmed."
114
- end
80
+ confirm("Are you sure you wish to delete the #{gemset} gemset?", {
81
+ accept: -> {
82
+ if File.exists?(gemset_path(gemset)) && FileUtils.rm_rf(gemset_path(gemset))
83
+ @output.puts "#{gemset} gemset removed!"
84
+ end
85
+ },
86
+ deny: -> {
87
+ @output.puts "No gemsets were harmed."
88
+ }
89
+ })
115
90
  end
116
91
 
117
92
  def remove(gemset)
118
93
  rm(gemset)
119
94
  end
120
95
 
121
- def open(gemset=nil)
122
- if AutoGemsets::on_OSX?
123
- if gemset
124
- if File.exists?(gemset_path(gemset))
125
- %x{open #{gemset_path(gemset)}}
126
- else
127
- @output.puts "No gemset named #{gemset}!"
128
- end
129
- else
130
- %x{open #{AutoGemsets::GEMSET_ROOT}}
131
- end
96
+ def open(gemset = nil)
97
+ command = case
98
+ when AutoGemsets::on_OSX?
99
+ 'open'
100
+ when AutoGemsets::on_linux?
101
+ 'xdg-open'
102
+ when AutoGemsets::on_windows?
103
+ 'explorer'
104
+ end
105
+
106
+ if gemset
107
+ %x{#{command} #{gemset_path(gemset)}} if File.exists?(gemset_path(gemset))
108
+ @output.puts "No gemset named #{gemset}!" unless File.exists?(gemset_path(gemset))
132
109
  else
133
- @output.puts "currently this command is only available for OS X users"
110
+ %x{#{command} #{AutoGemsets::GEMSET_ROOT}}
134
111
  end
135
112
  end
136
113
 
@@ -140,20 +117,19 @@ module AutoGemsets
140
117
  end
141
118
 
142
119
  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
120
  if File.exists? script_file
146
121
  @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
122
+ confirm("Do you wish overwrite this installation?", {
123
+ accept: -> {
124
+ create_script
125
+ },
126
+ deny: -> {
127
+ @output.puts "Existing installation preserved."
128
+ }
129
+ })
130
+ else
131
+ create_script
154
132
  end
155
- FileUtils.cp(script_file, AutoGemsets::INSTALL_ROOT)
156
- FileUtils.chmod("a+x", "#{AutoGemsets::INSTALL_ROOT}/auto_gemsets.sh")
157
133
  end
158
134
 
159
135
  private
@@ -162,10 +138,12 @@ module AutoGemsets
162
138
  OptionParser.new do |opts|
163
139
  opts.on("-v", "--version", "Version info") do
164
140
  @options[:version] = true
141
+ @command = :version
165
142
  end
166
143
 
167
144
  opts.on('-h', '--help', 'Display help') do
168
145
  @options[:help] = true
146
+ @command = :help
169
147
  end
170
148
  end.parse!
171
149
 
@@ -187,6 +165,38 @@ module AutoGemsets
187
165
  def default_gemset
188
166
  File.basename(ENV['DEFAULT_GEMSET'])
189
167
  end
168
+
169
+ def display_gemset(gemset_dir)
170
+ case gemset = File.basename(gemset_dir)
171
+ when default_gemset
172
+ gemset = " #{gemset}*"
173
+ when ENV['GEMSET']
174
+ gemset = "-> #{gemset}"
175
+ else
176
+ gemset = " #{gemset}"
177
+ end
178
+ gemset
179
+ end
180
+
181
+ def confirm(question, callbacks = {})
182
+ settings = {
183
+ accept: -> { nil },
184
+ deny: -> { nil }
185
+ }.merge! callbacks
186
+
187
+ @output.puts "#{question} y/n"
188
+ @input.gets =~ /^y/i ? settings[:accept].call : settings[:deny].call
189
+ end
190
+
191
+ def script_file
192
+ File.join(AutoGemsets::INSTALL_ROOT, "auto_gemsets.sh")
193
+ end
194
+
195
+ def create_script
196
+ 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)
198
+ FileUtils.chmod("a+x", File.join(AutoGemsets::INSTALL_ROOT, File.basename(script_file)))
199
+ end
190
200
  end
191
201
 
192
202
  end
@@ -71,28 +71,32 @@ auto_gemsets() {
71
71
 
72
72
  until [[ -z "$dir" ]]; do
73
73
  GEMFILE="$dir/Gemfile"
74
+ ag_get_parent_dirname
75
+
76
+ if [ "$GEMSET" == "$PARENT_DIR" ]; then
77
+ break
78
+ fi
74
79
 
75
80
  if [ -f "$GEMFILE" ]; then
76
- ag_get_parent_dirname
77
- if [ "$GEMSET" == "$PARENT_DIR" ]; then
78
- break
79
- else
80
- ag_set_gemset "$PARENT_DIR"
81
- break
82
- fi
83
- else
84
- if [ ! "$GEMSET" == "$DEFAULT" ]; then
85
- ag_set_default_gemset
86
- fi
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
87
88
  fi
88
89
 
89
90
  dir="${dir%/*}"
90
91
  done
92
+
91
93
  }
92
94
 
93
95
  ag_get_parent_dirname() {
94
- IFS='/' read -a gemfile_path_parts <<< "$GEMFILE"
95
- PARENT_DIR="${gemfile_path_parts[${#gemfile_path_parts[@]}-2]}"
96
+ if [ ! -z "$GEMFILE" ]; then
97
+ IFS='/' read -a gemfile_path_parts <<< "$GEMFILE"
98
+ PARENT_DIR="${gemfile_path_parts[${#gemfile_path_parts[@]}-2]}"
99
+ fi
96
100
  }
97
101
 
98
102
  ag_set_gemset() {
@@ -162,15 +166,10 @@ else
162
166
  # If there's already a prompt command,
163
167
  if [ -n "$PROMPT_COMMAND" ]; then
164
168
  # check if it's already in the PROMPT
165
- if [ ! "$PROMPT_COMMAND" == *auto_gemsets* ]; then
169
+ if [ -z "$(echo $PROMPT_COMMAND | grep auto_gemsets)" ] ; then
166
170
  PROMPT_COMMAND="$PROMPT_COMMAND; auto_gemsets"
167
171
  fi
168
172
  else
169
173
  PROMPT_COMMAND="auto_gemsets"
170
174
  fi
171
- fi
172
-
173
- # Set default when sourced
174
- ag_silent "on"
175
- ag_set_default_gemset
176
- ag_silent "off"
175
+ fi
@@ -10,22 +10,19 @@ describe AutoGemsets::Application do
10
10
  @gemset = SecureRandom::hex
11
11
  @random_gemset = File.join(ENV['HOME'], '.gemsets', @gemset)
12
12
  FileUtils.mkdir_p(@random_gemset)
13
+ @env_gemset = ENV['GEMSET']
14
+ @env_default_gemset = ENV['DEFAULT_GEMSET']
15
+ ENV['DEFAULT_GEMSET'] = 'mygemset'
16
+ ENV['GEMSET'] = @gemset
13
17
  end
14
18
 
15
19
  after do
16
20
  FileUtils.rm_rf(@random_gemset) if File.exists? @random_gemset
21
+ ENV['GEMSET'] = @env_gemset
22
+ ENV['DEFAULT_GEMSET'] = @env_default_gemset
17
23
  end
18
24
 
19
25
  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
26
  it "shows the current gemset" do
30
27
  @output.should_receive(:puts).with("-> #{@gemset}")
31
28
  @app.current
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
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.2.0
4
+ version: 0.2.1
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-23 00:00:00.000000000 Z
12
+ date: 2013-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -134,6 +134,7 @@ files:
134
134
  - spec/application_spec.rb
135
135
  - spec/auto-gemsets_spec.rb
136
136
  - spec/spec_helper.rb
137
+ - travis.yml
137
138
  homepage: http://github.com/daytonn/auto-gemsets
138
139
  licenses:
139
140
  - Apache 2.0
@@ -149,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
149
150
  version: '0'
150
151
  segments:
151
152
  - 0
152
- hash: 3895543352290661910
153
+ hash: 4587648895543290072
153
154
  required_rubygems_version: !ruby/object:Gem::Requirement
154
155
  none: false
155
156
  requirements: