wwtd 0.1.9 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8fc6e436ea91aa67fd00cc6285d866e4e5350ae
4
- data.tar.gz: 36e0bc7cc2f324b60772f343c889f66a6f1cfef4
3
+ metadata.gz: 31ec85abe62a348965669a72f3e66780513e4464
4
+ data.tar.gz: d385cb6dcc35c69d8a902144e11740487bfc3dcc
5
5
  SHA512:
6
- metadata.gz: 220f889c7096aea1267d3122bff57a6dbd4f5c35e7d30e847c96472ebf1cf284a168ffc2097b9b18e078fbe8c3fc22bc98a92f52f41642eb3096be5741b5a87b
7
- data.tar.gz: 31c06c72b004f3ad9e9efa5eaa7f7314ce45e86c78de4bcdf39c128cb419e3dd5364f57764a7d874b8267c5d2ffc0651119fc8bf074a33e46f0061dcc25a3e44
6
+ metadata.gz: d977fbdb37a688ef729aa6a44046f93dbc66f62dc5932564d37cebaff723d6e250dcc53cb7586307c472df1ff9592d4cfcb93f05998d068cdf0b11a2607570f6
7
+ data.tar.gz: 43c1c10ed25329f78fbd31a4f7cff1c5f5ab15139d77973a0144d312a3a69ffbff3c3e298bf20aff49804e0009f2a6c19ca451d59970dbd97d3b4039299f962f
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -11,9 +11,10 @@ module WWTD
11
11
  DEFAULT_GEMFILE = "Gemfile"
12
12
  COMBINATORS = ["rvm", "gemfile", "env"]
13
13
  UNDERSTOOD = ["rvm", "gemfile", "matrix", "script", "bundler_args"]
14
+ INFO_MAX_CHARACTERS = 30
14
15
 
15
16
  class << self
16
- def run(argv)
17
+ def run(argv=[])
17
18
  options = parse_options(argv)
18
19
 
19
20
  # Read actual .travis.yml
@@ -72,8 +73,12 @@ module WWTD
72
73
  end
73
74
 
74
75
  def config_info(matrix, config)
75
- config = config.select { |k,v| matrix.map { |c| c[k] }.uniq.size > 1 }.sort
76
- "#{config.map { |k,v| "#{k}: #{truncate(v, 30)}" }.join(", ")}"
76
+ config = config.select { |k,v| matrix.map { |c| c[k] }.uniq.size > 1 }.sort # find non-unique values aka interesting
77
+ maximum_value_lengths = Hash[config.map { |k,v| [k, matrix.map { |h| h[k].to_s.size }.max ] }] # find maximum value length for each key so we can align
78
+ config.map do |k, v|
79
+ value = truncate(v, INFO_MAX_CHARACTERS).ljust([INFO_MAX_CHARACTERS, maximum_value_lengths[k]].min)
80
+ "#{k}: #{value}"
81
+ end.join(" ") # truncate values that are too long
77
82
  end
78
83
 
79
84
  def tint(color, string)
@@ -119,17 +124,17 @@ module WWTD
119
124
  end
120
125
 
121
126
  def run_config(config, lock)
122
- if gemfile = config["gemfile"]
123
- ENV["BUNDLE_GEMFILE"] = gemfile
124
- end
125
- wants_bundle = gemfile || File.exist?(DEFAULT_GEMFILE)
127
+ with_clean_env do
128
+ Shellwords.split(config["env"] || "").each do |part|
129
+ name, value = part.split("=", 2)
130
+ ENV[name] = value
131
+ end
126
132
 
127
- Shellwords.split(config["env"] || "").each do |part|
128
- name, value = part.split("=", 2)
129
- ENV[name] = value
130
- end
133
+ if gemfile = config["gemfile"]
134
+ ENV["BUNDLE_GEMFILE"] = gemfile
135
+ end
136
+ wants_bundle = gemfile || File.exist?(DEFAULT_GEMFILE)
131
137
 
132
- with_clean_env do
133
138
  switch_ruby = switch_ruby(config["rvm"])
134
139
 
