capistrano-rbenv 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -40,6 +40,8 @@ Following options are available to manage your rbenv.
40
40
  * `:rbenv_use_configure` - configure rbenv in your shell config or not. `true` by default. users who are using Chef/Puppet may prefer setting this value `false`.
41
41
  * `:rbenv_configure_files` - list of shell configuration files to be configured for rbenv. by default, guessing from user's `$SHELL` and `$HOME`.
42
42
  * `:rbenv_configure_basenames` - advanced option for `:rbenv_configure_files`. list of filename of your shell configuration files if you don't like the default value of `:rbenv_configure_files`.
43
+ * `:rbenv_install_dependencies` - controls whether installing dependencies or not. `true` by default.
44
+ * `:rbenv_define_default_environment` - define `RBENV_ROOT` and update `PATH` to use rbenv over capistrano. `true` by default.
43
45
 
44
46
  ## Contributing
45
47
 
@@ -53,6 +55,7 @@ Following options are available to manage your rbenv.
53
55
 
54
56
  - YAMASHITA Yuu (https://github.com/yyuu)
55
57
  - Geisha Tokyo Entertainment Inc. (http://www.geishatokyo.com/)
58
+ - Nico Schottelius (http://www.nico.schottelius.org/)
56
59
 
57
60
  ## License
58
61
 
@@ -7,13 +7,17 @@ module Capistrano
7
7
  def self.extended(configuration)
8
8
  configuration.load {
9
9
  namespace(:rbenv) {
10
+ _cset(:rbenv_root, "$HOME/.rbenv")
10
11
  _cset(:rbenv_path) {
11
- capture("echo $HOME/.rbenv").chomp()
12
+ # expand to actual path to use this value since rbenv may be executed by users other than `:user`.
13
+ capture("echo #{rbenv_root.dump}").strip
12
14
  }
15
+ _cset(:rbenv_bin_path) { File.join(rbenv_path, "bin") }
16
+ _cset(:rbenv_shims_path) { File.join(rbenv_path, "shims") }
13
17
  _cset(:rbenv_bin) {
14
- File.join(rbenv_path, 'bin', 'rbenv')
18
+ File.join(rbenv_bin_path, "rbenv")
15
19
  }
16
- _cset(:rbenv_cmd) { # to use custom rbenv_path, we use `env` instead of cap's default_environment.
20
+ _cset(:rbenv_cmd) {
17
21
  "env RBENV_VERSION=#{rbenv_ruby_version.dump} #{rbenv_bin}"
18
22
  }
19
23
  _cset(:rbenv_repository, 'git://github.com/sstephenson/rbenv.git')
@@ -33,9 +37,11 @@ module Capistrano
33
37
  rbenv_use_bundler ? "#{rbenv_cmd} exec bundle" : 'bundle'
34
38
  }
35
39
 
40
+ _cset(:rbenv_install_dependencies, true)
41
+
36
42
  desc("Setup rbenv.")
37
43
  task(:setup, :except => { :no_release => true }) {
38
- dependencies
44
+ dependencies if rbenv_install_dependencies
39
45
  update
40
46
  configure
41
47
  build
@@ -80,9 +86,29 @@ module Capistrano
80
86
  plugins.update
81
87
  }
82
88
 
89
+ def setup_default_environment
90
+ env = fetch(:default_environment, {}).dup
91
+ env["RBENV_ROOT"] = rbenv_path
92
+ env["PATH"] = [ rbenv_shims_path, rbenv_bin_path, env.fetch("PATH", "$PATH") ].join(":")
93
+ set(:default_environment, env)
94
+ end
95
+
96
+ _cset(:rbenv_define_default_environment, true)
97
+ # workaround for `multistage` of capistrano-ext.
98
+ # https://github.com/yyuu/capistrano-rbenv/pull/5
99
+ if top.namespaces.key?(:multistage)
100
+ after "multistage:ensure" do
101
+ setup_default_environment if rbenv_define_default_environment
102
+ end
103
+ else
104
+ on :start do
105
+ setup_default_environment if rbenv_define_default_environment
106
+ end
107
+ end
108
+
83
109
  desc("Purge rbenv.")
84
110
  task(:purge, :except => { :no_release => true }) {
85
- run("rm -rf #{rbenv_path}")
111
+ run("rm -rf #{rbenv_path.dump}")
86
112
  }
87
113
 
88
114
  namespace(:plugins) {
@@ -120,35 +146,49 @@ module Capistrano
120
146
  _cset(:rbenv_configure_script) {
121
147
  (<<-EOS).gsub(/^\s*/, '')
122
148
  # Configured by capistrano-rbenv. Do not edit directly.
123
- export PATH="#{rbenv_path}/bin:$PATH"
149
+ export PATH=#{[ rbenv_bin_path, "$PATH"].join(":").dump}
124
150
  eval "$(rbenv init -)"
125
151
  EOS
126
152
  }
153
+
154
+ def _update_config(script_file, file, tempfile)
155
+ execute = []
156
+ ## (1) ensure copy source file exists
157
+ execute << "( test -f #{file.dump} || touch #{file.dump} )"
158
+ ## (2) copy originao config to temporary file
159
+ execute << "rm -f #{tempfile.dump}" # remove tempfile to preserve permissions of original file
160
+ execute << "cp -fp #{file.dump} #{tempfile.dump}"
161
+ ## (3) modify temporary file
162
+ execute << "sed -i -e '/^#{Regexp.escape(rbenv_configure_signature)}/,/^#{Regexp.escape(rbenv_configure_signature)}/d' #{tempfile.dump}"
163
+ execute << "echo #{rbenv_configure_signature.dump} >> #{tempfile.dump}"
164
+ execute << "cat #{script_file.dump} >> #{tempfile.dump}"
165
+ execute << "echo #{rbenv_configure_signature.dump} >> #{tempfile.dump}"
166
+ ## (4) update config only if it is needed
167
+ execute << "cp -fp #{file.dump} #{(file + ".orig").dump}"
168
+ execute << "( diff -u #{file.dump} #{tempfile.dump} || mv -f #{tempfile.dump} #{file.dump} )"
169
+ run(execute.join(" && "))
170
+ end
171
+
172
+ def update_config(script_file, file)
173
+ begin
174
+ tempfile = capture("mktemp /tmp/rbenv.XXXXXXXXXX").strip
175
+ _update_config(script_file, file, tempfile)
176
+ ensure
177
+ run("rm -f #{tempfile.dump}") rescue nil
178
+ end
179
+ end
180
+
127
181
  _cset(:rbenv_configure_signature, '##rbenv:configure')
128
182
  task(:configure, :except => { :no_release => true }) {
129
183
  if fetch(:rbenv_use_configure, true)
130
- script = File.join('/tmp', "rbenv.#{$$}")
131
- config = [ rbenv_configure_files ].flatten
132
- config_map = Hash[ config.map { |f| [f, File.join('/tmp', "#{File.basename(f)}.#{$$}")] } ]
133
184
  begin
134
- execute = []
135
- put(rbenv_configure_script, script)
136
- config_map.each { |file, temp|
137
- ## (1) copy original config to temporaly file and then modify
138
- execute << "( test -f #{file} || touch #{file} )"
139
- execute << "cp -fp #{file} #{temp}"
140
- execute << "sed -i -e '/^#{Regexp.escape(rbenv_configure_signature)}/,/^#{Regexp.escape(rbenv_configure_signature)}/d' #{temp}"
141
- execute << "echo #{rbenv_configure_signature.dump} >> #{temp}"
142
- execute << "cat #{script} >> #{temp}"
143
- execute << "echo #{rbenv_configure_signature.dump} >> #{temp}"
144
- ## (2) update config only if it is needed
145
- execute << "cp -fp #{file} #{file}.orig"
146
- execute << "( diff -u #{file} #{temp} || mv -f #{temp} #{file} )"
147
- }
148
- run(execute.join(' && '))
185
+ script_file = capture("mktemp /tmp/rbenv.XXXXXXXXXX").strip
186
+ top.put(rbenv_configure_script, script_file)
187
+ [ rbenv_configure_files ].flatten.each do |file|
188
+ update_config(script_file, file)
189
+ end
149
190
  ensure
150
- remove = [ script ] + config_map.values
151
- run("rm -f #{remove.join(' ')}") rescue nil
191
+ run("rm -f #{script_file.dump}") rescue nil
152
192
  end
153
193
  end
154
194
  }
@@ -223,6 +263,11 @@ module Capistrano
223
263
  run("unset -v GEM_HOME; #{gem} query #{q} 2>/dev/null | #{f} || #{gem} install -q #{i}")
224
264
  run("#{rbenv_cmd} rehash && #{bundle_cmd} version")
225
265
  }
266
+
267
+ # call `rbenv rehash` to update shims.
268
+ def rehash()
269
+ run("#{rbenv_cmd} rehash")
270
+ end
226
271
  }
227
272
  }
228
273
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module RbEnv
3
- VERSION = "0.0.10"
3
+ VERSION = "0.0.11"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-rbenv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
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-02-28 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capistrano