Skip to content

Commit

Permalink
Merge pull request #153 from alexjfisher/rubocop
Browse files Browse the repository at this point in the history
Rubocop Autofixes
  • Loading branch information
alexjfisher authored Feb 9, 2020
2 parents 5ce20d6 + 91d13c9 commit 7708708
Show file tree
Hide file tree
Showing 27 changed files with 915 additions and 391 deletions.
546 changes: 546 additions & 0 deletions .rubocop.yml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/facter/rvm_installed.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Facter.add("rvm_installed") do
rvm_binary = "/usr/local/rvm/bin/rvm"
Facter.add(:rvm_installed) do
rvm_binary = '/usr/local/rvm/bin/rvm'

setcode do
File.exists? rvm_binary
File.exist? rvm_binary
end
end
6 changes: 3 additions & 3 deletions lib/facter/rvm_version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Facter.add("rvm_version") do
rvm_binary = "/usr/local/rvm/bin/rvm"
Facter.add(:rvm_version) do
rvm_binary = '/usr/local/rvm/bin/rvm'

setcode do
File.exists?(rvm_binary) ? `#{rvm_binary} version`.strip.match(/rvm ([0-9]+\.[0-9]+\.[0-9]+) .*/)[1] : nil
File.exist?(rvm_binary) ? `#{rvm_binary} version`.strip.match(%r{rvm ([0-9]+\.[0-9]+\.[0-9]+) .*})[1] : nil
end
end
6 changes: 3 additions & 3 deletions lib/puppet/provider/rvm_alias/alias.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# RVM gemset support
Puppet::Type.type(:rvm_alias).provide(:alias) do
desc "RVM alias support."
desc 'RVM alias support.'

has_command(:rvmcmd, '/usr/local/rvm/bin/rvm') do
environment :HOME => ENV['HOME']
environment HOME: ENV['HOME']
end

def target_ruby
Expand All @@ -15,7 +15,7 @@ def alias_name
end

def aliascmd
[command(:rvmcmd), "alias"]
[command(:rvmcmd), 'alias']
end

def alias_list
Expand Down
73 changes: 33 additions & 40 deletions lib/puppet/provider/rvm_gem/gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,49 +3,45 @@

# Ruby gems support.
Puppet::Type.type(:rvm_gem).provide(:gem) do
desc "Ruby Gem support using RVM."
desc 'Ruby Gem support using RVM.'

has_feature :versionable
has_command(:rvmcmd, '/usr/local/rvm/bin/rvm') do
environment :HOME => ENV['HOME']
environment HOME: ENV['HOME']
end


def ruby_version
resource[:ruby_version]
end

def gembinary
[command(:rvmcmd), ruby_version, "do", "gem"]
[command(:rvmcmd), ruby_version, 'do', 'gem']
end


def gemlist(hash)
command = gembinary + ['list']

if hash[:local]
command << "--local"
else
command << "--remote"
end
command << if hash[:local]
'--local'
else
'--remote'
end

if name = hash[:justme]
command << '^' + name + '$'
end

# use proxy if proxy_url is set
if resource[:proxy_url] and !resource[:proxy_url].empty?
command << "--http-proxy" << resource[:proxy_url]
if resource[:proxy_url] && !resource[:proxy_url].empty?
command << '--http-proxy' << resource[:proxy_url]
end

list = []
begin
list = execute(command).split("\n").collect do |set|
list = execute(command).split("\n").map do |set|
if gemhash = self.class.gemsplit(set)
gemhash[:provider] = :gem
gemhash
else
nil
end
end.compact
rescue Puppet::ExecutionFailure => detail
Expand All @@ -60,85 +56,82 @@ def gemlist(hash)

