lib/agile_utils/helper.rb in agile_utils-0.1.1 vs lib/agile_utils/helper.rb in agile_utils-0.1.2
- old
+ new
@@ -1,34 +1,34 @@
-require 'open3'
-require 'stringio'
+require "open3"
+require "stringio"
module AgileUtils
module Helper
class << self
# Wrapper function to call the 'popen3' and return the result
#
# @param [Array<String>] commands list of command
# @return [String] result of the command as the string
def shell(commands = [])
begin
- command = commands.join(' ')
+ command = commands.join(" ")
stdin, _stderr, _status = Open3.capture3(command)
- rescue Exception => e
+ rescue => e
raise "Problem processing #{command}, #{e.message}"
end
stdin
end
def is_osx?
- uname && uname.strip.downcase == 'darwin'
+ uname && uname.strip.downcase == "darwin"
end
def is_linux?
- uname && uname.strip.downcase == 'linux'
+ uname && uname.strip.downcase == "linux"
end
def uname
- shell(%w(uname))
+ shell(%w[uname])
end
# Extract "key1: value1\nkey2: value 2" to
# hash of { "key1" => "value1", "key2" => "value 2" }
#
@@ -38,12 +38,12 @@
# as fast as we get the specific list of keys
def string_to_hash(input)
hash = {}
input.split('\n').each do |i|
# TODO: code smell?
- item = i.split(':') if is_linux?
- item = i.split('=') if is_osx?
+ item = i.split(":") if is_linux?
+ item = i.split("=") if is_osx?
next if item.empty? || item.size != 2
hash[item[0].strip] = item[1].strip
end
hash
end
@@ -85,12 +85,12 @@
#
# @param [Hash<Objects, Object>] options the option hash
# @return [Array<String>] the list of options for use with Thor
def make_list(options)
list = []
- to_switches(options).split(' ').each do |a|
- list << a.gsub('"', '')
+ to_switches(options).split(" ").each do |a|
+ list << a.gsub('"', "")
end
list
end
# Cross-platform way of finding an executable in the $PATH.
@@ -101,39 +101,39 @@
# Example:
# which('ruby') #=> /usr/bin/ruby
# which('/usr/bin/ruby') #=> nil
# which('bad-executable') #=> nil
def which(command)
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
+ exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
+ ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = File.join(path, "#{command}#{ext}")
return exe if File.executable? exe
end
end
nil
end
- private
+ private
# https://github.com/erikhuda/thor/blob/master/lib/thor/parser/options.rb
#
# Receives a hash and makes it switches.
def to_switches(options)
options.map do |key, value|
case value
when true
"--#{key}"
when Array
- "--#{key} #{value.map { |v| v.inspect }.join(' ')}" unless value.empty?
+ "--#{key} #{value.map { |v| v.inspect }.join(" ")}" unless value.empty?
when Hash
- "--#{key} #{value.map { |k, v| "#{k}:#{v}" }.join(' ')}" unless value.empty?
+ "--#{key} #{value.map { |k, v| "#{k}:#{v}" }.join(" ")}" unless value.empty?
when nil, false
- ''
+ ""
else
"--#{key} #{value.inspect}"
end
- end.join(' ')
+ end.join(" ")
end
end
end
end