135
140
  if wants_bundle
@@ -154,29 +159,29 @@ module WWTD
154
159
  if rvm_executable
155
160
  "rvm #{version} do "
156
161
  else
157
- if rbenv_executable
158
- switch_path(version, "rbenv")
159
- elsif chruby?
160
- switch_path(version, "chruby")
162
+ if ruby_root = ENV["RUBY_ROOT"] # chruby or RUBY_ROOT set
163
+ switch_path(File.dirname(ruby_root), version)
164
+ elsif rbenv_executable
165
+ rubies_root = cache_command("which rbenv").sub(%r{/(\.?rbenv)/.*}, "/\\1") + "/versions"
166
+ switch_path(rubies_root, version)
161
167
  else
162
- "false # could not find ruby version changer # "
168
+ "false # could not find rvm, rbenv or RUBY_ROOT # "
163
169
  end
164
170
  end
165
171
  end
166
172
 
167
- def switch_path(version, changer)
168
- prefix = extract_jruby_rbenv_options!(version)
169
- if bin_path = send("#{changer}_bin_path", version)
170
- "#{prefix}PATH=#{bin_path}:$PATH "
173
+ def switch_path(rubies_root, version)
174
+ extract_jruby_rbenv_options!(version)
175
+ if ruby_root = ruby_root(rubies_root, version)
176
+ gem_home = Dir["#{ruby_root}/lib/ruby/gems/*"].first
177
+ ENV["PATH"] = "#{ruby_root}/bin:#{ENV["PATH"]}"
178
+ ENV["GEM_HOME"] = gem_home
179
+ ""
171
180
  else
172
- "false # could not find #{version} in #{changer} # "
181
+ "false # could not find #{version} in #{rubies_root} # "
173
182
  end
174
183
  end
175
184
 
176
- def chruby?
177
- ENV["RUBY_ROOT"] # chruby is a shell function not available from inside ruby
178
- end
179
-
180
185
  def rvm_executable
181
186
  cache_command("which rvm")
182
187
  end
@@ -193,16 +198,8 @@ module WWTD
193
198
  end
194
199
  end
195
200
 
196
- def chruby_bin_path(version)
197
- found_version_path = Dir.glob("#{ENV['RUBY_ROOT']}/../*").detect { |p| File.basename(p).include?(version) }
198
- "#{found_version_path}/bin" if found_version_path
199
- end
200
-
201
- def rbenv_bin_path(version)
202
- known_version = capture("rbenv versions | grep #{version}")
203
- known_version = known_version.split("\n").last[2..-1].split(" ")[0]
204
- rbenv_root = rbenv_executable.sub(%r{/(\.?rbenv)/.*}, "/\\1")
205
- "#{rbenv_root}/versions/#{known_version}/bin"
201
+ def ruby_root(root, version)
202
+ Dir.glob("#{root}/*").detect { |p| File.basename(p).start_with?(version) }
206
203
  end
207
204
 
208
205
  def cache(key)
@@ -217,9 +214,9 @@ module WWTD
217
214
  # set ruby-opts for jruby flavors
218
215
  def extract_jruby_rbenv_options!(version)
219
216
  if version.sub!("-d19", "")
220
- "JRUBY_OPTS=--1.9 "
217
+ ENV["JRUBY_OPTS"] = "--1.9"
221
218
  elsif version.sub!("-d18", "")
222
- "JRUBY_OPTS=--1.8 "
219
+ ENV["JRUBY_OPTS"] = "--1.8"
223
220
  end
224
221
  end
225
222
 
@@ -1,10 +1,5 @@
1
1
  require "wwtd"
2
2
 
3
3
  task :wwtd do
4
- block = lambda{ sh "wwtd" }
5
- if defined?(Bundler)
6
- Bundler.with_clean_env(&block)
7
- else
8
- block.call
9
- end
4
+ exit 1 unless WWTD.run == 0
10
5
  end
@@ -1,3 +1,3 @@
1
1
  module WWTD
2
- VERSION = "0.1.9"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wwtd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser
metadata.gz.sig CHANGED
Binary file