def self.gemsplit(desc)
case desc
when /^\*\*\*/, /^\s*$/, /^\s+/; return nil
when /gem: not found/; return nil
when %r{^\*\*\*}, %r{^\s*$}, %r{^\s+} then return nil
when %r{gem: not found} then nil
# when /^(\S+)\s+\((((((\d+[.]?))+)(,\s)*)+)\)/
when /^(\S+)\s+\((\d+.*)\)/
name = $1
version = $2.split(/,\s*/)
return {
:name => name,
:ensure => version
when %r{^(\S+)\s+\((\d+.*)\)}
name = Regexp.last_match(1)
version = Regexp.last_match(2).split(%r{,\s*})
{
name: name,
ensure: version
}
else
Puppet.warning "Could not match #{desc}"
nil
end
end


def install(useversion = true)
command = gembinary + ['install']
command << "-v" << resource[:ensure] if (! resource[:ensure].is_a? Symbol) and useversion
command << '-v' << resource[:ensure] if (!resource[:ensure].is_a? Symbol) && useversion
# Dependencies are now installed by default
# command << "--include-dependencies"

# use proxy if proxy_url is set
if resource[:proxy_url] and !resource[:proxy_url].empty?
command << "--http-proxy" << resource[:proxy_url]
if resource[:proxy_url] && !resource[:proxy_url].empty?
command << '--http-proxy' << resource[:proxy_url]
end

if source = resource[:source]
begin
uri = URI.parse(source)
rescue => detail
fail "Invalid source '#{uri}': #{detail}"
raise "Invalid source '#{uri}': #{detail}"
end

case uri.scheme
when nil
# no URI scheme => interpret the source as a local file
command << source
when /file/i
when %r{file}i
command << uri.path
when 'puppet'
# we don't support puppet:// URLs (yet)
raise Puppet::Error.new("puppet:// URLs are not supported as gem sources")
raise Puppet::Error, 'puppet:// URLs are not supported as gem sources'
else
# interpret it as a gem repository
command << "--source" << "#{source}" << resource[:name]
command << '--source' << source.to_s << resource[:name]
end
else
command << "--no-rdoc" << "--no-ri" << resource[:name]
command << '--no-rdoc' << '--no-ri' << resource[:name]
end

# makefile opts,
# must be last
if resource[:withopts]
command << "--" << resource[:withopts]
end
command << '--' << resource[:withopts] if resource[:withopts]

output = execute(command)
# Apparently some stupid gem versions don't exit non-0 on failure
self.fail "Could not install: #{output.chomp}" if output.include?("ERROR")
raise "Could not install: #{output.chomp}" if output.include?('ERROR')
end

def latest
# This always gets the latest version available.
hash = gemlist(:justme => resource[:name])
hash = gemlist(justme: resource[:name])

hash[:ensure][0]
end

def query
gemlist(:justme => resource[:name], :local => true)
gemlist(justme: resource[:name], local: true)
end

def uninstall
execute(gembinary + ["uninstall", "-x", "-a", resource[:name]])
execute(gembinary + ['uninstall', '-x', '-a', resource[:name]])
end

def update
self.install(false)
install(false)
end
end
16 changes: 8 additions & 8 deletions lib/puppet/provider/rvm_gemset/gemset.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# RVM gemset support
Puppet::Type.type(:rvm_gemset).provide(:gemset) do
desc "RVM gemset support."
desc 'RVM gemset support.'

has_command(:rvmcmd, '/usr/local/rvm/bin/rvm') do
environment :HOME => ENV['HOME']
environment HOME: ENV['HOME']
end

def ruby_version
Expand All @@ -15,25 +15,25 @@ def gemset_name
end

def gemsetcommand
[command(:rvmcmd), ruby_version, "exec", "rvm", "gemset"]
[command(:rvmcmd), ruby_version, 'exec', 'rvm', 'gemset']
end

def gemsetcommand_force
[command(:rvmcmd), ruby_version, "exec", "rvm", "--force", "gemset"]
[command(:rvmcmd), ruby_version, 'exec', 'rvm', '--force', 'gemset']
end

def gemset_list
command = gemsetcommand + ['list']

# use proxy if proxy_url is set
if resource[:proxy_url] and !resource[:proxy_url].empty?
command << "--http-proxy" << resource[:proxy_url]
if resource[:proxy_url] && !resource[:proxy_url].empty?
command << '--http-proxy' << resource[:proxy_url]
end

list = []
begin
list = execute(command).split("\n").collect do |line|
line.strip if line =~ /^\s+\S+/
list = execute(command).split("\n").map do |line|
line.strip if line =~ %r{^\s+\S+}
end.compact
rescue Puppet::ExecutionFailure => detail
end
Expand Down
41 changes: 17 additions & 24 deletions lib/puppet/provider/rvm_system_ruby/rvm_system_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Puppet::Type.type(:rvm_system_ruby).provide(:rvm) do
desc "Ruby RVM support."
desc 'Ruby RVM support.'

has_command(:rvmcmd, '/usr/local/rvm/bin/rvm') do
environment :HOME => ENV['HOME']
environment HOME: ENV['HOME']
end

def create
Expand All @@ -15,36 +15,31 @@ def create
end

def destroy
rvmcmd "uninstall", resource[:name]
rvmcmd 'uninstall', resource[:name]
end

def exists?
begin
rvmcmd("list", "strings").split("\n").any? do |line|
line =~ Regexp.new(Regexp.escape(resource[:name]))
end
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not list RVMs: #{detail}"
rvmcmd('list', 'strings').split("\n").any? do |line|
line =~ Regexp.new(Regexp.escape(resource[:name]))
end

rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not list RVMs: #{detail}"
end

def default_use
begin
rvmcmd("list", "default").split("\n").any? do |line|
line =~ Regexp.new(Regexp.escape(resource[:name]))
end
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not list default RVM: #{detail}"
rvmcmd('list', 'default').split("\n").any? do |line|
line =~ Regexp.new(Regexp.escape(resource[:name]))
end
rescue Puppet::ExecutionFailure => detail
raise Puppet::Error, "Could not list default RVM: #{detail}"
end

def default_use=(value)
set_default if value
end

def set_default
rvmcmd "alias", "create", "default", resource[:name]
rvmcmd 'alias', 'create', 'default', resource[:name]
end

private
Expand All @@ -53,22 +48,20 @@ def install
unless resource[:proxy_url].nil?
ENV['http_proxy'] = resource[:proxy_url]
ENV['https_proxy'] = resource[:proxy_url]
unless resource[:no_proxy].nil?
ENV['no_proxy'] = resource[:no_proxy]
end
ENV['no_proxy'] = resource[:no_proxy] unless resource[:no_proxy].nil?
end
options = Array(resource[:build_opts])
if resource[:autolib_mode]
options << "--autolibs #{resource[:autolib_mode]}"
end
if resource[:proxy_url] and !resource[:proxy_url].empty?
rvmcmd "install", resource[:name], "--proxy", resource[:proxy_url], *options
if resource[:proxy_url] && !resource[:proxy_url].empty?
rvmcmd 'install', resource[:name], '--proxy', resource[:proxy_url], *options
else
rvmcmd "install", resource[:name], *options
rvmcmd 'install', resource[:name], *options
end
end

def mount
rvmcmd "mount", resource[:mount_from]
rvmcmd 'mount', resource[:mount_from]
end
end
8 changes: 4 additions & 4 deletions lib/puppet/provider/rvm_wrapper/wrapper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# RVM gemset support
Puppet::Type.type(:rvm_wrapper).provide(:wrapper) do
desc "RVM wrapper support."
desc 'RVM wrapper support.'

has_command(:rvmcmd, '/usr/local/rvm/bin/rvm') do
environment :HOME => ENV['HOME']
environment HOME: ENV['HOME']
end

def target_ruby
Expand All @@ -24,14 +24,14 @@ def wrapper_filename
end

def create
execute([command(:rvmcmd), "wrapper", target_ruby, prefix || "--no-prefix", wrapper_name])
execute([command(:rvmcmd), 'wrapper', target_ruby, prefix || '--no-prefix', wrapper_name])
end

def destroy
File.delete wrapper_filename
end

def exists?
File.exists? wrapper_filename
File.exist? wrapper_filename
end
end
5 changes: 2 additions & 3 deletions lib/puppet/type/rvm_alias.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Puppet::Type.newtype(:rvm_alias) do
@doc = "Manage RVM Aliases."
@doc = 'Manage RVM Aliases.'

ensurable

Expand All @@ -8,13 +8,12 @@
end

newparam(:name) do
desc "The name of the alias to be managed."
desc 'The name of the alias to be managed.'
isnamevar
end

newparam(:target_ruby) do
desc "The ruby version that is the target of our alias.
For example: 'ruby-1.9.2-p290'"
end

end
Loading

0 comments on commit 7708708

Please sign in to comment.