summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Roberts <Markus@reality.com>2010-07-09 18:06:06 -0700
committerMarkus Roberts <Markus@reality.com>2010-07-09 18:06:06 -0700
commit81e283b28cdd91d259e3b60687aee7ea66e9d05d (patch)
treee3c7b6e4b41cc219f75a3ae7d1294652ead6f268
parente8cf06336b64491a2dd7538a06651e0caaf6a48d (diff)
downloadpuppet-81e283b28cdd91d259e3b60687aee7ea66e9d05d.tar.gz
puppet-81e283b28cdd91d259e3b60687aee7ea66e9d05d.tar.xz
puppet-81e283b28cdd91d259e3b60687aee7ea66e9d05d.zip
Code smell: Line modifiers are preferred to one-line blocks.
* Replaced 6 occurances of (while .*?) *do$ with The do is unneeded in the block header form and causes problems with the block-to-one-line transformation. 3 Examples: The code: while line = f.gets do becomes: while line = f.gets The code: while line = shadow.gets do becomes: while line = shadow.gets The code: while wrapper = zeros.pop do becomes: while wrapper = zeros.pop * Replaced 19 occurances of ((if|unless) .*?) *then$ with The then is unneeded in the block header form and causes problems with the block-to-one-line transformation. 3 Examples: The code: if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then becomes: if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } The code: unless defined?(@spec_command) then becomes: unless defined?(@spec_command) The code: if c == ?\n then becomes: if c == ?\n * Replaced 758 occurances of ((?:if|unless|while|until) .*) (.*) end with The one-line form is preferable provided: * The condition is not used to assign a variable * The body line is not already modified * The resulting line is not too long 3 Examples: The code: if Puppet.features.libshadow? has_feature :manages_passwords end becomes: has_feature :manages_passwords if Puppet.features.libshadow? The code: unless (defined?(@current_pool) and @current_pool) @current_pool = process_zpool_data(get_pool_data) end becomes: @current_pool = process_zpool_data(get_pool_data) unless (defined?(@current_pool) and @current_pool) The code: if Puppet[:trace] puts detail.backtrace end becomes: puts detail.backtrace if Puppet[:trace]
-rw-r--r--autotest/rspec.rb4
-rw-r--r--autotest/watcher.rb4
-rw-r--r--ext/extlookup.rb4
-rwxr-xr-xext/puppetlisten/puppetlisten.rb2
-rwxr-xr-xinstall.rb4
-rw-r--r--lib/puppet/agent.rb4
-rw-r--r--lib/puppet/agent/locker.rb4
-rw-r--r--lib/puppet/application.rb8
-rw-r--r--lib/puppet/application/agent.rb32
-rw-r--r--lib/puppet/application/apply.rb18
-rw-r--r--lib/puppet/application/cert.rb4
-rw-r--r--lib/puppet/application/describe.rb20
-rw-r--r--lib/puppet/application/doc.rb16
-rw-r--r--lib/puppet/application/filebucket.rb8
-rw-r--r--lib/puppet/application/kick.rb4
-rw-r--r--lib/puppet/application/master.rb20
-rw-r--r--lib/puppet/application/queue.rb4
-rw-r--r--lib/puppet/application/resource.rb8
-rw-r--r--lib/puppet/configurer.rb4
-rwxr-xr-xlib/puppet/daemon.rb8
-rw-r--r--lib/puppet/defaults.rb12
-rw-r--r--lib/puppet/external/event-loop/event-loop.rb16
-rw-r--r--lib/puppet/external/event-loop/signal-system.rb4
-rwxr-xr-xlib/puppet/external/nagios/base.rb8
-rw-r--r--lib/puppet/external/nagios/parser.rb36
-rw-r--r--lib/puppet/external/pson/pure/parser.rb16
-rw-r--r--lib/puppet/feature/rails.rb4
-rw-r--r--lib/puppet/file_bucket/dipper.rb8
-rw-r--r--lib/puppet/file_serving/base.rb4
-rw-r--r--lib/puppet/file_serving/configuration.rb4
-rw-r--r--lib/puppet/file_serving/configuration/parser.rb4
-rw-r--r--lib/puppet/file_serving/fileset.rb4
-rw-r--r--lib/puppet/file_serving/mount/file.rb8
-rw-r--r--lib/puppet/indirector/catalog/compiler.rb4
-rw-r--r--lib/puppet/indirector/exec.rb8
-rw-r--r--lib/puppet/indirector/file_bucket_file/file.rb4
-rw-r--r--lib/puppet/indirector/indirection.rb20
-rw-r--r--lib/puppet/indirector/ldap.rb4
-rw-r--r--lib/puppet/indirector/node/exec.rb4
-rw-r--r--lib/puppet/indirector/node/ldap.rb8
-rw-r--r--lib/puppet/indirector/report/processor.rb4
-rw-r--r--lib/puppet/indirector/request.rb4
-rw-r--r--lib/puppet/indirector/rest.rb4
-rw-r--r--lib/puppet/indirector/terminus.rb8
-rw-r--r--lib/puppet/indirector/yaml.rb4
-rw-r--r--lib/puppet/metatype/manager.rb12
-rw-r--r--lib/puppet/module.rb4
-rw-r--r--lib/puppet/network/authconfig.rb16
-rw-r--r--lib/puppet/network/authorization.rb4
-rwxr-xr-xlib/puppet/network/authstore.rb12
-rw-r--r--lib/puppet/network/client.rb20
-rw-r--r--lib/puppet/network/client/ca.rb4
-rw-r--r--lib/puppet/network/client/report.rb8
-rw-r--r--lib/puppet/network/client/runner.rb4
-rw-r--r--lib/puppet/network/client_request.rb4
-rw-r--r--lib/puppet/network/format.rb4
-rw-r--r--lib/puppet/network/formats.rb4
-rw-r--r--lib/puppet/network/handler.rb4
-rw-r--r--lib/puppet/network/handler/ca.rb8
-rwxr-xr-xlib/puppet/network/handler/filebucket.rb4
-rwxr-xr-xlib/puppet/network/handler/fileserver.rb44
-rw-r--r--lib/puppet/network/handler/master.rb4
-rwxr-xr-xlib/puppet/network/handler/report.rb12
-rw-r--r--lib/puppet/network/http/api/v1.rb4
-rw-r--r--lib/puppet/network/http/mongrel.rb4
-rw-r--r--lib/puppet/network/http/rack/xmlrpc.rb4
-rw-r--r--lib/puppet/network/http/webrick.rb8
-rw-r--r--lib/puppet/network/http/webrick/rest.rb4
-rw-r--r--lib/puppet/network/http_pool.rb4
-rw-r--r--lib/puppet/network/http_server/mongrel.rb8
-rw-r--r--lib/puppet/network/http_server/webrick.rb16
-rw-r--r--lib/puppet/network/rest_authorization.rb4
-rwxr-xr-xlib/puppet/network/rights.rb16
-rw-r--r--lib/puppet/network/server.rb8
-rw-r--r--lib/puppet/network/xmlrpc/client.rb16
-rw-r--r--lib/puppet/network/xmlrpc/processor.rb8
-rw-r--r--lib/puppet/network/xmlrpc/webrick_servlet.rb16
-rw-r--r--lib/puppet/node.rb16
-rw-r--r--lib/puppet/node/environment.rb4
-rw-r--r--lib/puppet/parameter.rb20
-rw-r--r--lib/puppet/parameter/value_collection.rb16
-rw-r--r--lib/puppet/parser/ast/arithmetic_operator.rb4
-rw-r--r--lib/puppet/parser/ast/boolean_operator.rb4
-rw-r--r--lib/puppet/parser/ast/branch.rb4
-rw-r--r--lib/puppet/parser/ast/caseopt.rb12
-rw-r--r--lib/puppet/parser/ast/collexpr.rb4
-rw-r--r--lib/puppet/parser/ast/comparison_operator.rb4
-rw-r--r--lib/puppet/parser/ast/function.rb8
-rw-r--r--lib/puppet/parser/ast/in_operator.rb4
-rw-r--r--lib/puppet/parser/ast/leaf.rb4
-rw-r--r--lib/puppet/parser/ast/match_operator.rb4
-rw-r--r--lib/puppet/parser/ast/resource.rb4
-rw-r--r--lib/puppet/parser/ast/selector.rb4
-rw-r--r--lib/puppet/parser/collector.rb16
-rw-r--r--lib/puppet/parser/compiler.rb12
-rw-r--r--lib/puppet/parser/functions.rb12
-rw-r--r--lib/puppet/parser/functions/generate.rb4
-rw-r--r--lib/puppet/parser/functions/include.rb4
-rw-r--r--lib/puppet/parser/functions/shellquote.rb4
-rw-r--r--lib/puppet/parser/functions/split.rb4
-rw-r--r--lib/puppet/parser/functions/sprintf.rb4
-rw-r--r--lib/puppet/parser/grammar.ra32
-rw-r--r--lib/puppet/parser/parser_support.rb16
-rw-r--r--lib/puppet/parser/resource.rb28
-rw-r--r--lib/puppet/parser/scope.rb30
-rw-r--r--lib/puppet/parser/type_loader.rb4
-rw-r--r--lib/puppet/parser/yaml_trimmer.rb4
-rw-r--r--lib/puppet/property.rb24
-rw-r--r--lib/puppet/property/keyvalue.rb16
-rw-r--r--lib/puppet/property/list.rb20
-rw-r--r--lib/puppet/provider.rb12
-rw-r--r--lib/puppet/provider/augeas/augeas.rb20
-rw-r--r--lib/puppet/provider/confine/variable.rb4
-rw-r--r--lib/puppet/provider/confiner.rb4
-rwxr-xr-xlib/puppet/provider/cron/crontab.rb8
-rw-r--r--lib/puppet/provider/group/groupadd.rb4
-rw-r--r--lib/puppet/provider/group/ldap.rb4
-rw-r--r--lib/puppet/provider/host/parsed.rb8
-rw-r--r--lib/puppet/provider/ldap.rb4
-rw-r--r--lib/puppet/provider/macauthorization/macauthorization.rb16
-rwxr-xr-xlib/puppet/provider/maillist/mailman.rb14
-rw-r--r--lib/puppet/provider/mcx/mcxcontent.rb8
-rw-r--r--lib/puppet/provider/mount.rb8
-rw-r--r--lib/puppet/provider/nameservice.rb36
-rw-r--r--lib/puppet/provider/nameservice/directoryservice.rb28
-rw-r--r--lib/puppet/provider/package.rb4
-rw-r--r--lib/puppet/provider/package/aix.rb16
-rwxr-xr-xlib/puppet/provider/package/apt.rb12
-rwxr-xr-xlib/puppet/provider/package/aptitude.rb4
-rw-r--r--lib/puppet/provider/package/aptrpm.rb4
-rwxr-xr-xlib/puppet/provider/package/blastwave.rb12
-rwxr-xr-xlib/puppet/provider/package/darwinport.rb4
-rwxr-xr-xlib/puppet/provider/package/dpkg.rb8
-rwxr-xr-xlib/puppet/provider/package/fink.rb4
-rwxr-xr-xlib/puppet/provider/package/freebsd.rb4
-rwxr-xr-xlib/puppet/provider/package/gem.rb8
-rw-r--r--lib/puppet/provider/package/nim.rb4
-rwxr-xr-xlib/puppet/provider/package/openbsd.rb4
-rw-r--r--lib/puppet/provider/package/pkg.rb4
-rw-r--r--lib/puppet/provider/package/pkgdmg.rb4
-rw-r--r--lib/puppet/provider/package/portage.rb8
-rwxr-xr-xlib/puppet/provider/package/ports.rb4
-rwxr-xr-xlib/puppet/provider/package/rpm.rb4
-rwxr-xr-xlib/puppet/provider/package/sun.rb32
-rwxr-xr-xlib/puppet/provider/package/yum.rb16
-rwxr-xr-xlib/puppet/provider/parsedfile.rb36
-rw-r--r--lib/puppet/provider/selboolean/getsetsebool.rb2
-rw-r--r--lib/puppet/provider/selmodule/semodule.rb12
-rwxr-xr-xlib/puppet/provider/service/base.rb8
-rw-r--r--lib/puppet/provider/service/bsd.rb12
-rw-r--r--lib/puppet/provider/service/freebsd.rb6
-rwxr-xr-xlib/puppet/provider/service/init.rb4
-rw-r--r--lib/puppet/provider/service/launchd.rb40
-rw-r--r--lib/puppet/provider/user/ldap.rb8
-rw-r--r--lib/puppet/provider/user/pw.rb8
-rw-r--r--lib/puppet/provider/user/user_role_add.rb26
-rw-r--r--lib/puppet/provider/user/useradd.rb4
-rw-r--r--lib/puppet/provider/zone/solaris.rb16
-rw-r--r--lib/puppet/provider/zpool/solaris.rb4
-rw-r--r--lib/puppet/rails.rb36
-rw-r--r--lib/puppet/rails/benchmark.rb12
-rw-r--r--lib/puppet/rails/database/001_add_created_at_to_all_tables.rb8
-rw-r--r--lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb8
-rw-r--r--lib/puppet/rails/database/003_add_environment_to_host.rb8
-rw-r--r--lib/puppet/rails/database/schema.rb4
-rw-r--r--lib/puppet/rails/resource.rb12
-rw-r--r--lib/puppet/reference/providers.rb4
-rw-r--r--lib/puppet/reference/type.rb4
-rw-r--r--lib/puppet/relationship.rb4
-rwxr-xr-xlib/puppet/reports.rb4
-rw-r--r--lib/puppet/reports/rrdgraph.rb8
-rw-r--r--lib/puppet/reports/store.rb8
-rw-r--r--lib/puppet/reports/tagmail.rb12
-rw-r--r--lib/puppet/resource.rb8
-rw-r--r--lib/puppet/resource/catalog.rb24
-rw-r--r--lib/puppet/resource/type.rb8
-rw-r--r--lib/puppet/run.rb4
-rw-r--r--lib/puppet/simple_graph.rb10
-rw-r--r--lib/puppet/ssl/certificate_authority.rb24
-rw-r--r--lib/puppet/ssl/certificate_authority/interface.rb8
-rw-r--r--lib/puppet/ssl/host.rb2
-rwxr-xr-xlib/puppet/sslcertificates.rb4
-rw-r--r--lib/puppet/sslcertificates/ca.rb40
-rw-r--r--lib/puppet/sslcertificates/certificate.rb64
-rw-r--r--lib/puppet/sslcertificates/inventory.rb4
-rw-r--r--lib/puppet/sslcertificates/support.rb8
-rw-r--r--lib/puppet/transaction.rb16
-rw-r--r--lib/puppet/transaction/event_manager.rb4
-rw-r--r--lib/puppet/transaction/report.rb4
-rw-r--r--lib/puppet/transaction/resource_harness.rb4
-rw-r--r--lib/puppet/transportable.rb16
-rw-r--r--lib/puppet/type.rb112
-rw-r--r--lib/puppet/type/augeas.rb4
-rw-r--r--lib/puppet/type/component.rb4
-rwxr-xr-xlib/puppet/type/cron.rb24
-rwxr-xr-xlib/puppet/type/exec.rb36
-rw-r--r--lib/puppet/type/file.rb40
-rwxr-xr-xlib/puppet/type/file/mode.rb16
-rw-r--r--lib/puppet/type/file/selcontext.rb8
-rwxr-xr-xlib/puppet/type/file/source.rb8
-rw-r--r--lib/puppet/type/file/target.rb12
-rwxr-xr-xlib/puppet/type/mount.rb16
-rw-r--r--lib/puppet/type/resources.rb20
-rwxr-xr-xlib/puppet/type/schedule.rb24
-rw-r--r--lib/puppet/type/ssh_authorized_key.rb8
-rwxr-xr-xlib/puppet/type/tidy.rb4
-rwxr-xr-xlib/puppet/type/user.rb24
-rw-r--r--lib/puppet/type/yumrepo.rb20
-rw-r--r--lib/puppet/type/zone.rb12
-rwxr-xr-xlib/puppet/type/zpool.rb12
-rw-r--r--lib/puppet/util.rb28
-rw-r--r--lib/puppet/util/autoload.rb8
-rw-r--r--lib/puppet/util/autoload/file_cache.rb4
-rw-r--r--lib/puppet/util/cacher.rb12
-rw-r--r--lib/puppet/util/classgen.rb20
-rw-r--r--lib/puppet/util/command_line.rb4
-rw-r--r--lib/puppet/util/docs.rb4
-rw-r--r--lib/puppet/util/errors.rb4
-rw-r--r--lib/puppet/util/feature.rb12
-rw-r--r--lib/puppet/util/file_locking.rb4
-rw-r--r--lib/puppet/util/fileparsing.rb44
-rwxr-xr-xlib/puppet/util/filetype.rb20
-rw-r--r--lib/puppet/util/graph.rb4
-rw-r--r--lib/puppet/util/inifile.rb24
-rw-r--r--lib/puppet/util/inline_docs.rb4
-rwxr-xr-xlib/puppet/util/loadedfile.rb4
-rw-r--r--lib/puppet/util/log.rb48
-rw-r--r--lib/puppet/util/log/destinations.rb20
-rw-r--r--lib/puppet/util/log_paths.rb4
-rw-r--r--lib/puppet/util/logging.rb4
-rw-r--r--lib/puppet/util/methodhelper.rb4
-rw-r--r--lib/puppet/util/metric.rb4
-rw-r--r--lib/puppet/util/package.rb2
-rw-r--r--lib/puppet/util/rdoc/generators/puppet_generator.rb40
-rw-r--r--lib/puppet/util/rdoc/parser.rb4
-rw-r--r--lib/puppet/util/reference.rb12
-rw-r--r--lib/puppet/util/selinux.rb34
-rw-r--r--lib/puppet/util/settings.rb50
-rw-r--r--lib/puppet/util/settings/setting.rb16
-rw-r--r--lib/puppet/util/storage.rb8
-rw-r--r--lib/puppet/util/subclass_loader.rb12
-rw-r--r--lib/puppet/util/tagging.rb4
-rwxr-xr-xspec/unit/provider/mount/parsed_spec.rb4
-rwxr-xr-xspec/unit/resource/catalog_spec.rb4
-rwxr-xr-xspec/unit/type/group_spec.rb4
-rwxr-xr-xspec/unit/type/user_spec.rb4
-rwxr-xr-xtest/language/snippets.rb4
-rwxr-xr-xtest/language/transportable.rb4
-rwxr-xr-xtest/lib/puppettest.rb24
-rw-r--r--test/lib/puppettest/certificates.rb4
-rw-r--r--test/lib/puppettest/exetest.rb8
-rw-r--r--test/lib/puppettest/fakes.rb8
-rw-r--r--test/lib/puppettest/filetesting.rb20
-rw-r--r--test/lib/puppettest/parsertesting.rb24
-rw-r--r--test/lib/puppettest/railstesting.rb8
-rw-r--r--test/lib/puppettest/runnable_test.rb4
-rw-r--r--test/lib/puppettest/support/assertions.rb8
-rw-r--r--test/lib/puppettest/support/helpers.rb8
-rwxr-xr-xtest/lib/puppettest/support/resources.rb4
-rw-r--r--test/lib/puppettest/support/utils.rb16
-rw-r--r--test/lib/puppettest/testcase.rb4
-rw-r--r--test/lib/rake/puppet_test_loader.rb4
-rwxr-xr-xtest/network/handler/fileserver.rb4
-rwxr-xr-xtest/other/puppet.rb4
-rwxr-xr-xtest/other/transactions.rb8
-rwxr-xr-xtest/puppet/defaults.rb4
-rwxr-xr-xtest/ral/providers/cron/crontab.rb20
-rwxr-xr-xtest/ral/providers/group.rb4
-rwxr-xr-xtest/ral/providers/package.rb8
-rwxr-xr-xtest/ral/providers/provider.rb4
-rwxr-xr-xtest/ral/providers/user.rb8
-rwxr-xr-xtest/ral/providers/user/useradd.rb12
-rwxr-xr-xtest/ral/type/cron.rb4
-rwxr-xr-xtest/ral/type/exec.rb4
-rwxr-xr-xtest/ral/type/filesources.rb4
-rwxr-xr-xtest/ral/type/resources.rb8
-rwxr-xr-xtest/ral/type/sshkey.rb4
-rwxr-xr-xtest/ral/type/zone.rb4
-rwxr-xr-xtest/util/fileparsing.rb4
279 files changed, 782 insertions, 2298 deletions
diff --git a/autotest/rspec.rb b/autotest/rspec.rb
index 89978d866..42f4c004b 100644
--- a/autotest/rspec.rb
+++ b/autotest/rspec.rb
@@ -29,7 +29,7 @@ class Autotest::Rspec < Autotest
def consolidate_failures(failed)
filters = Hash.new { |h,k| h[k] = [] }
failed.each do |spec, failed_trace|
- if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
+ if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) }
filters[f] << spec
break
end
@@ -50,7 +50,7 @@ class Autotest::Rspec < Autotest
# ~/.autotest to provide a different spec command then the default
# paths provided.
def spec_command(separator=File::ALT_SEPARATOR)
- unless defined?(@spec_command) then
+ unless defined?(@spec_command)
@spec_command = spec_commands.find { |cmd| File.exists? cmd }
raise RspecCommandError, "No spec command could be found!" unless @spec_command
diff --git a/autotest/watcher.rb b/autotest/watcher.rb
index 0beaca7c6..99a7d1bb7 100644
--- a/autotest/watcher.rb
+++ b/autotest/watcher.rb
@@ -13,7 +13,7 @@ def run_comp(cmd)
c = f.getc
putc c
line << c
- if c == ?\n then
+ if c == ?\n
results << if RUBY_VERSION >= "1.9" then
line.join
else
@@ -125,7 +125,7 @@ end
# Ctrl-C
Signal.trap 'INT' do
- if @interrupted then
+ if @interrupted
@wants_to_quit = true
abort("\n")
else
diff --git a/ext/extlookup.rb b/ext/extlookup.rb
index b9ebc43c8..24b161e0f 100644
--- a/ext/extlookup.rb
+++ b/ext/extlookup.rb
@@ -116,9 +116,7 @@ module Puppet::Parser::Functions
# if we got a custom data file, put it first in the array of search files
if datafile != ""
- if File.exists?(extlookup_datadir + "/#{datafile}.csv")
- datafiles << extlookup_datadir + "/#{datafile}.csv"
- end
+ datafiles << extlookup_datadir + "/#{datafile}.csv" if File.exists?(extlookup_datadir + "/#{datafile}.csv")
end
extlookup_precedence.each do |d|
diff --git a/ext/puppetlisten/puppetlisten.rb b/ext/puppetlisten/puppetlisten.rb
index b86f4d822..d1d6e8e44 100755
--- a/ext/puppetlisten/puppetlisten.rb
+++ b/ext/puppetlisten/puppetlisten.rb
@@ -59,7 +59,7 @@ loop do
puts "accepted"
ns.puts "Executing #{cmd} on #{Facter.fqdn}.\n*******OUTPUT********\n\n"
IO.popen(cmd) do |f|
- while line = f.gets do
+ while line = f.gets
ns.puts line
end
end
diff --git a/install.rb b/install.rb
index 466b856f1..c0ac95703 100755
--- a/install.rb
+++ b/install.rb
@@ -418,9 +418,7 @@ def install_binfile(from, op_file, target)
ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
op.puts "#!#{ruby}"
contents = ip.readlines
- if contents[0] =~ /^#!/
- contents.shift
- end
+ contents.shift if contents[0] =~ /^#!/
op.write contents.join()
end
end
diff --git a/lib/puppet/agent.rb b/lib/puppet/agent.rb
index 3c8a2af67..b860677fd 100644
--- a/lib/puppet/agent.rb
+++ b/lib/puppet/agent.rb
@@ -81,9 +81,7 @@ class Puppet::Agent
end
def sync
- unless defined?(@sync) and @sync
- @sync = Sync.new
- end
+ @sync = Sync.new unless defined?(@sync) and @sync
@sync
end
diff --git a/lib/puppet/agent/locker.rb b/lib/puppet/agent/locker.rb
index eaf19177a..c49121e1b 100644
--- a/lib/puppet/agent/locker.rb
+++ b/lib/puppet/agent/locker.rb
@@ -29,9 +29,7 @@ module Puppet::Agent::Locker
end
def lockfile
- unless defined?(@lockfile)
- @lockfile = Puppet::Util::Pidlock.new(lockfile_path)
- end
+ @lockfile = Puppet::Util::Pidlock.new(lockfile_path) unless defined?(@lockfile)
@lockfile
end
diff --git a/lib/puppet/application.rb b/lib/puppet/application.rb
index db297e073..24f78e8dd 100644
--- a/lib/puppet/application.rb
+++ b/lib/puppet/application.rb
@@ -182,9 +182,7 @@ class Application
end
def should_parse_config?
- if ! defined?(@parse_config)
- @parse_config = true
- end
+ @parse_config = true if ! defined?(@parse_config)
return @parse_config
end
@@ -324,9 +322,7 @@ class Application
end
end
- unless options[:setdest]
- Puppet::Util::Log.newdestination(:syslog)
- end
+ Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
end
def parse_options
diff --git a/lib/puppet/application/agent.rb b/lib/puppet/application/agent.rb
index fce978d88..43ee683f6 100644
--- a/lib/puppet/application/agent.rb
+++ b/lib/puppet/application/agent.rb
@@ -76,9 +76,7 @@ class Puppet::Application::Agent < Puppet::Application
Puppet::Util::Log.newdestination(arg)
options[:setdest] = true
rescue => detail
- if Puppet[:debug]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:debug]
$stderr.puts detail.to_s
end
end
@@ -122,9 +120,7 @@ class Puppet::Application::Agent < Puppet::Application
begin
report = @agent.run
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err detail.to_s
end
@@ -167,9 +163,7 @@ class Puppet::Application::Agent < Puppet::Application
end
end
- unless options[:setdest]
- Puppet::Util::Log.newdestination(:syslog)
- end
+ Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
end
def enable_disable_client(agent)
@@ -207,14 +201,10 @@ class Puppet::Application::Agent < Puppet::Application
setup_logs
- if Puppet.settings.print_configs?
- exit(Puppet.settings.print_configs ? 0 : 1)
- end
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
# If noop is set, then also enable diffs
- if Puppet[:noop]
- Puppet[:show_diff] = true
- end
+ Puppet[:show_diff] = true if Puppet[:noop]
args[:Server] = Puppet[:server]
if options[:fqdn]
@@ -225,9 +215,7 @@ class Puppet::Application::Agent < Puppet::Application
if options[:centrallogs]
logdest = args[:Server]
- if args.include?(:Port)
- logdest += ":" + args[:Port]
- end
+ logdest += ":" + args[:Port] if args.include?(:Port)
Puppet::Util::Log.newdestination(logdest)
end
@@ -262,14 +250,10 @@ class Puppet::Application::Agent < Puppet::Application
# It'd be nice to daemonize later, but we have to daemonize before the
# waitforcert happens.
- if Puppet[:daemonize]
- @daemon.daemonize
- end
+ @daemon.daemonize if Puppet[:daemonize]
@host = Puppet::SSL::Host.new
- unless options[:fingerprint]
- cert = @host.wait_for_cert(options[:waitforcert])
- end
+ cert = @host.wait_for_cert(options[:waitforcert]) unless options[:fingerprint]
@objects = []
diff --git a/lib/puppet/application/apply.rb b/lib/puppet/application/apply.rb
index 07ce36736..cd4c75d75 100644
--- a/lib/puppet/application/apply.rb
+++ b/lib/puppet/application/apply.rb
@@ -45,9 +45,7 @@ class Puppet::Application::Apply < Puppet::Application
begin
catalog = Puppet::Resource::Catalog.convert_from(Puppet::Resource::Catalog.default_format,text)
- unless catalog.is_a?(Puppet::Resource::Catalog)
- catalog = Puppet::Resource::Catalog.pson_create(catalog)
- end
+ catalog = Puppet::Resource::Catalog.pson_create(catalog) unless catalog.is_a?(Puppet::Resource::Catalog)
rescue => detail
raise Puppet::Error, "Could not deserialize catalog from pson: #{detail}"
end
@@ -130,7 +128,7 @@ class Puppet::Application::Apply < Puppet::Application
configurer.execute_postrun_command
status = 0
- if not Puppet[:noop] and options[:detailed_exitcodes] then
+ if not Puppet[:noop] and options[:detailed_exitcodes]
transaction.generate_report
exit(transaction.report.exit_status)
else
@@ -144,18 +142,12 @@ class Puppet::Application::Apply < Puppet::Application
end
def setup
- if Puppet.settings.print_configs?
- exit(Puppet.settings.print_configs ? 0 : 1)
- end
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
# If noop is set, then also enable diffs
- if Puppet[:noop]
- Puppet[:show_diff] = true
- end
+ Puppet[:show_diff] = true if Puppet[:noop]
- unless options[:logset]
- Puppet::Util::Log.newdestination(:console)
- end
+ Puppet::Util::Log.newdestination(:console) unless options[:logset]
client = nil
server = nil
diff --git a/lib/puppet/application/cert.rb b/lib/puppet/application/cert.rb
index a85f6a02b..af9042993 100644
--- a/lib/puppet/application/cert.rb
+++ b/lib/puppet/application/cert.rb
@@ -64,9 +64,7 @@ class Puppet::Application::Cert < Puppet::Application
end
def setup
- if Puppet.settings.print_configs?
- exit(Puppet.settings.print_configs ? 0 : 1)
- end
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
Puppet::Util::Log.newdestination :console
diff --git a/lib/puppet/application/describe.rb b/lib/puppet/application/describe.rb
index e696f1613..f2621d354 100644
--- a/lib/puppet/application/describe.rb
+++ b/lib/puppet/application/describe.rb
@@ -36,9 +36,7 @@ class Formatter
def scrub(text)
# For text with no carriage returns, there's nothing to do.
- if text !~ /\n/
- return text
- end
+ return text if text !~ /\n/
indent = nil
# If we can match an indentation, then just remove that same level of
@@ -125,9 +123,7 @@ class TypeDoc
docs = {}
type.allattrs.each do |name|
kind = type.attrtype(name)
- if attrs.include?(kind) && name != :provider
- docs[name] = type.attrclass(name).doc
- end
+ docs[name] = type.attrclass(name).doc if attrs.include?(kind) && name != :provider
end
docs.sort { |a,b|
@@ -148,9 +144,7 @@ class TypeDoc
params = []
type.allattrs.each do |name|
kind = type.attrtype(name)
- if attrs.include?(kind) && name != :provider
- params << name.to_s
- end
+ params << name.to_s if attrs.include?(kind) && name != :provider
end
puts @format.wrap(params.sort.join(", "), :indent => 4)
end
@@ -202,12 +196,8 @@ class Puppet::Application::Describe < Puppet::Application
def setup
options[:types] = command_line.args.dup
- unless options[:list] || options[:types].size > 0
- handle_help(nil)
- end
- if options[:list] && options[:types].size > 0
- $stderr.puts "Warning: ignoring types when listing all types"
- end
+ handle_help(nil) unless options[:list] || options[:types].size > 0
+ $stderr.puts "Warning: ignoring types when listing all types" if options[:list] && options[:types].size > 0
end
end
diff --git a/lib/puppet/application/doc.rb b/lib/puppet/application/doc.rb
index 8dd116233..e4c247444 100644
--- a/lib/puppet/application/doc.rb
+++ b/lib/puppet/application/doc.rb
@@ -86,9 +86,7 @@ class Puppet::Application::Doc < Puppet::Application
Puppet::Util::RDoc.rdoc(options[:outputdir], files, options[:charset])
end
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
$stderr.puts "Could not generate documentation: #{detail}"
exit_code = 1
end
@@ -99,9 +97,7 @@ class Puppet::Application::Doc < Puppet::Application
require 'puppet/util/reference'
options[:references].each do |name|
section = Puppet::Util::Reference.reference(name) or raise "Could not find section #{name}"
- unless options[:mode] == :pdf
- section.trac
- end
+ section.trac unless options[:mode] == :pdf
end
end
@@ -154,9 +150,7 @@ class Puppet::Application::Doc < Puppet::Application
end
end
- unless with_contents # We've only got one reference
- text += Puppet::Util::Reference.footer
- end
+ text += Puppet::Util::Reference.footer unless with_contents # We've only got one reference
# Replace the trac links, since they're invalid everywhere else
text.gsub!(/`\w+\s+([^`]+)`:trac:/) { |m| $1 }
@@ -193,9 +187,7 @@ class Puppet::Application::Doc < Puppet::Application
end
end
- if options[:references].empty?
- options[:references] << :type
- end
+ options[:references] << :type if options[:references].empty?
end
def setup_rdoc(dummy_argument=:work_arround_for_ruby_GC_bug)
diff --git a/lib/puppet/application/filebucket.rb b/lib/puppet/application/filebucket.rb
index 095a413a7..8da2d014d 100644
--- a/lib/puppet/application/filebucket.rb
+++ b/lib/puppet/application/filebucket.rb
@@ -66,9 +66,7 @@ class Puppet::Application::Filebucket < Puppet::Application
# Now parse the config
Puppet.parse_config
- if Puppet.settings.print_configs?
- exit(Puppet.settings.print_configs ? 0 : 1)
- end
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
require 'puppet/file_bucket/dipper'
begin
@@ -80,9 +78,7 @@ class Puppet::Application::Filebucket < Puppet::Application
end
rescue => detail
$stderr.puts detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
exit(1)
end
end
diff --git a/lib/puppet/application/kick.rb b/lib/puppet/application/kick.rb
index eaafc0935..6c77e74f2 100644
--- a/lib/puppet/application/kick.rb
+++ b/lib/puppet/application/kick.rb
@@ -77,9 +77,7 @@ class Puppet::Application::Kick < Puppet::Application
# Remove our host from the list of children, so the parallelization
# continues working.
@children.delete(pid)
- if $CHILD_STATUS.exitstatus != 0
- failures << host
- end
+ failures << host if $CHILD_STATUS.exitstatus != 0
print "#{host} finished with exit code #{$CHILD_STATUS.exitstatus}\n"
else
$stderr.puts "Could not find host for PID #{pid} with status #{$CHILD_STATUS.exitstatus}"
diff --git a/lib/puppet/application/master.rb b/lib/puppet/application/master.rb
index 7ea3f3a83..7485dcb3f 100644
--- a/lib/puppet/application/master.rb
+++ b/lib/puppet/application/master.rb
@@ -20,9 +20,7 @@ class Puppet::Application::Master < Puppet::Application
Puppet::Util::Log.newdestination(arg)
options[:setdest] = true
rescue => detail
- if Puppet[:debug]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:debug]
$stderr.puts detail.to_s
end
end
@@ -82,18 +80,14 @@ class Puppet::Application::Master < Puppet::Application
xmlrpc_handlers = [:Status, :FileServer, :Master, :Report, :Filebucket]
- if Puppet[:ca]
- xmlrpc_handlers << :CA
- end
+ xmlrpc_handlers << :CA if Puppet[:ca]
# Make sure we've got a localhost ssl cert
Puppet::SSL::Host.localhost
# And now configure our server to *only* hit the CA for data, because that's
# all it will have write access to.
- if Puppet::SSL::CertificateAuthority.ca?
- Puppet::SSL::Host.ca_location = :only
- end
+ Puppet::SSL::Host.ca_location = :only if Puppet::SSL::CertificateAuthority.ca?
if Puppet.features.root?
begin
@@ -138,13 +132,9 @@ class Puppet::Application::Master < Puppet::Application
end
end
- unless options[:setdest]
- Puppet::Util::Log.newdestination(:syslog)
- end
+ Puppet::Util::Log.newdestination(:syslog) unless options[:setdest]
- if Puppet.settings.print_configs?
- exit(Puppet.settings.print_configs ? 0 : 1)
- end
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
Puppet.settings.use :main, :master, :ssl
diff --git a/lib/puppet/application/queue.rb b/lib/puppet/application/queue.rb
index 8e830b39e..6bbff75f9 100644
--- a/lib/puppet/application/queue.rb
+++ b/lib/puppet/application/queue.rb
@@ -75,9 +75,7 @@ class Puppet::Application::Queue < Puppet::Application
setup_logs
- if Puppet.settings.print_configs?
- exit(Puppet.settings.print_configs ? 0 : 1)
- end
+ exit(Puppet.settings.print_configs ? 0 : 1) if Puppet.settings.print_configs?
require 'puppet/resource/catalog'
Puppet::Resource::Catalog.terminus_class = :active_record
diff --git a/lib/puppet/application/resource.rb b/lib/puppet/application/resource.rb
index a6cc99302..9e1efe2ef 100644
--- a/lib/puppet/application/resource.rb
+++ b/lib/puppet/application/resource.rb
@@ -49,9 +49,7 @@ class Puppet::Application::Resource < Puppet::Application
end
end
- if options[:edit] and @host
- raise "You cannot edit a remote host"
- end
+ raise "You cannot edit a remote host" if options[:edit] and @host
properties = typeobj.properties.collect { |s| s.name }
@@ -63,9 +61,7 @@ class Puppet::Application::Resource < Puppet::Application
trans.delete(param)
end
- unless properties.include?(param) or @extra_params.include?(param)
- trans.delete(param)
- end
+ trans.delete(param) unless properties.include?(param) or @extra_params.include?(param)
end
trans.to_manifest
}
diff --git a/lib/puppet/configurer.rb b/lib/puppet/configurer.rb
index 832205f5f..2b5e3f98a 100644
--- a/lib/puppet/configurer.rb
+++ b/lib/puppet/configurer.rb
@@ -54,9 +54,7 @@ class Puppet::Configurer
Puppet::Util::Storage.load
@compile_time ||= Puppet::Util::Storage.cache(:configuration)[:compile_time]
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err "Corrupt state file #{Puppet[:statefile]}: #{detail}"
begin
::File.unlink(Puppet[:statefile])
diff --git a/lib/puppet/daemon.rb b/lib/puppet/daemon.rb
index ed06ea6c8..7e2fc7555 100755
--- a/lib/puppet/daemon.rb
+++ b/lib/puppet/daemon.rb
@@ -44,9 +44,7 @@ class Puppet::Daemon
# don't try to start.
def create_pidfile
Puppet::Util.sync(Puppet[:name]).synchronize(Sync::EX) do
- unless Puppet::Util::Pidlock.new(pidfile).lock
- raise "Could not create PID file: #{pidfile}"
- end
+ raise "Could not create PID file: #{pidfile}" unless Puppet::Util::Pidlock.new(pidfile).lock
end
end
@@ -77,9 +75,7 @@ class Puppet::Daemon
def remove_pidfile
Puppet::Util.sync(Puppet[:name]).synchronize(Sync::EX) do
locker = Puppet::Util::Pidlock.new(pidfile)
- if locker.locked?
- locker.unlock or Puppet.err "Could not remove PID file #{pidfile}"
- end
+ locker.unlock or Puppet.err "Could not remove PID file #{pidfile}" if locker.locked?
end
end
diff --git a/lib/puppet/defaults.rb b/lib/puppet/defaults.rb
index 64badedb0..18d045693 100644
--- a/lib/puppet/defaults.rb
+++ b/lib/puppet/defaults.rb
@@ -67,9 +67,7 @@ module Puppet
ENV["PATH"] = value unless value == "none"
paths = ENV["PATH"].split(File::PATH_SEPARATOR)
%w{/usr/sbin /sbin}.each do |path|
- unless paths.include?(path)
- ENV["PATH"] += File::PATH_SEPARATOR + path
- end
+ ENV["PATH"] += File::PATH_SEPARATOR + path unless paths.include?(path)
end
value
end
@@ -82,9 +80,7 @@ module Puppet
is in Ruby's search path",
:call_on_define => true, # Call our hook with the default value, so we always get the libdir set.
:hook => proc do |value|
- if defined?(@oldlibdir) and $LOAD_PATH.include?(@oldlibdir)
- $LOAD_PATH.delete(@oldlibdir)
- end
+ $LOAD_PATH.delete(@oldlibdir) if defined?(@oldlibdir) and $LOAD_PATH.include?(@oldlibdir)
@oldlibdir = value
$LOAD_PATH << value
end
@@ -566,9 +562,7 @@ module Puppet
:call_on_define => false,
:desc => "(Deprecated for 'report_server') The server to which to send transaction reports.",
:hook => proc do |value|
- if value
- Puppet.settings[:report_server] = value
- end
+ Puppet.settings[:report_server] = value if value
end
},
:report_server => ["$server",
diff --git a/lib/puppet/external/event-loop/event-loop.rb b/lib/puppet/external/event-loop/event-loop.rb
index 06fa34607..bd278556c 100644
--- a/lib/puppet/external/event-loop/event-loop.rb
+++ b/lib/puppet/external/event-loop/event-loop.rb
@@ -141,16 +141,12 @@ class EventLoop
def monitor_io (io, *events)
for event in events do
- unless monitoring_io?(io, event)
- @ios[event] << io ; wake_up
- end
+ @ios[event] << io ; wake_up unless monitoring_io?(io, event)
end
end
def monitor_timer (timer)
- unless monitoring_timer? timer
- @timers << timer
- end
+ @timers << timer unless monitoring_timer? timer
end
def check_timer (timer)
@@ -264,9 +260,7 @@ class EventLoop::Timer
@running = false
@start_time = nil
- if options.kind_of? Numeric
- options = { :interval => options }
- end
+ options = { :interval => options } if options.kind_of? Numeric
if options[:interval]
@interval = options[:interval].to_f
@@ -301,9 +295,7 @@ class EventLoop::Timer
def interval= (new_interval)
old_interval = @interval
@interval = new_interval
- if new_interval < old_interval
- @event_loop.check_timer(self)
- end
+ @event_loop.check_timer(self) if new_interval < old_interval
end
def end_time
diff --git a/lib/puppet/external/event-loop/signal-system.rb b/lib/puppet/external/event-loop/signal-system.rb
index 8d97c4359..0ea3552f2 100644
--- a/lib/puppet/external/event-loop/signal-system.rb
+++ b/lib/puppet/external/event-loop/signal-system.rb
@@ -63,9 +63,7 @@ SignalEmitterClass = SignalEmitterModule
module SignalEmitter
def self.included (includer)
- if not includer.kind_of? SignalEmitterClass
- includer.extend SignalEmitterClass
- end
+ includer.extend SignalEmitterClass if not includer.kind_of? SignalEmitterClass
end
def __maybe_initialize_signal_emitter
diff --git a/lib/puppet/external/nagios/base.rb b/lib/puppet/external/nagios/base.rb
index d3766e6f5..9ffac4391 100755
--- a/lib/puppet/external/nagios/base.rb
+++ b/lib/puppet/external/nagios/base.rb
@@ -245,9 +245,7 @@ class Nagios::Base
map = {
self.namevar => "cn"
}
- if self.class.map
- map.update(self.class.map)
- end
+ map.update(self.class.map) if self.class.map
end
if map.include?(param)
return map[param]
@@ -290,9 +288,7 @@ class Nagios::Base
str += "objectclass: #{oc}\n"
}
@parameters.each { |name,value|
- if self.class.suppress.include?(name)
- next
- end
+ next if self.class.suppress.include?(name)
ldapname = self.parammap(name)
str += ldapname + ": #{value}\n"
}
diff --git a/lib/puppet/external/nagios/parser.rb b/lib/puppet/external/nagios/parser.rb
index 80b912bc0..7e83f0346 100644
--- a/lib/puppet/external/nagios/parser.rb
+++ b/lib/puppet/external/nagios/parser.rb
@@ -24,22 +24,16 @@ self.class.module_eval <<'..end racc/parser.rb modeval..id5256434e8a', 'racc/par
# without restriction.
#
-unless defined?(NotImplementedError)
- NotImplementedError = NotImplementError
-end
+NotImplementedError = NotImplementError unless defined?(NotImplementedError)
module Racc
class ParseError < StandardError; end
end
-unless defined?(::ParseError)
- ParseError = Racc::ParseError
-end
+ParseError = Racc::ParseError unless defined?(::ParseError)
module Racc
- unless defined?(Racc_No_Extentions)
- Racc_No_Extentions = false
- end
+ Racc_No_Extentions = false unless defined?(Racc_No_Extentions)
class Parser
@@ -52,12 +46,8 @@ module Racc
require 'racc/cparse'
# Racc_Runtime_Core_Version_C = (defined in extention)
Racc_Runtime_Core_Revision_C = Racc_Runtime_Core_Id_C.split[2]
- unless new.respond_to?(:_racc_do_parse_c, true)
- raise LoadError, 'old cparse.so'
- end
- if Racc_No_Extentions
- raise LoadError, 'selecting ruby version of racc runtime core'
- end
+ raise LoadError, 'old cparse.so' unless new.respond_to?(:_racc_do_parse_c, true)
+ raise LoadError, 'selecting ruby version of racc runtime core' if Racc_No_Extentions
Racc_Main_Parsing_Routine = :_racc_do_parse_c
Racc_YY_Parse_Method = :_racc_yyparse_c
@@ -487,22 +477,16 @@ def token
return [ :RETURN, "\n" ]
end
- if @done
- return nil
- end
+ return nil if @done
yytext = String.new
# remove comments from this line
@src.sub!(/\A[ \t]*;.*\n/,"\n")
- if $MATCH
- return [:INLINECOMMENT, ""]
- end
+ return [:INLINECOMMENT, ""] if $MATCH
@src.sub!(/\A#.*\n/,"\n")
- if $MATCH
- return [:COMMENT, ""]
- end
+ return [:COMMENT, ""] if $MATCH
@src.sub!(/#.*/,'')
@@ -582,9 +566,7 @@ def on_error(token, value, vstack )
else
msg = "line #{@line}: syntax error at '#{token}'"
end
- unless @src.size > 0
- msg = "line #{@line}: Unexpected end of file"
- end
+ msg = "line #{@line}: Unexpected end of file" unless @src.size > 0
if token == '$end'.intern
puts "okay, this is silly"
else
diff --git a/lib/puppet/external/pson/pure/parser.rb b/lib/puppet/external/pson/pure/parser.rb
index ef05637e4..2d0a03066 100644
--- a/lib/puppet/external/pson/pure/parser.rb
+++ b/lib/puppet/external/pson/pure/parser.rb
@@ -144,9 +144,7 @@ module PSON
PSON::UTF16toUTF8.iconv(bytes)
end
end
- if string.respond_to?(:force_encoding)
- string.force_encoding(Encoding::UTF_8)
- end
+ string.force_encoding(Encoding::UTF_8) if string.respond_to?(:force_encoding)
string
else
UNPARSED
@@ -209,9 +207,7 @@ module PSON
raise ParserError, "expected ',' or ']' in array at '#{peek(20)}'!"
end
when scan(ARRAY_CLOSE)
- if delim
- raise ParserError, "expected next element in array at '#{peek(20)}'!"
- end
+ raise ParserError, "expected next element in array at '#{peek(20)}'!" if delim
break
when skip(IGNORE)
;
@@ -231,9 +227,7 @@ module PSON
case
when (string = parse_string) != UNPARSED
skip(IGNORE)
- unless scan(PAIR_DELIMITER)
- raise ParserError, "expected ':' in object at '#{peek(20)}'!"
- end
+ raise ParserError, "expected ':' in object at '#{peek(20)}'!" unless scan(PAIR_DELIMITER)
skip(IGNORE)
unless (value = parse_value).equal? UNPARSED
result[string] = value
@@ -250,9 +244,7 @@ module PSON
raise ParserError, "expected value in object at '#{peek(20)}'!"
end
when scan(OBJECT_CLOSE)
- if delim
- raise ParserError, "expected next name, value pair in object at '#{peek(20)}'!"
- end
+ raise ParserError, "expected next name, value pair in object at '#{peek(20)}'!" if delim
if @create_id and klassname = result[@create_id]
klass = PSON.deep_const_get klassname
break unless klass and klass.pson_creatable?
diff --git a/lib/puppet/feature/rails.rb b/lib/puppet/feature/rails.rb
index f1997bd6b..05d416edc 100644
--- a/lib/puppet/feature/rails.rb
+++ b/lib/puppet/feature/rails.rb
@@ -20,9 +20,7 @@ Puppet.features.add(:rails) do
end
end
- if count > 0
- retry
- end
+ retry if count > 0
end
end
diff --git a/lib/puppet/file_bucket/dipper.rb b/lib/puppet/file_bucket/dipper.rb
index 714f4f9cd..73b2035d1 100644
--- a/lib/puppet/file_bucket/dipper.rb
+++ b/lib/puppet/file_bucket/dipper.rb
@@ -30,9 +30,7 @@ class Puppet::FileBucket::Dipper
# Back up a file to our bucket
def backup(file)
- unless ::File.exist?(file)
- raise(ArgumentError, "File #{file} does not exist")
- end
+ raise(ArgumentError, "File #{file} does not exist") unless ::File.exist?(file)
contents = ::File.read(file)
begin
file_bucket_file = Puppet::FileBucket::File.new(contents, :bucket_path => @local_path, :path => absolutize_path(file) )
@@ -80,9 +78,7 @@ class Puppet::FileBucket::Dipper
::File.open(file, ::File::WRONLY|::File::TRUNC|::File::CREAT) { |of|
of.print(newcontents)
}
- if changed
- ::File.chmod(changed, file)
- end
+ ::File.chmod(changed, file) if changed
else
Puppet.err "Could not find file with checksum #{sum}"
return nil
diff --git a/lib/puppet/file_serving/base.rb b/lib/puppet/file_serving/base.rb
index 8e55f742a..c17b83f96 100644
--- a/lib/puppet/file_serving/base.rb
+++ b/lib/puppet/file_serving/base.rb
@@ -69,9 +69,7 @@ class Puppet::FileServing::Base
# Stat our file, using the appropriate link-sensitive method.
def stat
- unless defined?(@stat_method)
- @stat_method = self.links == :manage ? :lstat : :stat
- end
+ @stat_method = self.links == :manage ? :lstat : :stat unless defined?(@stat_method)
File.send(@stat_method, full_path())
end
diff --git a/lib/puppet/file_serving/configuration.rb b/lib/puppet/file_serving/configuration.rb
index 69b1f9329..5f958eb1d 100644
--- a/lib/puppet/file_serving/configuration.rb
+++ b/lib/puppet/file_serving/configuration.rb
@@ -109,9 +109,7 @@ class Puppet::FileServing::Configuration
@parser ||= Puppet::FileServing::Configuration::Parser.new(config)
- if check and ! @parser.changed?
- return
- end
+ return if check and ! @parser.changed?
# Don't assign the mounts hash until we're sure the parsing succeeded.
begin
diff --git a/lib/puppet/file_serving/configuration/parser.rb b/lib/puppet/file_serving/configuration/parser.rb
index f40a554e3..79fb0314d 100644
--- a/lib/puppet/file_serving/configuration/parser.rb
+++ b/lib/puppet/file_serving/configuration/parser.rb
@@ -87,9 +87,7 @@ class Puppet::FileServing::Configuration::Parser < Puppet::Util::LoadedFile
# Create a new mount.
def newmount(name)
- if @mounts.include?(name)
- raise ArgumentError, "#{@mounts[name]} is already mounted at #{name}", @count, file
- end
+ raise ArgumentError, "#{@mounts[name]} is already mounted at #{name}", @count, file if @mounts.include?(name)
case name
when "modules"
mount = Mount::Modules.new(name)
diff --git a/lib/puppet/file_serving/fileset.rb b/lib/puppet/file_serving/fileset.rb
index 4155685d6..dbfe46631 100644
--- a/lib/puppet/file_serving/fileset.rb
+++ b/lib/puppet/file_serving/fileset.rb
@@ -158,9 +158,7 @@ class Puppet::FileServing::Fileset
public
# Stat a given file, using the links-appropriate method.
def stat(path)
- unless defined?(@stat_method)
- @stat_method = self.links == :manage ? :lstat : :stat
- end
+ @stat_method = self.links == :manage ? :lstat : :stat unless defined?(@stat_method)
begin
return File.send(@stat_method, path)
diff --git a/lib/puppet/file_serving/mount/file.rb b/lib/puppet/file_serving/mount/file.rb
index c876cc2c0..89d8c0587 100644
--- a/lib/puppet/file_serving/mount/file.rb
+++ b/lib/puppet/file_serving/mount/file.rb
@@ -55,12 +55,8 @@ class Puppet::FileServing::Mount::File < Puppet::FileServing::Mount
# Mark that we're expandable.
@expandable = true
else
- unless FileTest.directory?(path)
- raise ArgumentError, "#{path} does not exist or is not a directory"
- end
- unless FileTest.readable?(path)
- raise ArgumentError, "#{path} is not readable"
- end
+ raise ArgumentError, "#{path} does not exist or is not a directory" unless FileTest.directory?(path)
+ raise ArgumentError, "#{path} is not readable" unless FileTest.readable?(path)
@expandable = false
end
@path = path
diff --git a/lib/puppet/indirector/catalog/compiler.rb b/lib/puppet/indirector/catalog/compiler.rb
index a689eff2d..c990456e3 100644
--- a/lib/puppet/indirector/catalog/compiler.rb
+++ b/lib/puppet/indirector/catalog/compiler.rb
@@ -67,9 +67,7 @@ class Puppet::Resource::Catalog::Compiler < Puppet::Indirector::Code
# Compile the actual catalog.
def compile(node)
str = "Compiled catalog for #{node.name}"
- if node.environment
- str += " in environment #{node.environment}"
- end
+ str += " in environment #{node.environment}" if node.environment
config = nil
loglevel = networked? ? :notice : :none
diff --git a/lib/puppet/indirector/exec.rb b/lib/puppet/indirector/exec.rb
index f8d863562..cf09ed379 100644
--- a/lib/puppet/indirector/exec.rb
+++ b/lib/puppet/indirector/exec.rb
@@ -25,14 +25,10 @@ class Puppet::Indirector::Exec < Puppet::Indirector::Terminus
external_command = command
# Make sure it's an arry
- unless external_command.is_a?(Array)
- raise Puppet::DevError, "Exec commands must be an array"
- end
+ raise Puppet::DevError, "Exec commands must be an array" unless external_command.is_a?(Array)
# Make sure it's fully qualified.
- unless external_command[0][0] == File::SEPARATOR[0]
- raise ArgumentError, "You must set the exec parameter to a fully qualified command"
- end
+ raise ArgumentError, "You must set the exec parameter to a fully qualified command" unless external_command[0][0] == File::SEPARATOR[0]
# Add our name to it.
external_command << name
diff --git a/lib/puppet/indirector/file_bucket_file/file.rb b/lib/puppet/indirector/file_bucket_file/file.rb
index 1667c1d7e..0cd3cda65 100644
--- a/lib/puppet/indirector/file_bucket_file/file.rb
+++ b/lib/puppet/indirector/file_bucket_file/file.rb
@@ -36,9 +36,7 @@ module Puppet::FileBucketFile
bucket_file.bucket_path = options[:bucket_path]
filename = contents_path_for( bucket_file )
- if ! ::File.exist? filename
- return nil
- end
+ return nil if ! ::File.exist? filename
begin
contents = ::File.read filename
diff --git a/lib/puppet/indirector/indirection.rb b/lib/puppet/indirector/indirection.rb
index 95a022e38..b7a6b8f1d 100644
--- a/lib/puppet/indirector/indirection.rb
+++ b/lib/puppet/indirector/indirection.rb
@@ -64,9 +64,7 @@ class Puppet::Indirector::Indirection
# Default to the runinterval for the ttl.
def ttl
- unless defined?(@ttl)
- @ttl = Puppet[:runinterval].to_i
- end
+ @ttl = Puppet[:runinterval].to_i unless defined?(@ttl)
@ttl
end
@@ -79,9 +77,7 @@ class Puppet::Indirector::Indirection
def doc
text = ""
- if defined?(@doc) and @doc
- text += scrub(@doc) + "\n\n"
- end
+ text += scrub(@doc) + "\n\n" if defined?(@doc) and @doc
if s = terminus_setting()
text += "* **Terminus Setting**: #{terminus_setting}"
@@ -123,9 +119,7 @@ class Puppet::Indirector::Indirection
# Return the singleton terminus for this indirection.
def terminus(terminus_name = nil)
# Get the name of the terminus.
- unless terminus_name ||= terminus_class
- raise Puppet::DevError, "No terminus specified for #{self.name}; cannot redirect"
- end
+ raise Puppet::DevError, "No terminus specified for #{self.name}; cannot redirect" unless terminus_name ||= terminus_class
return termini[terminus_name] ||= make_terminus(terminus_name)
end
@@ -157,9 +151,7 @@ class Puppet::Indirector::Indirection
# This is used by terminus_class= and cache=.
def validate_terminus_class(terminus_class)
- unless terminus_class and terminus_class.to_s != ""
- raise ArgumentError, "Invalid terminus name #{terminus_class.inspect}"
- end
+ raise ArgumentError, "Invalid terminus name #{terminus_class.inspect}" unless terminus_class and terminus_class.to_s != ""
unless Puppet::Indirector::Terminus.terminus_class(self.name, terminus_class)
raise ArgumentError, "Could not find terminus #{terminus_class} for indirection #{self.name}"
end
@@ -281,9 +273,7 @@ class Puppet::Indirector::Indirection
unless terminus.authorized?(request)
msg = "Not authorized to call #{request.method} on #{request}"
- unless request.options.empty?
- msg += " with #{request.options.inspect}"
- end
+ msg += " with #{request.options.inspect}" unless request.options.empty?
raise ArgumentError, msg
end
end
diff --git a/lib/puppet/indirector/ldap.rb b/lib/puppet/indirector/ldap.rb
index 5888418ee..795aafa67 100644
--- a/lib/puppet/indirector/ldap.rb
+++ b/lib/puppet/indirector/ldap.rb
@@ -62,9 +62,7 @@ class Puppet::Indirector::Ldap < Puppet::Indirector::Terminus
# Create an ldap connection.
def connection
unless defined?(@connection) and @connection
- unless Puppet.features.ldap?
- raise Puppet::Error, "Could not set up LDAP Connection: Missing ruby/ldap libraries"
- end
+ raise Puppet::Error, "Could not set up LDAP Connection: Missing ruby/ldap libraries" unless Puppet.features.ldap?
begin
conn = Puppet::Util::Ldap::Connection.instance
conn.start
diff --git a/lib/puppet/indirector/node/exec.rb b/lib/puppet/indirector/node/exec.rb
index 445059d14..cac515f59 100644
--- a/lib/puppet/indirector/node/exec.rb
+++ b/lib/puppet/indirector/node/exec.rb
@@ -8,9 +8,7 @@ class Puppet::Node::Exec < Puppet::Indirector::Exec
def command
command = Puppet[:external_nodes]
- unless command != "none"
- raise ArgumentError, "You must set the 'external_nodes' parameter to use the external node terminus"
- end
+ raise ArgumentError, "You must set the 'external_nodes' parameter to use the external node terminus" unless command != "none"
command.split
end
diff --git a/lib/puppet/indirector/node/ldap.rb b/lib/puppet/indirector/node/ldap.rb
index 4cbc97573..71bca586d 100644
--- a/lib/puppet/indirector/node/ldap.rb
+++ b/lib/puppet/indirector/node/ldap.rb
@@ -49,9 +49,7 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
# Look for our node in ldap.
def find(request)
names = [request.key]
- if request.key.include?(".") # we assume it's an fqdn
- names << request.key.sub(/\..+/, '')
- end
+ names << request.key.sub(/\..+/, '') if request.key.include?(".") # we assume it's an fqdn
names << "default"
node = nil
@@ -248,9 +246,7 @@ class Puppet::Node::Ldap < Puppet::Indirector::Ldap
# Preload the parent array with the node name.
parents = [info[:name]]
while parent
- if parents.include?(parent)
- raise ArgumentError, "Found loop in LDAP node parents; #{parent} appears twice"
- end
+ raise ArgumentError, "Found loop in LDAP node parents; #{parent} appears twice" if parents.include?(parent)
parents << parent
parent = find_and_merge_parent(parent, info)
end
diff --git a/lib/puppet/indirector/report/processor.rb b/lib/puppet/indirector/report/processor.rb
index 1b4c5ef8d..80570d9c3 100644
--- a/lib/puppet/indirector/report/processor.rb
+++ b/lib/puppet/indirector/report/processor.rb
@@ -31,9 +31,7 @@ class Puppet::Transaction::Report::Processor < Puppet::Indirector::Code
newrep.extend(mod)
newrep.process
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err "Report #{name} failed: #{detail}"
end
else
diff --git a/lib/puppet/indirector/request.rb b/lib/puppet/indirector/request.rb
index 6d19e59d7..373d4a27d 100644
--- a/lib/puppet/indirector/request.rb
+++ b/lib/puppet/indirector/request.rb
@@ -21,9 +21,7 @@ class Puppet::Indirector::Request
end
def environment
- unless defined?(@environment) and @environment
- @environment = Puppet::Node::Environment.new()
- end
+ @environment = Puppet::Node::Environment.new() unless defined?(@environment) and @environment
@environment
end
diff --git a/lib/puppet/indirector/rest.rb b/lib/puppet/indirector/rest.rb
index f38d1f927..6061b533d 100644
--- a/lib/puppet/indirector/rest.rb
+++ b/lib/puppet/indirector/rest.rb
@@ -39,9 +39,7 @@ class Puppet::Indirector::REST < Puppet::Indirector::Terminus
when "404"
return nil
when /^2/
- unless response['content-type']
- raise "No content type in http response; cannot parse"
- end
+ raise "No content type in http response; cannot parse" unless response['content-type']
content_type = response['content-type'].gsub(/\s*;.*$/,'') # strip any appended charset
diff --git a/lib/puppet/indirector/terminus.rb b/lib/puppet/indirector/terminus.rb
index 60f8ec1f2..546f83524 100644
--- a/lib/puppet/indirector/terminus.rb
+++ b/lib/puppet/indirector/terminus.rb
@@ -122,9 +122,7 @@ class Puppet::Indirector::Terminus
private
def setup_instance_loading(type)
- unless instance_loading?(type)
- instance_load type, "puppet/indirector/#{type}"
- end
+ instance_load type, "puppet/indirector/#{type}" unless instance_loading?(type)
end
end
@@ -133,9 +131,7 @@ class Puppet::Indirector::Terminus
end
def initialize
- if self.class.abstract_terminus?
- raise Puppet::DevError, "Cannot create instances of abstract terminus types"
- end
+ raise Puppet::DevError, "Cannot create instances of abstract terminus types" if self.class.abstract_terminus?
end
def model
diff --git a/lib/puppet/indirector/yaml.rb b/lib/puppet/indirector/yaml.rb
index d82cbfa1d..826a8ae9d 100644
--- a/lib/puppet/indirector/yaml.rb
+++ b/lib/puppet/indirector/yaml.rb
@@ -32,9 +32,7 @@ class Puppet::Indirector::Yaml < Puppet::Indirector::Terminus
basedir = File.dirname(file)
# This is quite likely a bad idea, since we're not managing ownership or modes.
- unless FileTest.exist?(basedir)
- Dir.mkdir(basedir)
- end
+ Dir.mkdir(basedir) unless FileTest.exist?(basedir)
begin
writelock(file, 0660) { |f| f.print to_yaml(request.instance) }
diff --git a/lib/puppet/metatype/manager.rb b/lib/puppet/metatype/manager.rb
index 6d634c245..118862bc7 100644
--- a/lib/puppet/metatype/manager.rb
+++ b/lib/puppet/metatype/manager.rb
@@ -83,9 +83,7 @@ module Manager
# If they've got all the necessary methods defined and they haven't
# already added the property, then do so now.
- if klass.ensurable? and ! klass.validproperty?(:ensure)
- klass.ensurable
- end
+ klass.ensurable if klass.ensurable? and ! klass.validproperty?(:ensure)
# Now set up autoload any providers that might exist for this type.
@@ -111,9 +109,7 @@ module Manager
:hash => @types
)
- if respond_to?("new#{name}")
- singleton_class.send(:remove_method, "new#{name}")
- end
+ singleton_class.send(:remove_method, "new#{name}") if respond_to?("new#{name}")
end
# Return a Type instance by name.
@@ -126,9 +122,7 @@ module Manager
return t
else
if typeloader.load(name)
- unless @types.include? name
- Puppet.warning "Loaded puppet/type/#{name} but no class was created"
- end
+ Puppet.warning "Loaded puppet/type/#{name} but no class was created" unless @types.include? name
end
return @types[name]
diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb
index 611cbdd4b..821cca924 100644
--- a/lib/puppet/module.rb
+++ b/lib/puppet/module.rb
@@ -158,9 +158,7 @@ class Puppet::Module
def to_s
result = "Module #{name}"
- if path
- result += "(#{path})"
- end
+ result += "(#{path})" if path
result
end
diff --git a/lib/puppet/network/authconfig.rb b/lib/puppet/network/authconfig.rb
index 7c3a51743..8c2ad5857 100644
--- a/lib/puppet/network/authconfig.rb
+++ b/lib/puppet/network/authconfig.rb
@@ -6,9 +6,7 @@ module Puppet
class Network::AuthConfig < Puppet::Util::LoadedFile
def self.main
- unless defined?(@main)
- @main = self.new()
- end
+ @main = self.new() unless defined?(@main)
@main
end
@@ -45,18 +43,14 @@ module Puppet
def initialize(file = nil, parsenow = true)
@file = file || Puppet[:authconfig]
- unless @file
- raise Puppet::DevError, "No authconfig file defined"
- end
+ raise Puppet::DevError, "No authconfig file defined" unless @file
return unless self.exists?
super(@file)
@rights = Puppet::Network::Rights.new
@configstamp = @configstatted = nil
@configtimeout = 60
- if parsenow
- read()
- end
+ read() if parsenow
end
# Read the configuration file.
@@ -106,9 +100,7 @@ module Puppet
next
when /^(?:(\[[\w.]+\])|(path)\s+((?:~\s+)?[^ ]+))\s*$/ # "namespace" or "namespace.method" or "path /path" or "path ~ regex"
name = $1
- if $2 == "path"
- name = $3
- end
+ name = $3 if $2 == "path"
name.chomp!
right = newrights.newright(name, count, @file)
when /^\s*(allow|deny|method|environment|auth(?:enticated)?)\s+(.+)$/
diff --git a/lib/puppet/network/authorization.rb b/lib/puppet/network/authorization.rb
index 97db59338..136875392 100644
--- a/lib/puppet/network/authorization.rb
+++ b/lib/puppet/network/authorization.rb
@@ -10,9 +10,7 @@ module Puppet::Network
# Create our config object if necessary. This works even if
# there's no configuration file.
def authconfig
- unless defined?(@authconfig)
- @authconfig = Puppet::Network::AuthConfig.main()
- end
+ @authconfig = Puppet::Network::AuthConfig.main() unless defined?(@authconfig)
@authconfig
end
diff --git a/lib/puppet/network/authstore.rb b/lib/puppet/network/authstore.rb
index dc3451e34..555a5df64 100755
--- a/lib/puppet/network/authstore.rb
+++ b/lib/puppet/network/authstore.rb
@@ -31,9 +31,7 @@ module Puppet
# This is probably unnecessary, and can cause some weirdnesses in
# cases where we're operating over localhost but don't have a real
# IP defined.
- unless name and ip
- raise Puppet::DevError, "Name and IP must be passed to 'allowed?'"
- end
+ raise Puppet::DevError, "Name and IP must be passed to 'allowed?'" unless name and ip
# else, we're networked and such
else
# we're local
@@ -41,9 +39,7 @@ module Puppet
end
# yay insecure overrides
- if globalallow?
- return true
- end
+ return true if globalallow?
if decl = declarations.find { |d| d.match?(name, ip) }
return decl.result
@@ -175,9 +171,7 @@ module Puppet
# Set the declaration type. Either :allow or :deny.
def type=(type)
type = symbolize(type)
- unless [:allow, :deny].include?(type)
- raise ArgumentError, "Invalid declaration type #{type}"
- end
+ raise ArgumentError, "Invalid declaration type #{type}" unless [:allow, :deny].include?(type)
@type = type
end
diff --git a/lib/puppet/network/client.rb b/lib/puppet/network/client.rb
index 7bdde65be..6d8779f5b 100644
--- a/lib/puppet/network/client.rb
+++ b/lib/puppet/network/client.rb
@@ -23,9 +23,7 @@ class Net::HTTP
# JJM: This is a "backport" of sorts to older ruby versions which
# do not have this accessor. See #896 for more information.
- unless Net::HTTP.instance_methods.include? "enable_post_connection_check"
- attr_accessor :enable_post_connection_check
- end
+ attr_accessor :enable_post_connection_check unless Net::HTTP.instance_methods.include? "enable_post_connection_check"
end
# The base class for all of the clients. Many clients just directly
@@ -50,25 +48,19 @@ class Puppet::Network::Client
# Determine what clients look for when being passed an object for local
# client/server stuff. E.g., you could call Client::CA.new(:CA => ca).
def self.drivername
- unless defined?(@drivername)
- @drivername = self.name
- end
+ @drivername = self.name unless defined?(@drivername)
@drivername
end
# Figure out the handler for our client.
def self.handler
- unless defined?(@handler)
- @handler = Puppet::Network::Handler.handler(self.name)
- end
+ @handler = Puppet::Network::Handler.handler(self.name) unless defined?(@handler)
@handler
end
# The class that handles xmlrpc interaction for us.
def self.xmlrpc_client
- unless defined?(@xmlrpc_client)
- @xmlrpc_client = Puppet::Network::XMLRPCClient.handler_class(self.handler)
- end
+ @xmlrpc_client = Puppet::Network::XMLRPCClient.handler_class(self.handler) unless defined?(@xmlrpc_client)
@xmlrpc_client
end
@@ -156,9 +148,7 @@ class Puppet::Network::Client
Puppet.notice "Already in shutdown"
else
self.stopping = true
- if self.respond_to? :running? and self.running?
- Puppet::Util::Storage.store
- end
+ Puppet::Util::Storage.store if self.respond_to? :running? and self.running?
rmpidfile()
end
end
diff --git a/lib/puppet/network/client/ca.rb b/lib/puppet/network/client/ca.rb
index 2b96cd681..1460e4d6e 100644
--- a/lib/puppet/network/client/ca.rb
+++ b/lib/puppet/network/client/ca.rb
@@ -25,9 +25,7 @@ class Puppet::Network::Client::CA < Puppet::Network::Client
begin
cert, cacert = @driver.getcert(csr.to_pem)
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
raise Puppet::Error.new("Certificate retrieval failed: #{detail}")
end
diff --git a/lib/puppet/network/client/report.rb b/lib/puppet/network/client/report.rb
index 9bd61de2e..f4a9cdaa7 100644
--- a/lib/puppet/network/client/report.rb
+++ b/lib/puppet/network/client/report.rb
@@ -2,9 +2,7 @@ class Puppet::Network::Client::Report < Puppet::Network::Client
@handler = Puppet::Network::Handler.handler(:report)
def initialize(hash = {})
- if hash.include?(:Report)
- hash[:Report] = self.class.handler.new
- end
+ hash[:Report] = self.class.handler.new if hash.include?(:Report)
super(hash)
end
@@ -14,9 +12,7 @@ class Puppet::Network::Client::Report < Puppet::Network::Client
def report(transreport)
report = YAML.dump(transreport)
- unless self.local
- report = CGI.escape(report)
- end
+ report = CGI.escape(report) unless self.local
# Now send the report
file = nil
diff --git a/lib/puppet/network/client/runner.rb b/lib/puppet/network/client/runner.rb
index 5806dd343..c6ba328b4 100644
--- a/lib/puppet/network/client/runner.rb
+++ b/lib/puppet/network/client/runner.rb
@@ -2,9 +2,7 @@ class Puppet::Network::Client::Runner < Puppet::Network::Client::ProxyClient
self.mkmethods
def initialize(hash = {})
- if hash.include?(:Runner)
- hash[:Runner] = self.class.handler.new()
- end
+ hash[:Runner] = self.class.handler.new() if hash.include?(:Runner)
super(hash)
end
diff --git a/lib/puppet/network/client_request.rb b/lib/puppet/network/client_request.rb
index 07c974799..f914bad09 100644
--- a/lib/puppet/network/client_request.rb
+++ b/lib/puppet/network/client_request.rb
@@ -12,9 +12,7 @@ module Puppet::Network # :nodoc:
# are responsible for setting the values correctly, but this common
# format makes it possible to check rights.
def call
- unless handler and method
- raise ArgumentError, "Request is not set up; cannot build call"
- end
+ raise ArgumentError, "Request is not set up; cannot build call" unless handler and method
[handler, method].join(".")
end
diff --git a/lib/puppet/network/format.rb b/lib/puppet/network/format.rb
index 59082c72a..fb5a74a1c 100644
--- a/lib/puppet/network/format.rb
+++ b/lib/puppet/network/format.rb
@@ -42,9 +42,7 @@ class Puppet::Network::Format
init_attribute(method, value)
end
- unless @options.empty?
- raise ArgumentError, "Unsupported option(s) #{@options.keys}"
- end
+ raise ArgumentError, "Unsupported option(s) #{@options.keys}" unless @options.empty?
@options = nil
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index dfdb4cc67..2d519aea6 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -153,9 +153,7 @@ Puppet::Network::FormatHandler.create(:pson, :mime => "text/pson", :weight => 10
if data.is_a?(Hash) and d = data['data']
data = d
end
- if data.is_a?(klass)
- return data
- end
+ return data if data.is_a?(klass)
klass.from_pson(data)
end
end
diff --git a/lib/puppet/network/handler.rb b/lib/puppet/network/handler.rb
index 3903bdc63..4b741eb0f 100644
--- a/lib/puppet/network/handler.rb
+++ b/lib/puppet/network/handler.rb
@@ -30,9 +30,7 @@ module Puppet::Network
def self.side(side = nil)
if side
side = side.intern if side.is_a?(String)
- unless [:client, :server].include?(side)
- raise ArgumentError, "Invalid side registration '#{side}' for #{self.name}"
- end
+ raise ArgumentError, "Invalid side registration '#{side}' for #{self.name}" unless [:client, :server].include?(side)
@side = side
else
@side ||= :server
diff --git a/lib/puppet/network/handler/ca.rb b/lib/puppet/network/handler/ca.rb
index 8bafb5f9b..c72171d5d 100644
--- a/lib/puppet/network/handler/ca.rb
+++ b/lib/puppet/network/handler/ca.rb
@@ -60,9 +60,7 @@ class Puppet::Network::Handler
def initialize(hash = {})
Puppet.settings.use(:main, :ssl, :ca)
- if hash.include? :autosign
- @autosign = hash[:autosign]
- end
+ @autosign = hash[:autosign] if hash.include? :autosign
@ca = Puppet::SSLCertificates::CA.new(hash)
end
@@ -109,9 +107,7 @@ class Puppet::Network::Handler
return [cert.to_pem, cacert.to_pem]
elsif @ca
if self.autosign?(hostname) or client.nil?
- if client.nil?
- Puppet.info "Signing certificate for CA server"
- end
+ Puppet.info "Signing certificate for CA server" if client.nil?
# okay, we don't have a signed cert
# if we're a CA and autosign is turned on, then go ahead and sign
# the csr and return the results
diff --git a/lib/puppet/network/handler/filebucket.rb b/lib/puppet/network/handler/filebucket.rb
index bea1c85f5..13fee1661 100755
--- a/lib/puppet/network/handler/filebucket.rb
+++ b/lib/puppet/network/handler/filebucket.rb
@@ -26,9 +26,7 @@ class Puppet::Network::Handler # :nodoc:
# Accept a file from a client and store it by md5 sum, returning
# the sum.
def addfile(contents, path, client = nil, clientip = nil)
- if client
- contents = Base64.decode64(contents)
- end
+ contents = Base64.decode64(contents) if client
bucket = Puppet::FileBucket::File.new(contents)
return bucket.save
end
diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb
index 756e74909..cb54ca4e4 100755
--- a/lib/puppet/network/handler/fileserver.rb
+++ b/lib/puppet/network/handler/fileserver.rb
@@ -98,22 +98,16 @@ class Puppet::Network::Handler
@local = false
end
- if hash[:Config] == false
- @noreadconfig = true
- end
+ @noreadconfig = true if hash[:Config] == false
@passed_configuration_path = hash[:Config]
if hash.include?(:Mount)
@passedconfig = true
- unless hash[:Mount].is_a?(Hash)
- raise Puppet::DevError, "Invalid mount hash #{hash[:Mount].inspect}"
- end
+ raise Puppet::DevError, "Invalid mount hash #{hash[:Mount].inspect}" unless hash[:Mount].is_a?(Hash)
hash[:Mount].each { |dir, name|
- if FileTest.exists?(dir)
- self.mount(dir, name)
- end
+ self.mount(dir, name) if FileTest.exists?(dir)
}
self.mount(nil, MODULES)
self.mount(nil, PLUGINS)
@@ -179,9 +173,7 @@ class Puppet::Network::Handler
mount, path = convert(url, client, clientip)
- if client
- mount.info "Sending #{url} to #{client}"
- end
+ mount.info "Sending #{url} to #{client}" if client
unless mount.path_exists?(path, client)
mount.debug "#{mount} reported that #{path} does not exist"
@@ -264,9 +256,7 @@ class Puppet::Network::Handler
return unless configuration
- if check and ! @configuration.changed?
- return
- end
+ return if check and ! @configuration.changed?
newmounts = {}
begin
@@ -279,9 +269,7 @@ class Puppet::Network::Handler
when /^\s*$/; next # skip blank lines
when /\[([-\w]+)\]/
name = $1
- if newmounts.include?(name)
- raise FileServerError, "#{newmounts[name]} is already mounted as #{name} in #{@configuration.file}"
- end
+ raise FileServerError, "#{newmounts[name]} is already mounted as #{name} in #{@configuration.file}" if newmounts.include?(name)
mount = Mount.new(name)
newmounts[name] = mount
when /^\s*(\w+)\s+(.+)$/
@@ -379,9 +367,7 @@ class Puppet::Network::Handler
# We let the check raise an error, so that it can raise an error
# pointing to the specific problem.
newmounts.each { |name, mount|
- unless mount.valid?
- raise FileServerError, "Invalid mount #{name}"
- end
+ raise FileServerError, "Invalid mount #{name}" unless mount.valid?
}
@mounts = newmounts
end
@@ -529,9 +515,7 @@ class Puppet::Network::Handler
end
# This, ah, might be completely redundant
- unless obj[:links] == links
- obj[:links] = links
- end
+ obj[:links] = links unless obj[:links] == links
return obj
end
@@ -572,15 +556,9 @@ class Puppet::Network::Handler
# Mark that we're expandable.
@expandable = true
else
- unless FileTest.exists?(path)
- raise FileServerError, "#{path} does not exist"
- end
- unless FileTest.directory?(path)
- raise FileServerError, "#{path} is not a directory"
- end
- unless FileTest.readable?(path)
- raise FileServerError, "#{path} is not readable"
- end
+ raise FileServerError, "#{path} does not exist" unless FileTest.exists?(path)
+ raise FileServerError, "#{path} is not a directory" unless FileTest.directory?(path)
+ raise FileServerError, "#{path} is not readable" unless FileTest.readable?(path)
@expandable = false
end
@path = path
diff --git a/lib/puppet/network/handler/master.rb b/lib/puppet/network/handler/master.rb
index beb6e4c57..d55046b5b 100644
--- a/lib/puppet/network/handler/master.rb
+++ b/lib/puppet/network/handler/master.rb
@@ -45,9 +45,7 @@ class Puppet::Network::Handler
# This is only used by the cfengine module, or if --loadclasses was
# specified in +puppet+.
- if hash.include?(:Classes)
- args[:Classes] = hash[:Classes]
- end
+ args[:Classes] = hash[:Classes] if hash.include?(:Classes)
end
# Call our various handlers; this handler is getting deprecated.
diff --git a/lib/puppet/network/handler/report.rb b/lib/puppet/network/handler/report.rb
index 9f885518e..50e2fbfea 100755
--- a/lib/puppet/network/handler/report.rb
+++ b/lib/puppet/network/handler/report.rb
@@ -24,18 +24,14 @@ class Puppet::Network::Handler
# Accept a report from a client.
def report(report, client = nil, clientip = nil)
# Unescape the report
- unless @local
- report = CGI.unescape(report)
- end
+ report = CGI.unescape(report) unless @local
Puppet.info "Processing reports #{reports().join(", ")} for #{client}"
begin
process(report)
rescue => detail
Puppet.err "Could not process report for #{client}: #{detail}"
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
end
end
@@ -65,9 +61,7 @@ class Puppet::Network::Handler
newrep.extend(mod)
newrep.process
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err "Report #{name} failed: #{detail}"
end
else
diff --git a/lib/puppet/network/http/api/v1.rb b/lib/puppet/network/http/api/v1.rb
index 25e27c486..347da93a6 100644
--- a/lib/puppet/network/http/api/v1.rb
+++ b/lib/puppet/network/http/api/v1.rb
@@ -39,9 +39,7 @@ module Puppet::Network::HTTP::API::V1
end
def indirection_method(http_method, indirection)
- unless METHOD_MAP[http_method]
- raise ArgumentError, "No support for http method #{http_method}"
- end
+ raise ArgumentError, "No support for http method #{http_method}" unless METHOD_MAP[http_method]
unless method = METHOD_MAP[http_method][plurality(indirection)]
raise ArgumentError, "No support for plural #{http_method} operations"
diff --git a/lib/puppet/network/http/mongrel.rb b/lib/puppet/network/http/mongrel.rb
index 8181600e3..88494eea8 100644
--- a/lib/puppet/network/http/mongrel.rb
+++ b/lib/puppet/network/http/mongrel.rb
@@ -40,9 +40,7 @@ class Puppet::Network::HTTP::Mongrel
klass = class_for_protocol(:rest)
@server.register('/', klass.new(:server => @server))
- if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
- setup_xmlrpc_handlers
- end
+ setup_xmlrpc_handlers if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
end
# Use our existing code to provide the xmlrpc backward compatibility.
diff --git a/lib/puppet/network/http/rack/xmlrpc.rb b/lib/puppet/network/http/rack/xmlrpc.rb
index 49eb6fe49..9192b1d48 100644
--- a/lib/puppet/network/http/rack/xmlrpc.rb
+++ b/lib/puppet/network/http/rack/xmlrpc.rb
@@ -18,12 +18,12 @@ class Puppet::Network::HTTP::RackXMLRPC < Puppet::Network::HTTP::RackHttpHandler
def process(request, response)
# errors are sent as text/plain
response['Content-Type'] = 'text/plain'
- if not request.post? then
+ if not request.post?
response.status = 405
response.write 'Method Not Allowed'
return
end
- if request.media_type() != "text/xml" then
+ if request.media_type() != "text/xml"
response.status = 400
response.write 'Bad Request'
return
diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb
index d0533f7ff..66932ad2c 100644
--- a/lib/puppet/network/http/webrick.rb
+++ b/lib/puppet/network/http/webrick.rb
@@ -105,9 +105,7 @@ class Puppet::Network::HTTP::WEBrick
results[:SSLStartImmediately] = true
results[:SSLEnable] = true
- unless Puppet::SSL::Certificate.find(Puppet::SSL::CA_NAME)
- raise Puppet::Error, "Could not find CA certificate"
- end
+ raise Puppet::Error, "Could not find CA certificate" unless Puppet::SSL::Certificate.find(Puppet::SSL::CA_NAME)
results[:SSLCACertificateFile] = Puppet[:localcacert]
results[:SSLVerifyClient] = OpenSSL::SSL::VERIFY_PEER
@@ -125,9 +123,7 @@ class Puppet::Network::HTTP::WEBrick
@server.mount('/', klass, :this_value_is_apparently_necessary_but_unused)
# And then set up xmlrpc, if configured.
- if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
- @server.mount("/RPC2", xmlrpc_servlet)
- end
+ @server.mount("/RPC2", xmlrpc_servlet) if @protocols.include?(:xmlrpc) and ! @xmlrpc_handlers.empty?
end
# Create our xmlrpc servlet, which provides backward compatibility.
diff --git a/lib/puppet/network/http/webrick/rest.rb b/lib/puppet/network/http/webrick/rest.rb
index 9bfd0ce6a..9a8bf0a83 100644
--- a/lib/puppet/network/http/webrick/rest.rb
+++ b/lib/puppet/network/http/webrick/rest.rb
@@ -52,9 +52,7 @@ class Puppet::Network::HTTP::WEBrickREST < WEBrick::HTTPServlet::AbstractServlet
response.status = status
if status >= 200 and status != 304
response.body = result
- if result.is_a?(File)
- response["content-length"] = result.stat.size
- end
+ response["content-length"] = result.stat.size if result.is_a?(File)
end
response.reason_phrase = result if status < 200 or status >= 300
end
diff --git a/lib/puppet/network/http_pool.rb b/lib/puppet/network/http_pool.rb
index 458fe2c97..2bccba2e8 100644
--- a/lib/puppet/network/http_pool.rb
+++ b/lib/puppet/network/http_pool.rb
@@ -58,9 +58,7 @@ module Puppet::Network::HttpPool
http.cert = ssl_host.certificate.content
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
http.key = ssl_host.key.content
- if Puppet[:debug]
- http.verify_callback = self.method(:ssl_verify_callback).to_proc
- end
+ http.verify_callback = self.method(:ssl_verify_callback).to_proc if Puppet[:debug]
end
def self.ssl_verify_callback(peer_ok, x509_store_ctx)
diff --git a/lib/puppet/network/http_server/mongrel.rb b/lib/puppet/network/http_server/mongrel.rb
index b26eee602..23ab40bb0 100644
--- a/lib/puppet/network/http_server/mongrel.rb
+++ b/lib/puppet/network/http_server/mongrel.rb
@@ -75,27 +75,27 @@ module Puppet::Network
def process(request, response)
# Make sure this has been a POST as required for XMLRPC.
request_method = request.params[Mongrel::Const::REQUEST_METHOD] || Mongrel::Const::GET
- if request_method != "POST" then
+ if request_method != "POST"
response.start(405) { |head, out| out.write("Method Not Allowed") }
return
end
# Make sure the user has sent text/xml data.
request_mime = request.params["CONTENT_TYPE"] || "text/plain"
- if parse_content_type(request_mime).first != "text/xml" then
+ if parse_content_type(request_mime).first != "text/xml"
response.start(400) { |head, out| out.write("Bad Request") }
return
end
# Make sure there is data in the body at all.
length = request.params[Mongrel::Const::CONTENT_LENGTH].to_i
- if length <= 0 then
+ if length <= 0
response.start(411) { |head, out| out.write("Length Required") }
return
end
# Check the body to be valid.
- if request.body.nil? or request.body.size != length then
+ if request.body.nil? or request.body.size != length
response.start(400) { |head, out| out.write("Bad Request") }
return
end
diff --git a/lib/puppet/network/http_server/webrick.rb b/lib/puppet/network/http_server/webrick.rb
index 6cf5c91fe..df7a87bf2 100644
--- a/lib/puppet/network/http_server/webrick.rb
+++ b/lib/puppet/network/http_server/webrick.rb
@@ -29,9 +29,7 @@ module Puppet
store = OpenSSL::X509::Store.new
store.purpose = OpenSSL::X509::PURPOSE_ANY
store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL|OpenSSL::X509::V_FLAG_CRL_CHECK if Puppet.settings[:certificate_revocation]
- unless self.ca_cert
- raise Puppet::Error, "Could not find CA certificate"
- end
+ raise Puppet::Error, "Could not find CA certificate" unless self.ca_cert
store.add_file(Puppet[:localcacert])
store.add_crl(crl)
@@ -57,9 +55,7 @@ module Puppet
file_io.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
args << file_io
- if Puppet[:debug]
- args << WEBrick::Log::DEBUG
- end
+ args << WEBrick::Log::DEBUG if Puppet[:debug]
log = WEBrick::Log.new(*args)
@@ -115,16 +111,12 @@ module Puppet
# Create a ca client to set up our cert for us.
def request_cert(ca)
client = Puppet::Network::Client.ca.new(:CA => ca)
- unless client.request_cert
- raise Puppet::Error, "Could get certificate"
- end
+ raise Puppet::Error, "Could get certificate" unless client.request_cert
end
# Create all of our handler instances.
def setup_handlers(handlers)
- unless handlers.is_a?(Hash)
- raise ServerError, "Handlers must have arguments"
- end
+ raise ServerError, "Handlers must have arguments" unless handlers.is_a?(Hash)
handlers.collect { |handler, args|
hclass = nil
diff --git a/lib/puppet/network/rest_authorization.rb b/lib/puppet/network/rest_authorization.rb
index 0cf4472f1..3c7c98a21 100644
--- a/lib/puppet/network/rest_authorization.rb
+++ b/lib/puppet/network/rest_authorization.rb
@@ -9,9 +9,7 @@ module Puppet::Network
# Create our config object if necessary. If there's no configuration file
# we install our defaults
def authconfig
- unless defined?(@authconfig)
- @authconfig = Puppet::Network::RestAuthConfig.main
- end
+ @authconfig = Puppet::Network::RestAuthConfig.main unless defined?(@authconfig)
@authconfig
end
diff --git a/lib/puppet/network/rights.rb b/lib/puppet/network/rights.rb
index 57f90727a..509a9231b 100755
--- a/lib/puppet/network/rights.rb
+++ b/lib/puppet/network/rights.rb
@@ -197,27 +197,21 @@ class Rights
def restrict_method(m)
m = m.intern if m.is_a?(String)
- unless ALL.include?(m)
- raise ArgumentError, "'#{m}' is not an allowed value for method directive"
- end
+ raise ArgumentError, "'#{m}' is not an allowed value for method directive" unless ALL.include?(m)
# if we were allowing all methods, then starts from scratch
if @methods === ALL
@methods = []
end
- if @methods.include?(m)
- raise ArgumentError, "'#{m}' is already in the '#{name}' ACL"
- end
+ raise ArgumentError, "'#{m}' is already in the '#{name}' ACL" if @methods.include?(m)
@methods << m
end
def restrict_environment(env)
env = Puppet::Node::Environment.new(env)
- if @environment.include?(env)
- raise ArgumentError, "'#{env}' is already in the '#{name}' ACL"
- end
+ raise ArgumentError, "'#{env}' is already in the '#{name}' ACL" if @environment.include?(env)
@environment << env
end
@@ -255,9 +249,7 @@ class Rights
# * regex path rights are then all queued in file order
def <=>(rhs)
# move namespace rights at front
- if self.acl_type != rhs.acl_type
- return self.acl_type == :name ? -1 : 1
- end
+ return self.acl_type == :name ? -1 : 1 if self.acl_type != rhs.acl_type
# sort by creation order (ie first match appearing in the file will win)
# that is don't sort, in which case the sort algorithm will order in the
diff --git a/lib/puppet/network/server.rb b/lib/puppet/network/server.rb
index eb22e1614..dfc7e1008 100644
--- a/lib/puppet/network/server.rb
+++ b/lib/puppet/network/server.rb
@@ -33,9 +33,7 @@ class Puppet::Network::Server
# don't try to start.
def create_pidfile
Puppet::Util.sync(Puppet[:name]).synchronize(Sync::EX) do
- unless Puppet::Util::Pidlock.new(pidfile).lock
- raise "Could not create PID file: #{pidfile}"
- end
+ raise "Could not create PID file: #{pidfile}" unless Puppet::Util::Pidlock.new(pidfile).lock
end
end
@@ -43,9 +41,7 @@ class Puppet::Network::Server
def remove_pidfile
Puppet::Util.sync(Puppet[:name]).synchronize(Sync::EX) do
locker = Puppet::Util::Pidlock.new(pidfile)
- if locker.locked?
- locker.unlock or Puppet.err "Could not remove PID file #{pidfile}"
- end
+ locker.unlock or Puppet.err "Could not remove PID file #{pidfile}" if locker.locked?
end
end
diff --git a/lib/puppet/network/xmlrpc/client.rb b/lib/puppet/network/xmlrpc/client.rb
index 828b8a77a..86b1fbd0b 100644
--- a/lib/puppet/network/xmlrpc/client.rb
+++ b/lib/puppet/network/xmlrpc/client.rb
@@ -79,9 +79,7 @@ module Puppet::Network
return :retry
end
["certificate verify failed", "hostname was not match", "hostname not match"].each do |str|
- if detail.message.include?(str)
- Puppet.warning "Certificate validation failed; consider using the certname configuration option"
- end
+ Puppet.warning "Certificate validation failed; consider using the certname configuration option" if detail.message.include?(str)
end
raise XMLRPCClientError, "Certificates were not trusted: #{detail}"
end
@@ -104,9 +102,7 @@ module Puppet::Network
return :retry
end
["certificate verify failed", "hostname was not match", "hostname not match"].each do |str|
- if detail.message.include?(str)
- Puppet.warning "Certificate validation failed; consider using the certname configuration option"
- end
+ Puppet.warning "Certificate validation failed; consider using the certname configuration option" if detail.message.include?(str)
end
raise XMLRPCClientError, "Certificates were not trusted: #{detail}"
end
@@ -154,9 +150,7 @@ module Puppet::Network
end
def http
- unless @http
- @http = Puppet::Network::HttpPool.http_instance(host, port, true)
- end
+ @http = Puppet::Network::HttpPool.http_instance(host, port, true) unless @http
@http
end
@@ -196,9 +190,7 @@ module Puppet::Network
# or we've just downloaded certs and we need to create new http instances
# with the certs added.
def recycle_connection
- if http.started?
- http.finish
- end
+ http.finish if http.started?
@http = nil
self.http # force a new one
end
diff --git a/lib/puppet/network/xmlrpc/processor.rb b/lib/puppet/network/xmlrpc/processor.rb
index 14f91d8b4..e016b177b 100644
--- a/lib/puppet/network/xmlrpc/processor.rb
+++ b/lib/puppet/network/xmlrpc/processor.rb
@@ -58,9 +58,7 @@ module Puppet::Network
1, detail.to_s
)
rescue Puppet::Error => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err detail.to_s
error = ::XMLRPC::FaultException.new(
1, detail.to_s
@@ -68,9 +66,7 @@ module Puppet::Network
error.set_backtrace detail.backtrace
raise error
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not call: #{detail}"
error = ::XMLRPC::FaultException.new(1, detail.to_s)
error.set_backtrace detail.backtrace
diff --git a/lib/puppet/network/xmlrpc/webrick_servlet.rb b/lib/puppet/network/xmlrpc/webrick_servlet.rb
index f58286c3a..a3022dbe9 100644
--- a/lib/puppet/network/xmlrpc/webrick_servlet.rb
+++ b/lib/puppet/network/xmlrpc/webrick_servlet.rb
@@ -10,9 +10,7 @@ module Puppet::Network::XMLRPC
# This is a hackish way to avoid an auth message every time we have a
# normal operation
def self.log(msg)
- unless defined?(@logs)
- @logs = {}
- end
+ @logs = {} unless defined?(@logs)
if @logs.include?(msg)
@logs[msg] += 1
else
@@ -51,9 +49,7 @@ module Puppet::Network::XMLRPC
"unsupported method `#{request.request_method}'."
end
- if parse_content_type(request['Content-type']).first != "text/xml"
- raise WEBrick::HTTPStatus::BadRequest
- end
+ raise WEBrick::HTTPStatus::BadRequest if parse_content_type(request['Content-type']).first != "text/xml"
length = (request['Content-length'] || 0).to_i
@@ -61,14 +57,10 @@ module Puppet::Network::XMLRPC
data = request.body
- if data.nil? or data.size != length
- raise WEBrick::HTTPStatus::BadRequest
- end
+ raise WEBrick::HTTPStatus::BadRequest if data.nil? or data.size != length
resp = process(data, client_request(request))
- if resp.nil? or resp.size <= 0
- raise WEBrick::HTTPStatus::InternalServerError
- end
+ raise WEBrick::HTTPStatus::InternalServerError if resp.nil? or resp.size <= 0
response.status = 200
response['Content-Length'] = resp.size
diff --git a/lib/puppet/node.rb b/lib/puppet/node.rb
index 2418b3e44..47be43168 100644
--- a/lib/puppet/node.rb
+++ b/lib/puppet/node.rb
@@ -32,9 +32,7 @@ class Puppet::Node
end
def initialize(name, options = {})
- unless name
- raise ArgumentError, "Node names cannot be nil"
- end
+ raise ArgumentError, "Node names cannot be nil" unless name
@name = name
if classes = options[:classes]
@@ -81,15 +79,11 @@ class Puppet::Node
# Calculate the list of names we might use for looking
# up our node. This is only used for AST nodes.
def names
- if Puppet.settings[:strict_hostname_checking]
- return [name]
- end
+ return [name] if Puppet.settings[:strict_hostname_checking]
names = []
- if name.include?(".")
- names += split_name(name)
- end
+ names += split_name(name) if name.include?(".")
# First, get the fqdn
unless fqdn = parameters["fqdn"]
@@ -102,9 +96,7 @@ class Puppet::Node
# Now that we (might) have the fqdn, add each piece to the name
# list to search, in order of longest to shortest.
- if fqdn
- names += split_name(fqdn)
- end
+ names += split_name(fqdn) if fqdn
# And make sure the node name is first, since that's the most
# likely usage.
diff --git a/lib/puppet/node/environment.rb b/lib/puppet/node/environment.rb
index 8d4b20611..97dcc89e6 100644
--- a/lib/puppet/node/environment.rb
+++ b/lib/puppet/node/environment.rb
@@ -87,9 +87,7 @@ class Puppet::Node::Environment
# all known directories all the time.
cached_attr(:modulepath, :ttl => Puppet[:filetimeout]) do
dirs = self[:modulepath].split(File::PATH_SEPARATOR)
- if ENV["PUPPETLIB"]
- dirs = ENV["PUPPETLIB"].split(File::PATH_SEPARATOR) + dirs
- end
+ dirs = ENV["PUPPETLIB"].split(File::PATH_SEPARATOR) + dirs if ENV["PUPPETLIB"]
validate_dirs(dirs)
end
diff --git a/lib/puppet/parameter.rb b/lib/puppet/parameter.rb
index 82b603a57..5b9ecf5ba 100644
--- a/lib/puppet/parameter.rb
+++ b/lib/puppet/parameter.rb
@@ -53,9 +53,7 @@ class Puppet::Parameter
end
def nodefault
- if public_method_defined? :default
- undef_method :default
- end
+ undef_method :default if public_method_defined? :default
end
# Store documentation for this parameter.
@@ -174,13 +172,9 @@ class Puppet::Parameter
error = type.new(args.join(" "))
- if defined?(@resource) and @resource and @resource.line
- error.line = @resource.line
- end
+ error.line = @resource.line if defined?(@resource) and @resource and @resource.line
- if defined?(@resource) and @resource and @resource.file
- error.file = @resource.file
- end
+ error.file = @resource.file if defined?(@resource) and @resource and @resource.file
raise error
end
@@ -217,9 +211,7 @@ class Puppet::Parameter
# for testing whether we should actually do anything
def noop
- unless defined?(@noop)
- @noop = false
- end
+ @noop = false unless defined?(@noop)
tmp = @noop || self.resource.noop || Puppet[:noop] || false
#debug "noop is #{tmp}"
return tmp
@@ -306,9 +298,7 @@ class Puppet::Parameter
unless defined?(@tags)
@tags = []
# This might not be true in testing
- if @resource.respond_to? :tags
- @tags = @resource.tags
- end
+ @tags = @resource.tags if @resource.respond_to? :tags
@tags << self.name.to_s
end
@tags
diff --git a/lib/puppet/parameter/value_collection.rb b/lib/puppet/parameter/value_collection.rb
index 840b892f1..eabeb30f1 100644
--- a/lib/puppet/parameter/value_collection.rb
+++ b/lib/puppet/parameter/value_collection.rb
@@ -28,9 +28,7 @@ class Puppet::Parameter::ValueCollection
end.join(", ") + "."
end
- unless regexes.empty?
- @doc += " Values can match ``" + regexes.join("``, ``") + "``."
- end
+ @doc += " Values can match ``" + regexes.join("``, ``") + "``." unless regexes.empty?
end
@doc
@@ -104,9 +102,7 @@ class Puppet::Parameter::ValueCollection
value.call = options[:call] || :none
end
- if block_given? and ! value.regex?
- value.method ||= "set_#{value.name}"
- end
+ value.method ||= "set_#{value.name}" if block_given? and ! value.regex?
value
end
@@ -127,13 +123,9 @@ class Puppet::Parameter::ValueCollection
unless @values.detect { |name, v| v.match?(value) }
str = "Invalid value #{value.inspect}. "
- unless values.empty?
- str += "Valid values are #{values.join(", ")}. "
- end
+ str += "Valid values are #{values.join(", ")}. " unless values.empty?
- unless regexes.empty?
- str += "Valid values match #{regexes.join(", ")}."
- end
+ str += "Valid values match #{regexes.join(", ")}." unless regexes.empty?
raise ArgumentError, str
end
diff --git a/lib/puppet/parser/ast/arithmetic_operator.rb b/lib/puppet/parser/ast/arithmetic_operator.rb
index b4c0215cc..6b9a6018c 100644
--- a/lib/puppet/parser/ast/arithmetic_operator.rb
+++ b/lib/puppet/parser/ast/arithmetic_operator.rb
@@ -33,9 +33,7 @@ class Puppet::Parser::AST
def initialize(hash)
super
- unless %w{+ - * / << >>}.include?(@operator)
- raise ArgumentError, "Invalid arithmetic operator #{@operator}"
- end
+ raise ArgumentError, "Invalid arithmetic operator #{@operator}" unless %w{+ - * / << >>}.include?(@operator)
end
end
end
diff --git a/lib/puppet/parser/ast/boolean_operator.rb b/lib/puppet/parser/ast/boolean_operator.rb
index 9214afbd5..0f7e21d2c 100644
--- a/lib/puppet/parser/ast/boolean_operator.rb
+++ b/lib/puppet/parser/ast/boolean_operator.rb
@@ -40,9 +40,7 @@ class Puppet::Parser::AST
def initialize(hash)
super
- unless %w{and or}.include?(@operator)
- raise ArgumentError, "Invalid boolean operator #{@operator}"
- end
+ raise ArgumentError, "Invalid boolean operator #{@operator}" unless %w{and or}.include?(@operator)
end
end
end
diff --git a/lib/puppet/parser/ast/branch.rb b/lib/puppet/parser/ast/branch.rb
index c0fa0da30..0be6ca018 100644
--- a/lib/puppet/parser/ast/branch.rb
+++ b/lib/puppet/parser/ast/branch.rb
@@ -23,9 +23,7 @@ class Puppet::Parser::AST
super(arghash)
# Create the hash, if it was not set at initialization time.
- unless defined?(@children)
- @children = []
- end
+ @children = [] unless defined?(@children)
# Verify that we only got valid AST nodes.
@children.each { |child|
diff --git a/lib/puppet/parser/ast/caseopt.rb b/lib/puppet/parser/ast/caseopt.rb
index 51a82c5c0..1268aa7b9 100644
--- a/lib/puppet/parser/ast/caseopt.rb
+++ b/lib/puppet/parser/ast/caseopt.rb
@@ -16,9 +16,7 @@ class Puppet::Parser::AST
# Are we the default option?
def default?
# Cache the @default value.
- if defined?(@default)
- return @default
- end
+ return @default if defined?(@default)
if @value.is_a?(AST::ASTArray)
@value.each { |subval|
@@ -28,14 +26,10 @@ class Puppet::Parser::AST
end
}
else
- if @value.is_a?(AST::Default)
- @default = true
- end
+ @default = true if @value.is_a?(AST::Default)
end
- unless defined?(@default)
- @default = false
- end
+ @default = false unless defined?(@default)
return @default
end
diff --git a/lib/puppet/parser/ast/collexpr.rb b/lib/puppet/parser/ast/collexpr.rb
index 95fb5a94f..f71b53d46 100644
--- a/lib/puppet/parser/ast/collexpr.rb
+++ b/lib/puppet/parser/ast/collexpr.rb
@@ -80,9 +80,7 @@ class CollExpr < AST::Branch
def initialize(hash = {})
super
- unless %w{== != and or}.include?(@oper)
- raise ArgumentError, "Invalid operator #{@oper}"
- end
+ raise ArgumentError, "Invalid operator #{@oper}" unless %w{== != and or}.include?(@oper)
end
end
end
diff --git a/lib/puppet/parser/ast/comparison_operator.rb b/lib/puppet/parser/ast/comparison_operator.rb
index 85903ec31..e8b21d45f 100644
--- a/lib/puppet/parser/ast/comparison_operator.rb
+++ b/lib/puppet/parser/ast/comparison_operator.rb
@@ -33,9 +33,7 @@ class Puppet::Parser::AST
def initialize(hash)
super
- unless %w{== != < > <= >=}.include?(@operator)
- raise ArgumentError, "Invalid comparison operator #{@operator}"
- end
+ raise ArgumentError, "Invalid comparison operator #{@operator}" unless %w{== != < > <= >=}.include?(@operator)
end
end
end
diff --git a/lib/puppet/parser/ast/function.rb b/lib/puppet/parser/ast/function.rb
index c3769cbd4..79d3d95ed 100644
--- a/lib/puppet/parser/ast/function.rb
+++ b/lib/puppet/parser/ast/function.rb
@@ -13,16 +13,12 @@ class Puppet::Parser::AST
def evaluate(scope)
# Make sure it's a defined function
- unless Puppet::Parser::Functions.function(@name)
- raise Puppet::ParseError, "Unknown function #{@name}"
- end
+ raise Puppet::ParseError, "Unknown function #{@name}" unless Puppet::Parser::Functions.function(@name)
# Now check that it's been used correctly
case @ftype
when :rvalue
- unless Puppet::Parser::Functions.rvalue?(@name)
- raise Puppet::ParseError, "Function '#{@name}' does not return a value"
- end
+ raise Puppet::ParseError, "Function '#{@name}' does not return a value" unless Puppet::Parser::Functions.rvalue?(@name)
when :statement
if Puppet::Parser::Functions.rvalue?(@name)
raise Puppet::ParseError,
diff --git a/lib/puppet/parser/ast/in_operator.rb b/lib/puppet/parser/ast/in_operator.rb
index 0f543af9b..05f864edc 100644
--- a/lib/puppet/parser/ast/in_operator.rb
+++ b/lib/puppet/parser/ast/in_operator.rb
@@ -12,9 +12,7 @@ class Puppet::Parser::AST
# evaluate the operands, should return a boolean value
lval = @lval.safeevaluate(scope)
- unless lval.is_a?(::String)
- raise ArgumentError, "'#{lval}' from left operand of 'in' expression is not a string"
- end
+ raise ArgumentError, "'#{lval}' from left operand of 'in' expression is not a string" unless lval.is_a?(::String)
rval = @rval.safeevaluate(scope)
unless rval.respond_to?(:include?)
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 6ef346123..666edd66a 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -162,9 +162,7 @@ class Puppet::Parser::AST
def evaluate(scope)
object = evaluate_container(scope)
- unless object.is_a?(Hash) or object.is_a?(Array)
- raise Puppet::ParseError, "#{variable} is not an hash or array when accessing it with #{accesskey}"
- end
+ raise Puppet::ParseError, "#{variable} is not an hash or array when accessing it with #{accesskey}" unless object.is_a?(Hash) or object.is_a?(Array)
return object[evaluate_key(scope)]
end
diff --git a/lib/puppet/parser/ast/match_operator.rb b/lib/puppet/parser/ast/match_operator.rb
index c528a90e5..9a12351b9 100644
--- a/lib/puppet/parser/ast/match_operator.rb
+++ b/lib/puppet/parser/ast/match_operator.rb
@@ -23,9 +23,7 @@ class Puppet::Parser::AST
def initialize(hash)
super
- unless %w{!~ =~}.include?(@operator)
- raise ArgumentError, "Invalid regexp operator #{@operator}"
- end
+ raise ArgumentError, "Invalid regexp operator #{@operator}" unless %w{!~ =~}.include?(@operator)
end
end
end
diff --git a/lib/puppet/parser/ast/resource.rb b/lib/puppet/parser/ast/resource.rb
index 5aa11129a..01b9370ff 100644
--- a/lib/puppet/parser/ast/resource.rb
+++ b/lib/puppet/parser/ast/resource.rb
@@ -21,9 +21,7 @@ class Resource < AST::ResourceReference
resource_titles = @title.safeevaluate(scope)
# it's easier to always use an array, even for only one name
- unless resource_titles.is_a?(Array)
- resource_titles = [resource_titles]
- end
+ resource_titles = [resource_titles] unless resource_titles.is_a?(Array)
# We want virtual to be true if exported is true. We can't
# just set :virtual => self.virtual in the initialization,
diff --git a/lib/puppet/parser/ast/selector.rb b/lib/puppet/parser/ast/selector.rb
index 8eb930cc4..cf6b8ac19 100644
--- a/lib/puppet/parser/ast/selector.rb
+++ b/lib/puppet/parser/ast/selector.rb
@@ -18,9 +18,7 @@ class Puppet::Parser::AST
default = nil
- unless @values.instance_of? AST::ASTArray or @values.instance_of? Array
- @values = [@values]
- end
+ @values = [@values] unless @values.instance_of? AST::ASTArray or @values.instance_of? Array
# Then look for a match in the options.
@values.each do |obj|
diff --git a/lib/puppet/parser/collector.rb b/lib/puppet/parser/collector.rb
index 3f1432af2..d2b993017 100644
--- a/lib/puppet/parser/collector.rb
+++ b/lib/puppet/parser/collector.rb
@@ -24,9 +24,7 @@ class Puppet::Parser::Collector
objects = send(method).each do |obj|
obj.virtual = false
end
- if objects.empty?
- return false
- end
+ return false if objects.empty?
end
# we have an override for the collected resources
@@ -86,9 +84,7 @@ class Puppet::Parser::Collector
# add a resource override to the soon to be exported/realized resources
def add_override(hash)
- unless hash[:parameters]
- raise ArgumentError, "Exported resource try to override without parameters"
- end
+ raise ArgumentError, "Exported resource try to override without parameters" unless hash[:parameters]
# schedule an override for an upcoming collection
@overrides = hash
@@ -160,9 +156,7 @@ class Puppet::Parser::Collector
end
def collect_resources
- unless @resources.is_a?(Array)
- @resources = [@resources]
- end
+ @resources = [@resources] unless @resources.is_a?(Array)
method = "collect_#{form.to_s}_resources"
send(method)
end
@@ -186,9 +180,7 @@ class Puppet::Parser::Collector
# If there are no more resources to find, delete this from the list
# of collections.
- if @resources.empty?
- @scope.compiler.delete_collection(self)
- end
+ @scope.compiler.delete_collection(self) if @resources.empty?
return result
end
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb
index a2186b2c9..121dae1b1 100644
--- a/lib/puppet/parser/compiler.rb
+++ b/lib/puppet/parser/compiler.rb
@@ -61,9 +61,7 @@ class Puppet::Parser::Compiler
return if resource.type.to_s.downcase == "stage"
if resource.type.to_s.downcase != "class"
- if resource[:stage]
- raise ArgumentError, "Only classes can set 'stage'; normal resources like #{resource} cannot change run stage"
- end
+ raise ArgumentError, "Only classes can set 'stage'; normal resources like #{resource} cannot change run stage" if resource[:stage]
return @catalog.add_edge(scope.resource, resource)
end
@@ -142,9 +140,7 @@ class Puppet::Parser::Compiler
# creates resource objects that point back to the classes, and then the
# resources are themselves evaluated later in the process.
def evaluate_classes(classes, scope, lazy_evaluate = true)
- unless scope.source
- raise Puppet::DevError, "No source for scope passed to evaluate_classes"
- end
+ raise Puppet::DevError, "No source for scope passed to evaluate_classes" unless scope.source
found = []
classes.each do |name|
# If we can find the class, then make a resource that will evaluate it.
@@ -354,9 +350,7 @@ class Puppet::Parser::Compiler
end
end
- unless remaining.empty?
- raise Puppet::ParseError, "Failed to realize virtual resources #{remaining.join(', ')}"
- end
+ raise Puppet::ParseError, "Failed to realize virtual resources #{remaining.join(', ')}" unless remaining.empty?
end
# Make sure all of our resources and such have done any last work
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb
index 5b07a9c09..c86548bfb 100644
--- a/lib/puppet/parser/functions.rb
+++ b/lib/puppet/parser/functions.rb
@@ -40,9 +40,7 @@ module Puppet::Parser::Functions
def self.newfunction(name, options = {}, &block)
name = symbolize(name)
- if functions.include?(name)
- raise Puppet::DevError, "Function #{name} already defined"
- end
+ raise Puppet::DevError, "Function #{name} already defined" if functions.include?(name)
ftype = options[:type] || :statement
@@ -56,18 +54,14 @@ module Puppet::Parser::Functions
# Someday we'll support specifying an arity, but for now, nope
#functions[name] = {:arity => arity, :type => ftype}
functions[name] = {:type => ftype, :name => fname}
- if options[:doc]
- functions[name][:doc] = options[:doc]
- end
+ functions[name][:doc] = options[:doc] if options[:doc]
end
# Remove a function added by newfunction
def self.rmfunction(name)
name = symbolize(name)
- unless functions.include? name
- raise Puppet::DevError, "Function #{name} is not defined"
- end
+ raise Puppet::DevError, "Function #{name} is not defined" unless functions.include? name
functions.delete name
diff --git a/lib/puppet/parser/functions/generate.rb b/lib/puppet/parser/functions/generate.rb
index cf46775ab..8430f03a6 100644
--- a/lib/puppet/parser/functions/generate.rb
+++ b/lib/puppet/parser/functions/generate.rb
@@ -11,9 +11,7 @@ Puppet::Parser::Functions::newfunction(:generate, :type => :rvalue,
generators, so all shell metacharacters are passed directly to
the generator.") do |args|
- unless args[0] =~ /^#{File::SEPARATOR}/
- raise Puppet::ParseError, "Generators must be fully qualified"
- end
+ raise Puppet::ParseError, "Generators must be fully qualified" unless args[0] =~ /^#{File::SEPARATOR}/
unless args[0] =~ /^[-#{File::SEPARATOR}\w.]+$/
raise Puppet::ParseError,
diff --git a/lib/puppet/parser/functions/include.rb b/lib/puppet/parser/functions/include.rb
index a8b6f175b..d1bafa54a 100644
--- a/lib/puppet/parser/functions/include.rb
+++ b/lib/puppet/parser/functions/include.rb
@@ -12,9 +12,7 @@ Puppet::Parser::Functions::newfunction(:include, :doc => "Evaluate one or more c
unless missing.empty?
# Throw an error if we didn't evaluate all of the classes.
str = "Could not find class"
- if missing.length > 1
- str += "es"
- end
+ str += "es" if missing.length > 1
str += " " + missing.join(", ")
diff --git a/lib/puppet/parser/functions/shellquote.rb b/lib/puppet/parser/functions/shellquote.rb
index 0a7ae5958..96feaa1ee 100644
--- a/lib/puppet/parser/functions/shellquote.rb
+++ b/lib/puppet/parser/functions/shellquote.rb
@@ -26,9 +26,7 @@ module Puppet::Parser::Functions
else
r = '"'
word.each_byte() do |c|
- if Dangerous.include?(c)
- r += "\\"
- end
+ r += "\\" if Dangerous.include?(c)
r += c.chr()
end
r += '"'
diff --git a/lib/puppet/parser/functions/split.rb b/lib/puppet/parser/functions/split.rb
index c3466ba4a..09caa18aa 100644
--- a/lib/puppet/parser/functions/split.rb
+++ b/lib/puppet/parser/functions/split.rb
@@ -22,9 +22,7 @@ a regexp meta-character (.), and that needs protection. A simple
way to do that for a single character is to enclose it in square
brackets.") do |args|
- if args.length != 2
- raise Puppet::ParseError, ("split(): wrong number of arguments (#{args.length}; must be 2)")
- end
+ raise Puppet::ParseError, ("split(): wrong number of arguments (#{args.length}; must be 2)") if args.length != 2
return args[0].split(Regexp.compile(args[1]))
end
diff --git a/lib/puppet/parser/functions/sprintf.rb b/lib/puppet/parser/functions/sprintf.rb
index 4a53a9736..4a3916c89 100644
--- a/lib/puppet/parser/functions/sprintf.rb
+++ b/lib/puppet/parser/functions/sprintf.rb
@@ -6,9 +6,7 @@ module Puppet::Parser::Functions
:doc => "Perform printf-style formatting of text.
The first parameter is format string describing how the rest of the parameters should be formatted. See the documentation for the ``Kernel::sprintf()`` function in Ruby for all the details.") do |args|
- if args.length < 1
- raise Puppet::ParseError, 'sprintf() needs at least one argument'
- end
+ raise Puppet::ParseError, 'sprintf() needs at least one argument' if args.length < 1
fmt = args.shift()
return sprintf(fmt, *args)
end
diff --git a/lib/puppet/parser/grammar.ra b/lib/puppet/parser/grammar.ra
index c08b1a31a..9fa8f5069 100644
--- a/lib/puppet/parser/grammar.ra
+++ b/lib/puppet/parser/grammar.ra
@@ -153,16 +153,12 @@ namestring: name
resource: classname LBRACE resourceinstances endsemi RBRACE {
@lexer.commentpop
array = val[2]
- if array.instance_of?(AST::ResourceInstance)
- array = [array]
- end
+ array = [array] if array.instance_of?(AST::ResourceInstance)
result = ast AST::ASTArray
# this iterates across each specified resourceinstance
array.each { |instance|
- unless instance.instance_of?(AST::ResourceInstance)
- raise Puppet::Dev, "Got something that isn't an instance"
- end
+ raise Puppet::Dev, "Got something that isn't an instance" unless instance.instance_of?(AST::ResourceInstance)
# now, i need to somehow differentiate between those things with
# arrays in their names, and normal things
@@ -197,9 +193,7 @@ virtualresource: at resource {
Puppet.warning addcontext("You cannot collect without storeconfigs being set")
end
- if val[1].is_a? AST::ResourceDefaults
- error "Defaults are not virtualizable"
- end
+ error "Defaults are not virtualizable" if val[1].is_a? AST::ResourceDefaults
method = type.to_s + "="
@@ -222,9 +216,7 @@ at: AT { result = :virtual }
# will, I assume.
collection: classref collectrhand LBRACE anyparams endcomma RBRACE {
@lexer.commentpop
- if val[0] =~ /^[a-z]/
- Puppet.warning addcontext("Collection names must now be capitalized")
- end
+ Puppet.warning addcontext("Collection names must now be capitalized") if val[0] =~ /^[a-z]/
type = val[0].downcase
args = {:type => type}
@@ -348,9 +340,7 @@ resourcename: quotedtext
| hasharrayaccesses
assignment: VARIABLE EQUALS expression {
- if val[0][:value] =~ /::/
- raise Puppet::ParseError, "Cannot assign to variables in other namespaces"
- end
+ raise Puppet::ParseError, "Cannot assign to variables in other namespaces" if val[0][:value] =~ /::/
# this is distinct from referencing a variable
variable = ast AST::Name, :value => val[0][:value], :line => val[0][:line]
result = ast AST::VarDef, :name => variable, :value => val[2], :line => val[0][:line]
@@ -477,9 +467,7 @@ ifstatement: expression LBRACE statements RBRACE else {
:statements => val[2]
}
- if val[4]
- args[:else] = val[4]
- end
+ args[:else] = val[4] if val[4]
result = ast AST::IfStatement, args
}
@@ -490,9 +478,7 @@ ifstatement: expression LBRACE statements RBRACE else {
:statements => ast(AST::Nop)
}
- if val[3]
- args[:else] = val[3]
- end
+ args[:else] = val[3] if val[3]
result = ast AST::IfStatement, args
}
@@ -587,9 +573,7 @@ expression: rvalue
casestatement: CASE rvalue LBRACE caseopts RBRACE {
@lexer.commentpop
options = val[3]
- unless options.instance_of?(AST::ASTArray)
- options = ast AST::ASTArray, :children => [val[3]]
- end
+ options = ast AST::ASTArray, :children => [val[3]] unless options.instance_of?(AST::ASTArray)
result = ast AST::CaseStatement, :test => val[1], :options => options
}
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index f2fd710cf..e63483050 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -74,9 +74,7 @@ class Puppet::Parser::Parser
end
except = Puppet::ParseError.new(message)
except.line = @lexer.line
- if @lexer.file
- except.file = @lexer.file
- end
+ except.file = @lexer.file if @lexer.file
raise except
end
@@ -90,9 +88,7 @@ class Puppet::Parser::Parser
unless file =~ /\.pp$/
file = file + ".pp"
end
- unless FileTest.exist?(file)
- raise Puppet::Error, "Could not find file #{file}"
- end
+ raise Puppet::Error, "Could not find file #{file}" unless FileTest.exist?(file)
end
raise Puppet::AlreadyImportedError, "Import loop detected" if known_resource_types.watching_file?(file)
@@ -171,9 +167,7 @@ class Puppet::Parser::Parser
except = Puppet::ParseError.new(error)
except.line = @lexer.line
- if @lexer.file
- except.file = @lexer.file
- end
+ except.file = @lexer.file if @lexer.file
raise except
end
@@ -181,9 +175,7 @@ class Puppet::Parser::Parser
# how should I do error handling here?
def parse(string = nil)
return parse_ruby_file if self.file =~ /\.rb$/
- if string
- self.string = string
- end
+ self.string = string if string
begin
@yydebug = false
main = yyparse(@lexer,:scan)
diff --git a/lib/puppet/parser/resource.rb b/lib/puppet/parser/resource.rb
index 257440ab4..e29beeb95 100644
--- a/lib/puppet/parser/resource.rb
+++ b/lib/puppet/parser/resource.rb
@@ -27,9 +27,7 @@ class Puppet::Parser::Resource < Puppet::Resource
# Determine whether the provided parameter name is a relationship parameter.
def self.relationship_parameter?(name)
- unless defined?(@relationship_names)
- @relationship_names = Puppet::Type.relationship_params.collect { |p| p.name }
- end
+ @relationship_names = Puppet::Type.relationship_params.collect { |p| p.name } unless defined?(@relationship_names)
@relationship_names.include?(name)
end
@@ -110,9 +108,7 @@ class Puppet::Parser::Resource < Puppet::Resource
def initialize(*args)
super
- unless scope
- raise ArgumentError, "Resources require a scope"
- end
+ raise ArgumentError, "Resources require a scope" unless scope
@source ||= scope.source
end
@@ -179,9 +175,7 @@ class Puppet::Parser::Resource < Puppet::Resource
@parameters.inject({}) do |hash, ary|
param = ary[1]
# Skip "undef" values.
- if param.value != :undef
- hash[param.name] = param.value
- end
+ hash[param.name] = param.value if param.value != :undef
hash
end
end
@@ -198,13 +192,9 @@ class Puppet::Parser::Resource < Puppet::Resource
v = Puppet::Resource.new(v.type, v.title)
elsif v.is_a?(Array)
# flatten resource references arrays
- if v.flatten.find { |av| av.is_a?(Puppet::Resource) }
- v = v.flatten
- end
+ v = v.flatten if v.flatten.find { |av| av.is_a?(Puppet::Resource) }
v = v.collect do |av|
- if av.is_a?(Puppet::Resource)
- av = Puppet::Resource.new(av.type, av.title)
- end
+ av = Puppet::Resource.new(av.type, av.title) if av.is_a?(Puppet::Resource)
av
end
end
@@ -287,9 +277,7 @@ class Puppet::Parser::Resource < Puppet::Resource
unless param.source.child_of?(current.source)
puts caller if Puppet[:trace]
msg = "Parameter '#{param.name}' is already set on #{self}"
- if current.source.to_s != ""
- msg += " by #{current.source}"
- end
+ msg += " by #{current.source}" if current.source.to_s != ""
if current.file or current.line
fields = []
fields << current.file if current.file
@@ -330,9 +318,7 @@ class Puppet::Parser::Resource < Puppet::Resource
def extract_parameters(params)
params.each do |param|
# Don't set the same parameter twice
- if @parameters[param.name]
- self.fail Puppet::ParseError, "Duplicate parameter '#{param.name}' for on #{self}"
- end
+ self.fail Puppet::ParseError, "Duplicate parameter '#{param.name}' for on #{self}" if @parameters[param.name]
set_parameter(param)
end
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb
index 02dd3e733..5a0dbfeba 100644
--- a/lib/puppet/parser/scope.rb
+++ b/lib/puppet/parser/scope.rb
@@ -74,9 +74,7 @@ class Puppet::Parser::Scope
# Is the value a number?, return the correct object or nil if not a number
def self.number?(value)
- unless value.is_a?(Fixnum) or value.is_a?(Bignum) or value.is_a?(Float) or value.is_a?(String)
- return nil
- end
+ return nil unless value.is_a?(Fixnum) or value.is_a?(Bignum) or value.is_a?(Float) or value.is_a?(String)
if value.is_a?(String)
if value =~ /^-?\d+(:?\.\d+|(:?\.\d+)?e\d+)$/
@@ -267,13 +265,11 @@ class Puppet::Parser::Scope
# by default) including the values defined in our parent. Local values
# shadow parent values.
def to_hash(recursive = true)
- if recursive and parent then
- target = parent.to_hash(recursive)
- end
+ target = parent.to_hash(recursive) if recursive and parent
target ||= Hash.new
@symtable.keys.each { |name|
value = @symtable[name]
- if value == :undef then
+ if value == :undef
target.delete(name)
else
target[name] = value
@@ -339,12 +335,8 @@ class Puppet::Parser::Scope
else
error = Puppet::ParseError.new("Cannot append, variable #{name} is defined in this scope")
end
- if options[:file]
- error.file = options[:file]
- end
- if options[:line]
- error.line = options[:line]
- end
+ error.file = options[:file] if options[:file]
+ error.line = options[:line] if options[:line]
raise error
end
@@ -399,12 +391,8 @@ class Puppet::Parser::Scope
out << '$'
else
str = "Unrecognised escape sequence '#{ss.matched}'"
- if file
- str += " in file #{file}"
- end
- if line
- str += " at line #{line}"
- end
+ str += " in file #{file}" if file
+ str += " at line #{line}" if line
Puppet.warning str
out << ss.matched
end
@@ -444,9 +432,7 @@ class Puppet::Parser::Scope
# Undefine a variable; only used for testing.
def unsetvar(var)
table = ephemeral?(var) ? @ephemeral.last : @symtable
- if table.include?(var)
- table.delete(var)
- end
+ table.delete(var) if table.include?(var)
end
# remove ephemeral scope up to level
diff --git a/lib/puppet/parser/type_loader.rb b/lib/puppet/parser/type_loader.rb
index e0b4143fc..24411522b 100644
--- a/lib/puppet/parser/type_loader.rb
+++ b/lib/puppet/parser/type_loader.rb
@@ -102,9 +102,7 @@ class Puppet::Parser::TypeLoader
fullname = (namespace + "::#{name}").sub(/^::/, '')
# Try to load the module init file if we're a qualified name
- if fullname.include?("::")
- names_to_try << fullname.split("::")[0]
- end
+ names_to_try << fullname.split("::")[0] if fullname.include?("::")
# Then the fully qualified name
names_to_try << fullname
diff --git a/lib/puppet/parser/yaml_trimmer.rb b/lib/puppet/parser/yaml_trimmer.rb
index 14064c8e6..09159e38f 100644
--- a/lib/puppet/parser/yaml_trimmer.rb
+++ b/lib/puppet/parser/yaml_trimmer.rb
@@ -3,9 +3,7 @@ module Puppet::Parser::YamlTrimmer
def to_yaml_properties
r = instance_variables - REMOVE
- if respond_to?(:skip_for_yaml)
- r -= skip_for_yaml()
- end
+ r -= skip_for_yaml() if respond_to?(:skip_for_yaml)
r
end
end
diff --git a/lib/puppet/property.rb b/lib/puppet/property.rb
index f18709721..e8aeec053 100644
--- a/lib/puppet/property.rb
+++ b/lib/puppet/property.rb
@@ -21,18 +21,14 @@ class Puppet::Property < Puppet::Parameter
# Return array matching info, defaulting to just matching
# the first value.
def array_matching
- unless defined?(@array_matching)
- @array_matching = :first
- end
+ @array_matching = :first unless defined?(@array_matching)
@array_matching
end
# Set whether properties should match all values or just the first one.
def array_matching=(value)
value = value.intern if value.is_a?(String)
- unless [:first, :all].include?(value)
- raise ArgumentError, "Supported values for Property#array_matching are 'first' and 'all'"
- end
+ raise ArgumentError, "Supported values for Property#array_matching are 'first' and 'all'" unless [:first, :all].include?(value)
@array_matching = value
end
end
@@ -67,9 +63,7 @@ class Puppet::Property < Puppet::Parameter
def self.newvalue(name, options = {}, &block)
value = value_collection.newvalue(name, options, &block)
- if value.method and value.block
- define_method(value.method, &value.block)
- end
+ define_method(value.method, &value.block) if value.method and value.block
value
end
@@ -164,9 +158,7 @@ class Puppet::Property < Puppet::Parameter
def insync?(is)
return true unless @should
- unless @should.is_a?(Array)
- self.devfail "#{self.class.name}'s should is not array"
- end
+ self.devfail "#{self.class.name}'s should is not array" unless @should.is_a?(Array)
# an empty array is analogous to no should values
return true if @should.empty?
@@ -278,9 +270,7 @@ class Puppet::Property < Puppet::Parameter
def should
return nil unless defined?(@should)
- unless @should.is_a?(Array)
- self.devfail "should for #{self.class.name} on #{resource.name} is not an array"
- end
+ self.devfail "should for #{self.class.name} on #{resource.name} is not an array" unless @should.is_a?(Array)
if match_all?
return @should.collect { |val| self.unmunge(val) }
@@ -291,9 +281,7 @@ class Puppet::Property < Puppet::Parameter
# Set the should value.
def should=(values)
- unless values.is_a?(Array)
- values = [values]
- end
+ values = [values] unless values.is_a?(Array)
@shouldorig = values
diff --git a/lib/puppet/property/keyvalue.rb b/lib/puppet/property/keyvalue.rb
index df6560643..a1495b6a7 100644
--- a/lib/puppet/property/keyvalue.rb
+++ b/lib/puppet/property/keyvalue.rb
@@ -45,16 +45,12 @@ module Puppet
return {} if current == :absent
#inclusive means we are managing everything so if it isn't in should, its gone
- if inclusive?
- current.each_key { |key| current[key] = nil }
- end
+ current.each_key { |key| current[key] = nil } if inclusive?
current
end
def should
- unless defined?(@should) and @should
- return nil
- end
+ return nil unless defined?(@should) and @should
members = hashify(@should)
current = process_current_hash(retrieve)
@@ -81,13 +77,9 @@ module Puppet
end
def insync?(is)
- unless defined?(@should) and @should
- return true
- end
+ return true unless defined?(@should) and @should
- unless is
- return true
- end
+ return true unless is
return (is == self.should)
end
diff --git a/lib/puppet/property/list.rb b/lib/puppet/property/list.rb
index 2e38aeccc..2254ed249 100644
--- a/lib/puppet/property/list.rb
+++ b/lib/puppet/property/list.rb
@@ -22,9 +22,7 @@ module Puppet
end
def add_should_with_current(should, current)
- if current.is_a?(Array)
- should += current
- end
+ should += current if current.is_a?(Array)
should.uniq
end
@@ -38,15 +36,11 @@ module Puppet
end
def should
- unless defined?(@should) and @should
- return nil
- end
+ return nil unless defined?(@should) and @should
members = @should
#inclusive means we are managing everything so if it isn't in should, its gone
- if ! inclusive?
- members = add_should_with_current(members, retrieve)
- end
+ members = add_should_with_current(members, retrieve) if ! inclusive?
dearrayify(members)
end
@@ -72,13 +66,9 @@ module Puppet
end
def insync?(is)
- unless defined?(@should) and @should
- return true
- end
+ return true unless defined?(@should) and @should
- unless is
- return true
- end
+ return true unless is
return (prepare_is_for_comparison(is) == self.should)
end
diff --git a/lib/puppet/provider.rb b/lib/puppet/provider.rb
index ed7142e51..78c9b86f9 100644
--- a/lib/puppet/provider.rb
+++ b/lib/puppet/provider.rb
@@ -110,9 +110,7 @@ class Puppet::Provider
# Now define a method for that command
unless singleton_class.method_defined?(name)
meta_def(name) do |*args|
- unless command(name)
- raise Puppet::Error, "Command #{name} is missing"
- end
+ raise Puppet::Error, "Command #{name} is missing" unless command(name)
if args.empty?
cmd = [command(name)]
else
@@ -167,9 +165,7 @@ class Puppet::Provider
name = symbolize(name)
@commands[name] = path
- if block_given?
- yield(name, path)
- end
+ yield(name, path) if block_given?
# Now define the class and instance methods.
make_command_methods(name)
@@ -178,9 +174,7 @@ class Puppet::Provider
# Retrieve the data source. Defaults to the provider name.
def self.source
- unless defined?(@source)
- @source = self.name
- end
+ @source = self.name unless defined?(@source)
@source
end
diff --git a/lib/puppet/provider/augeas/augeas.rb b/lib/puppet/provider/augeas/augeas.rb
index 163c864fa..e41570105 100644
--- a/lib/puppet/provider/augeas/augeas.rb
+++ b/lib/puppet/provider/augeas/augeas.rb
@@ -62,9 +62,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
context << "/" if context[-1, 1] != "/"
end
- if data.is_a?(String)
- data = data.split($/)
- end
+ data = data.split($/) if data.is_a?(String)
data = data.flatten
args = []
data.each do |line|
@@ -116,9 +114,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
else
argline << sc.scan(/[^\s]+/)
end
- unless argline[-1]
- fail("missing string argument #{narg} for #{cmd}")
- end
+ fail("missing string argument #{narg} for #{cmd}") unless argline[-1]
elsif f == :comparator
argline << sc.scan(/(==|!=|=~|<|<=|>|>=)/)
unless argline[-1]
@@ -147,9 +143,7 @@ Puppet::Type.type(:augeas).provide(:augeas) do
debug("Opening augeas with root #{root}, lens path #{load_path}, flags #{flags}")
@aug = Augeas::open(root, load_path,flags)
- if get_augeas_version >= "0.3.6"
- debug("Augeas version #{get_augeas_version} is installed")
- end
+ debug("Augeas version #{get_augeas_version} is installed") if get_augeas_version >= "0.3.6"
if resource[:incl]
aug.set("/augeas/load/Xfm/lens", resource[:lens])
@@ -309,16 +303,12 @@ Puppet::Type.type(:augeas).provide(:augeas) do
# Re-connect to augeas, and re-execute the changes
begin
open_augeas
- if get_augeas_version >= "0.3.6"
- set_augeas_save_mode(SAVE_OVERWRITE)
- end
+ set_augeas_save_mode(SAVE_OVERWRITE) if get_augeas_version >= "0.3.6"
do_execute_changes
success = @aug.save
- if success != true
- fail("Save failed with return code #{success}")
- end
+ fail("Save failed with return code #{success}") if success != true
ensure
close_augeas
end
diff --git a/lib/puppet/provider/confine/variable.rb b/lib/puppet/provider/confine/variable.rb
index 0a5cc2960..66fe9b836 100644
--- a/lib/puppet/provider/confine/variable.rb
+++ b/lib/puppet/provider/confine/variable.rb
@@ -18,9 +18,7 @@ class Puppet::Provider::Confine::Variable < Puppet::Provider::Confine
# Retrieve the value from facter
def facter_value
- unless defined?(@facter_value) and @facter_value
- @facter_value = ::Facter.value(name).to_s.downcase
- end
+ @facter_value = ::Facter.value(name).to_s.downcase unless defined?(@facter_value) and @facter_value
@facter_value
end
diff --git a/lib/puppet/provider/confiner.rb b/lib/puppet/provider/confiner.rb
index 65243efce..1649336f3 100644
--- a/lib/puppet/provider/confiner.rb
+++ b/lib/puppet/provider/confiner.rb
@@ -6,9 +6,7 @@ module Puppet::Provider::Confiner
end
def confine_collection
- unless defined?(@confine_collection)
- @confine_collection = Puppet::Provider::ConfineCollection.new(self.to_s)
- end
+ @confine_collection = Puppet::Provider::ConfineCollection.new(self.to_s) unless defined?(@confine_collection)
@confine_collection
end
diff --git a/lib/puppet/provider/cron/crontab.rb b/lib/puppet/provider/cron/crontab.rb
index 5f2999fa2..a9c9889f8 100755
--- a/lib/puppet/provider/cron/crontab.rb
+++ b/lib/puppet/provider/cron/crontab.rb
@@ -21,9 +21,7 @@ tab = case Facter.value(:operatingsystem)
commands :crontab => "crontab"
text_line :comment, :match => %r{^#}, :post_parse => proc { |record|
- if record[:line] =~ /Puppet Name: (.+)\s*$/
- record[:name] = $1
- end
+ record[:name] = $1 if record[:line] =~ /Puppet Name: (.+)\s*$/
}
text_line :blank, :match => %r{^\s*$}
@@ -66,9 +64,7 @@ tab = case Facter.value(:operatingsystem)
# Add name and environments as necessary.
def to_line(record)
str = ""
- if record[:name]
- str = "# Puppet Name: #{record[:name]}\n"
- end
+ str = "# Puppet Name: #{record[:name]}\n" if record[:name]
if record[:environment] and record[:environment] != :absent and record[:environment] != [:absent]
record[:environment].each do |env|
str += env + "\n"
diff --git a/lib/puppet/provider/group/groupadd.rb b/lib/puppet/provider/group/groupadd.rb
index 65c3a5008..d9c50c2d5 100644
--- a/lib/puppet/provider/group/groupadd.rb
+++ b/lib/puppet/provider/group/groupadd.rb
@@ -20,9 +20,7 @@ Puppet::Type.type(:group).provide :groupadd, :parent => Puppet::Provider::NameSe
cmd << flag(:gid) << gid
end
end
- if @resource.allowdupe?
- cmd << "-o"
- end
+ cmd << "-o" if @resource.allowdupe?
cmd << @resource[:name]
return cmd
diff --git a/lib/puppet/provider/group/ldap.rb b/lib/puppet/provider/group/ldap.rb
index 87d62d53a..73524c268 100644
--- a/lib/puppet/provider/group/ldap.rb
+++ b/lib/puppet/provider/group/ldap.rb
@@ -30,9 +30,7 @@ Puppet::Type.type(:group).provide :ldap, :parent => Puppet::Provider::Ldap do
existing.each do |hash|
next unless value = hash[:gid]
num = value[0].to_i
- if num > largest
- largest = num
- end
+ largest = num if num > largest
end
end
largest + 1
diff --git a/lib/puppet/provider/host/parsed.rb b/lib/puppet/provider/host/parsed.rb
index 7c824ac9b..be2f735cd 100644
--- a/lib/puppet/provider/host/parsed.rb
+++ b/lib/puppet/provider/host/parsed.rb
@@ -45,9 +45,7 @@ end
raise Puppet::Error, "Could not match '#{line}'"
end
- if hash[:host_aliases] == ""
- hash[:host_aliases] = []
- end
+ hash[:host_aliases] = [] if hash[:host_aliases] == ""
return hash
end
@@ -56,9 +54,7 @@ end
def self.to_line(hash)
return super unless hash[:record_type] == :parsed
[:ip, :name].each do |n|
- unless hash[n] and hash[n] != :absent
- raise ArgumentError, "#{n} is a required attribute for hosts"
- end
+ raise ArgumentError, "#{n} is a required attribute for hosts" unless hash[n] and hash[n] != :absent
end
str = "#{hash[:ip]}\t#{hash[:name]}"
diff --git a/lib/puppet/provider/ldap.rb b/lib/puppet/provider/ldap.rb
index 098daa6ab..650258957 100644
--- a/lib/puppet/provider/ldap.rb
+++ b/lib/puppet/provider/ldap.rb
@@ -111,9 +111,7 @@ class Puppet::Provider::Ldap < Puppet::Provider
def properties
if @property_hash.empty?
@property_hash = query || {:ensure => :absent}
- if @property_hash.empty?
- @property_hash[:ensure] = :absent
- end
+ @property_hash[:ensure] = :absent if @property_hash.empty?
end
@property_hash.dup
end
diff --git a/lib/puppet/provider/macauthorization/macauthorization.rb b/lib/puppet/provider/macauthorization/macauthorization.rb
index 696b5bb82..a372618cc 100644
--- a/lib/puppet/provider/macauthorization/macauthorization.rb
+++ b/lib/puppet/provider/macauthorization/macauthorization.rb
@@ -63,9 +63,7 @@ Puppet::Type.type(:macauthorization).provide :macauthorization, :parent => Puppe
def populate_rules_rights
auth_plist = Plist::parse_xml(AuthDB)
- if not auth_plist
- raise Puppet::Error.new("Cannot parse: #{AuthDB}")
- end
+ raise Puppet::Error.new("Cannot parse: #{AuthDB}") if not auth_plist
self.rights = auth_plist["rights"].dup
self.rules = auth_plist["rules"].dup
self.parsed_auth_db = self.rights.dup
@@ -163,9 +161,7 @@ Puppet::Type.type(:macauthorization).provide :macauthorization, :parent => Puppe
cmds << :security << "authorizationdb" << "read" << resource[:name]
output = execute(cmds, :combine => false)
current_values = Plist::parse_xml(output)
- if current_values.nil?
- current_values = {}
- end
+ current_values = {} if current_values.nil?
specified_values = convert_plist_to_native_attributes(@property_hash)
# take the current values, merge the specified values to obtain a
@@ -178,9 +174,7 @@ Puppet::Type.type(:macauthorization).provide :macauthorization, :parent => Puppe
authdb = Plist::parse_xml(AuthDB)
authdb_rules = authdb["rules"].dup
current_values = {}
- if authdb_rules[resource[:name]]
- current_values = authdb_rules[resource[:name]]
- end
+ current_values = authdb_rules[resource[:name]] if authdb_rules[resource[:name]]
specified_values = convert_plist_to_native_attributes(@property_hash)
new_values = current_values.merge(specified_values)
set_rule(resource[:name], new_values)
@@ -254,9 +248,7 @@ Puppet::Type.type(:macauthorization).provide :macauthorization, :parent => Puppe
def retrieve_value(resource_name, attribute)
# We set boolean values to symbols when retrieving values
- if not self.class.parsed_auth_db.has_key?(resource_name)
- raise Puppet::Error.new("Cannot find #{resource_name} in auth db")
- end
+ raise Puppet::Error.new("Cannot find #{resource_name} in auth db") if not self.class.parsed_auth_db.has_key?(resource_name)
if PuppetToNativeAttributeMap.has_key?(attribute)
native_attribute = PuppetToNativeAttributeMap[attribute]
diff --git a/lib/puppet/provider/maillist/mailman.rb b/lib/puppet/provider/maillist/mailman.rb
index 5e60b20f1..cfb788b31 100755
--- a/lib/puppet/provider/maillist/mailman.rb
+++ b/lib/puppet/provider/maillist/mailman.rb
@@ -1,7 +1,7 @@
require 'puppet/provider/parsedfile'
Puppet::Type.type(:maillist).provide(:mailman) do
- if [ "CentOS", "RedHat", "Fedora" ].any? { |os| Facter.value(:operatingsystem) == os } then
+ if [ "CentOS", "RedHat", "Fedora" ].any? { |os| Facter.value(:operatingsystem) == os }
commands :list_lists => "/usr/lib/mailman/bin/list_lists", :rmlist => "/usr/lib/mailman/bin/rmlist", :newlist => "/usr/lib/mailman/bin/newlist"
commands :mailman => "/usr/lib/mailman/mail/mailman"
else
@@ -16,9 +16,7 @@ Puppet::Type.type(:maillist).provide(:mailman) do
def self.instances
list_lists.split("\n").reject { |line| line.include?("matching mailing lists") }.collect do |line|
name, description = line.sub(/^\s+/, '').sub(/\s+$/, '').split(/\s+-\s+/)
- if description.include?("no description available")
- description = :absent
- end
+ description = :absent if description.include?("no description available")
new(:ensure => :present, :name => name, :description => description)
end
end
@@ -69,9 +67,7 @@ Puppet::Type.type(:maillist).provide(:mailman) do
# Delete the list.
def destroy(purge = false)
args = []
- if purge
- args << "--archives"
- end
+ args << "--archives" if purge
args << self.name
rmlist(*args)
end
@@ -90,9 +86,7 @@ Puppet::Type.type(:maillist).provide(:mailman) do
def properties
if @property_hash.empty?
@property_hash = query || {:ensure => :absent}
- if @property_hash.empty?
- @property_hash[:ensure] = :absent
- end
+ @property_hash[:ensure] = :absent if @property_hash.empty?
end
@property_hash.dup
end
diff --git a/lib/puppet/provider/mcx/mcxcontent.rb b/lib/puppet/provider/mcx/mcxcontent.rb
index de60de15a..3a1deb5f3 100644
--- a/lib/puppet/provider/mcx/mcxcontent.rb
+++ b/lib/puppet/provider/mcx/mcxcontent.rb
@@ -140,15 +140,11 @@ Puppet::Type.type(:mcx).provide :mcxcontent, :parent => Puppet::Provider do
# This is a private instance method, not a class method.
def get_dsparams
ds_type = resource[:ds_type]
- if ds_type.nil?
- ds_type = parse_type(resource[:name])
- end
+ ds_type = parse_type(resource[:name]) if ds_type.nil?
raise MCXContentProviderException unless TypeMap.keys.include? ds_type.to_sym
ds_name = resource[:ds_name]
- if ds_name.nil?
- ds_name = parse_name(resource[:name])
- end
+ ds_name = parse_name(resource[:name]) if ds_name.nil?
rval = {
:ds_type => ds_type.to_sym,
diff --git a/lib/puppet/provider/mount.rb b/lib/puppet/provider/mount.rb
index a63a0402c..86361969c 100644
--- a/lib/puppet/provider/mount.rb
+++ b/lib/puppet/provider/mount.rb
@@ -11,14 +11,10 @@ module Puppet::Provider::Mount
# Manually pass the mount options in, since some OSes *cough*OS X*cough* don't
# read from /etc/fstab but still want to use this type.
args = []
- if self.options and self.options != :absent
- args << "-o" << self.options
- end
+ args << "-o" << self.options if self.options and self.options != :absent
args << resource[:name]
- if respond_to?(:flush)
- flush
- end
+ flush if respond_to?(:flush)
mountcmd(*args)
end
diff --git a/lib/puppet/provider/nameservice.rb b/lib/puppet/provider/nameservice.rb
index dace6b512..4a7c38bdb 100644
--- a/lib/puppet/provider/nameservice.rb
+++ b/lib/puppet/provider/nameservice.rb
@@ -44,9 +44,7 @@ class Puppet::Provider::NameService < Puppet::Provider
end
def options(name, hash)
- unless resource_type.valid_parameter?(name)
- raise Puppet::DevError, "#{name} is not a valid attribute for #{resource_type.name}"
- end
+ raise Puppet::DevError, "#{name} is not a valid attribute for #{resource_type.name}" unless resource_type.valid_parameter?(name)
@options ||= {}
@options[name] ||= {}
@@ -65,9 +63,7 @@ class Puppet::Provider::NameService < Puppet::Provider
begin
while ent = Etc.send("get#{section()}ent")
names << ent.name
- if block_given?
- yield ent.name
- end
+ yield ent.name if block_given?
end
ensure
Etc.send("end#{section()}ent")
@@ -80,12 +76,8 @@ class Puppet::Provider::NameService < Puppet::Provider
super
@resource_type.validproperties.each do |prop|
next if prop == :ensure
- unless public_method_defined?(prop)
- define_method(prop) { get(prop) || :absent}
- end
- unless public_method_defined?(prop.to_s + "=")
- define_method(prop.to_s + "=") { |*vals| set(prop, *vals) }
- end
+ define_method(prop) { get(prop) || :absent} unless public_method_defined?(prop)
+ define_method(prop.to_s + "=") { |*vals| set(prop, *vals) } unless public_method_defined?(prop.to_s + "=")
end
end
@@ -109,9 +101,7 @@ class Puppet::Provider::NameService < Puppet::Provider
name = name.intern if name.is_a? String
if @checks.include? name
block = @checks[name][:block]
- unless block.call(value)
- raise ArgumentError, "Invalid value #{value}: #{@checks[name][:error]}"
- end
+ raise ArgumentError, "Invalid value #{value}: #{@checks[name][:error]}" unless block.call(value)
end
end
@@ -164,9 +154,7 @@ class Puppet::Provider::NameService < Puppet::Provider
else
Etc.send(group) { |obj|
if obj.gid > highest
- unless obj.send(method) > 65000
- highest = obj.send(method)
- end
+ highest = obj.send(method) unless obj.send(method) > 65000
end
}
@@ -264,9 +252,7 @@ class Puppet::Provider::NameService < Puppet::Provider
while group = Etc.getgrent
members = group.mem
- if members.include? user
- groups << group.name
- end
+ groups << group.name if members.include? user
end
# We have to close the file, so each listing is a separate
@@ -281,9 +267,7 @@ class Puppet::Provider::NameService < Puppet::Provider
hash = {}
self.class.resource_type.validproperties.each do |param|
method = posixmethod(param)
- if info.respond_to? method
- hash[param] = info.send(posixmethod(param))
- end
+ hash[param] = info.send(posixmethod(param)) if info.respond_to? method
end
return hash
@@ -298,9 +282,7 @@ class Puppet::Provider::NameService < Puppet::Provider
def set(param, value)
self.class.validate(param, value)
cmd = modifycmd(param, value)
- unless cmd.is_a?(Array)
- raise Puppet::DevError, "Nameservice command must be an array"
- end
+ raise Puppet::DevError, "Nameservice command must be an array" unless cmd.is_a?(Array)
begin
execute(cmd)
rescue Puppet::ExecutionFailure => detail
diff --git a/lib/puppet/provider/nameservice/directoryservice.rb b/lib/puppet/provider/nameservice/directoryservice.rb
index 251f496d5..5ee4d8e21 100644
--- a/lib/puppet/provider/nameservice/directoryservice.rb
+++ b/lib/puppet/provider/nameservice/directoryservice.rb
@@ -93,9 +93,7 @@ class DirectoryService < Puppet::Provider::NameService
# For example, if we're working with an user type, this will be /Users
# with a group type, this will be /Groups.
# @ds_path is an attribute of the class itself.
- if defined?(@ds_path)
- return @ds_path
- end
+ return @ds_path if defined?(@ds_path)
# JJM: "Users" or "Groups" etc ... (Based on the Puppet::Type)
# Remember this is a class method, so self.class is Class
# Also, @resource_type seems to be the reference to the
@@ -104,9 +102,7 @@ class DirectoryService < Puppet::Provider::NameService
end
def self.get_macosx_version_major
- if defined?(@macosx_version_major)
- return @macosx_version_major
- end
+ return @macosx_version_major if defined?(@macosx_version_major)
begin
# Make sure we've loaded all of the facts
Facter.loadfacts
@@ -117,14 +113,10 @@ class DirectoryService < Puppet::Provider::NameService
# TODO: remove this code chunk once we require Facter 1.5.5 or higher.
Puppet.warning("DEPRECATION WARNING: Future versions of the directoryservice provider will require Facter 1.5.5 or newer.")
product_version = Facter.value(:macosx_productversion)
- if product_version.nil?
- fail("Could not determine OS X version from Facter")
- end
+ fail("Could not determine OS X version from Facter") if product_version.nil?
product_version_major = product_version.scan(/(\d+)\.(\d+)./).join(".")
end
- if %w{10.0 10.1 10.2 10.3}.include?(product_version_major)
- fail("#{product_version_major} is not supported by the directoryservice provider")
- end
+ fail("#{product_version_major} is not supported by the directoryservice provider") if %w{10.0 10.1 10.2 10.3}.include?(product_version_major)
@macosx_version_major = product_version_major
return @macosx_version_major
rescue Puppet::ExecutionFailure => detail
@@ -215,9 +207,7 @@ class DirectoryService < Puppet::Provider::NameService
# stored in the user record. It is stored at a path that involves the
# UUID of the user record for non-Mobile local acccounts.
# Mobile Accounts are out of scope for this provider for now
- if @resource_type.validproperties.include?(:password) and Puppet.features.root?
- attribute_hash[:password] = self.get_password(attribute_hash[:guid])
- end
+ attribute_hash[:password] = self.get_password(attribute_hash[:guid]) if @resource_type.validproperties.include?(:password) and Puppet.features.root?
return attribute_hash
end
@@ -323,9 +313,7 @@ class DirectoryService < Puppet::Provider::NameService
password_hash = nil
password_hash_file = "#{@@password_hash_dir}/#{guid}"
if File.exists?(password_hash_file) and File.file?(password_hash_file)
- if not File.readable?(password_hash_file)
- fail("Could not read password hash file at #{password_hash_file}")
- end
+ fail("Could not read password hash file at #{password_hash_file}") if not File.readable?(password_hash_file)
f = File.new(password_hash_file)
password_hash = f.read
f.close
@@ -383,9 +371,7 @@ class DirectoryService < Puppet::Provider::NameService
# If we are meant to be authoritative for the group membership
# then remove all existing members who haven't been specified
# in the manifest.
- if @resource[:auth_membership] and not current_members.nil?
- remove_unwanted_members(current_members, value)
- end
+ remove_unwanted_members(current_members, value) if @resource[:auth_membership] and not current_members.nil?
# if they're not a member, make them one.
add_members(current_members, value)
diff --git a/lib/puppet/provider/package.rb b/lib/puppet/provider/package.rb
index f7ff7e55a..0ce6cca0a 100644
--- a/lib/puppet/provider/package.rb
+++ b/lib/puppet/provider/package.rb
@@ -20,9 +20,7 @@ class Puppet::Provider::Package < Puppet::Provider
def properties
if @property_hash.empty?
@property_hash = query || {:ensure => :absent}
- if @property_hash.empty?
- @property_hash[:ensure] = :absent
- end
+ @property_hash[:ensure] = :absent if @property_hash.empty?
end
@property_hash.dup
end
diff --git a/lib/puppet/provider/package/aix.rb b/lib/puppet/provider/package/aix.rb
index 7523b776d..fd0cfdc7e 100644
--- a/lib/puppet/provider/package/aix.rb
+++ b/lib/puppet/provider/package/aix.rb
@@ -22,9 +22,7 @@ Puppet::Type.type(:package).provide :aix, :parent => Puppet::Provider::Package d
end
def self.prefetch(packages)
- if Process.euid != 0
- raise Puppet::Error, "The aix provider can only be used by root"
- end
+ raise Puppet::Error, "The aix provider can only be used by root" if Process.euid != 0
return unless packages.detect { |name, package| package.should(:ensure) == :latest }
@@ -42,9 +40,7 @@ Puppet::Type.type(:package).provide :aix, :parent => Puppet::Provider::Package d
if updates.key?(current[:name])
previous = updates[current[:name]]
- unless Puppet::Util::Package.versioncmp(previous[:version], current[:version]) == 1
- updates[ current[:name] ] = current
- end
+ updates[ current[:name] ] = current unless Puppet::Util::Package.versioncmp(previous[:version], current[:version]) == 1
else
updates[current[:name]] = current
@@ -73,9 +69,7 @@ Puppet::Type.type(:package).provide :aix, :parent => Puppet::Provider::Package d
pkg = @resource[:name]
- if (! @resource.should(:ensure).is_a? Symbol) and useversion
- pkg << " #{@resource.should(:ensure)}"
- end
+ pkg << " #{@resource.should(:ensure)}" if (! @resource.should(:ensure).is_a? Symbol) and useversion
installp "-acgwXY", "-d", source, pkg
end
@@ -118,9 +112,7 @@ Puppet::Type.type(:package).provide :aix, :parent => Puppet::Provider::Package d
unless upd.nil?
return "#{upd[:version]}"
else
- if properties[:ensure] == :absent
- raise Puppet::DevError, "Tried to get latest on a missing package"
- end
+ raise Puppet::DevError, "Tried to get latest on a missing package" if properties[:ensure] == :absent
return properties[:ensure]
end
diff --git a/lib/puppet/provider/package/apt.rb b/lib/puppet/provider/package/apt.rb
index 622e182ea..afbff6237 100755
--- a/lib/puppet/provider/package/apt.rb
+++ b/lib/puppet/provider/package/apt.rb
@@ -42,9 +42,7 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg, :source => :dpkg do
# Install a package using 'apt-get'. This function needs to support
# installing a specific version.
def install
- if @resource[:responsefile]
- self.run_preseed
- end
+ self.run_preseed if @resource[:responsefile]
should = @resource[:ensure]
checkforcdrom()
@@ -100,16 +98,12 @@ Puppet::Type.type(:package).provide :apt, :parent => :dpkg, :source => :dpkg do
end
def uninstall
- if @resource[:responsefile]
- self.run_preseed
- end
+ self.run_preseed if @resource[:responsefile]
aptget "-y", "-q", :remove, @resource[:name]
end
def purge
- if @resource[:responsefile]
- self.run_preseed
- end
+ self.run_preseed if @resource[:responsefile]
aptget '-y', '-q', :remove, '--purge', @resource[:name]
# workaround a "bug" in apt, that already removed packages are not purged
super
diff --git a/lib/puppet/provider/package/aptitude.rb b/lib/puppet/provider/package/aptitude.rb
index 607f8c0dc..5529535de 100755
--- a/lib/puppet/provider/package/aptitude.rb
+++ b/lib/puppet/provider/package/aptitude.rb
@@ -11,9 +11,7 @@ Puppet::Type.type(:package).provide :aptitude, :parent => :apt, :source => :dpkg
def aptget(*args)
args.flatten!
# Apparently aptitude hasn't always supported a -q flag.
- if args.include?("-q")
- args.delete("-q")
- end
+ args.delete("-q") if args.include?("-q")
output = aptitude(*args)
# Yay, stupid aptitude doesn't throw an error when the package is missing.
diff --git a/lib/puppet/provider/package/aptrpm.rb b/lib/puppet/provider/package/aptrpm.rb
index a3ad3b447..42f7e706c 100644
--- a/lib/puppet/provider/package/aptrpm.rb
+++ b/lib/puppet/provider/package/aptrpm.rb
@@ -59,9 +59,7 @@ Puppet::Type.type(:package).provide :aptrpm, :parent => :rpm, :source => :rpm do
if available_versions.length == 0
self.debug "No latest version"
- if Puppet[:debug]
- print output
- end
+ print output if Puppet[:debug]
end
# Get the latest and greatest version number
diff --git a/lib/puppet/provider/package/blastwave.rb b/lib/puppet/provider/package/blastwave.rb
index ee1e8f73a..d1cfe6f2b 100755
--- a/lib/puppet/provider/package/blastwave.rb
+++ b/lib/puppet/provider/package/blastwave.rb
@@ -2,9 +2,7 @@
Puppet::Type.type(:package).provide :blastwave, :parent => :sun, :source => :sun do
desc "Package management using Blastwave.org's ``pkg-get`` command on Solaris."
pkgget = "pkg-get"
- if FileTest.executable?("/opt/csw/bin/pkg-get")
- pkgget = "/opt/csw/bin/pkg-get"
- end
+ pkgget = "/opt/csw/bin/pkg-get" if FileTest.executable?("/opt/csw/bin/pkg-get")
confine :operatingsystem => :solaris
@@ -37,9 +35,7 @@ Puppet::Type.type(:package).provide :blastwave, :parent => :sun, :source => :sun
def self.blastlist(hash)
command = ["-c"]
- if hash[:justme]
- command << hash[:justme]
- end
+ command << hash[:justme] if hash[:justme]
output = Puppet::Util::Execution::withenv(:PAGER => "/usr/bin/cat") { pkgget command }
@@ -74,9 +70,7 @@ Puppet::Type.type(:package).provide :blastwave, :parent => :sun, :source => :sun
end
hash[:avail] = $5
- if hash[:avail] == "SAME"
- hash[:avail] = hash[:ensure]
- end
+ hash[:avail] = hash[:ensure] if hash[:avail] == "SAME"
# Use the name method, so it works with subclasses.
hash[:provider] = self.name
diff --git a/lib/puppet/provider/package/darwinport.rb b/lib/puppet/provider/package/darwinport.rb
index 2153d2f83..4b9fdb462 100755
--- a/lib/puppet/provider/package/darwinport.rb
+++ b/lib/puppet/provider/package/darwinport.rb
@@ -56,9 +56,7 @@ Puppet::Type.type(:package).provide :darwinport, :parent => Puppet::Provider::Pa
def query
version = nil
self.class.eachpkgashash do |hash|
- if hash[:name] == @resource[:name]
- return hash
- end
+ return hash if hash[:name] == @resource[:name]
end
return nil
diff --git a/lib/puppet/provider/package/dpkg.rb b/lib/puppet/provider/package/dpkg.rb
index 3c3141b4f..77f7a61eb 100755
--- a/lib/puppet/provider/package/dpkg.rb
+++ b/lib/puppet/provider/package/dpkg.rb
@@ -52,9 +52,7 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package
elsif ['config-files', 'half-installed', 'unpacked', 'half-configured'].include?(hash[:status])
hash[:ensure] = :absent
end
- if hash[:desired] == 'hold'
- hash[:ensure] = :held
- end
+ hash[:ensure] = :held if hash[:desired] == 'hold'
else
Puppet.warning "Failed to match dpkg-query line #{line.inspect}"
return nil
@@ -91,9 +89,7 @@ Puppet::Type.type(:package).provide :dpkg, :parent => Puppet::Provider::Package
def latest
output = dpkg_deb "--show", @resource[:source]
matches = /^(\S+)\t(\S+)$/.match(output).captures
- unless matches[0].match( Regexp.escape(@resource[:name]) )
- warning "source doesn't contain named package, but #{matches[0]}"
- end
+ warning "source doesn't contain named package, but #{matches[0]}" unless matches[0].match( Regexp.escape(@resource[:name]) )
matches[1]
end
diff --git a/lib/puppet/provider/package/fink.rb b/lib/puppet/provider/package/fink.rb
index 3f0d79475..a7310b00a 100755
--- a/lib/puppet/provider/package/fink.rb
+++ b/lib/puppet/provider/package/fink.rb
@@ -22,9 +22,7 @@ Puppet::Type.type(:package).provide :fink, :parent => :dpkg, :source => :dpkg do
# Install a package using 'apt-get'. This function needs to support
# installing a specific version.
def install
- if @resource[:responsefile]
- self.run_preseed
- end
+ self.run_preseed if @resource[:responsefile]
should = @resource.should(:ensure)
str = @resource[:name]
diff --git a/lib/puppet/provider/package/freebsd.rb b/lib/puppet/provider/package/freebsd.rb
index 0c816cdb6..20ded987e 100755
--- a/lib/puppet/provider/package/freebsd.rb
+++ b/lib/puppet/provider/package/freebsd.rb
@@ -29,9 +29,7 @@ Puppet::Type.type(:package).provide :freebsd, :parent => :openbsd do
end
end
else
- if @resource[:source]
- Puppet.warning "source is defined but does not have trailing slash, ignoring #{@resource[:source]}"
- end
+ Puppet.warning "source is defined but does not have trailing slash, ignoring #{@resource[:source]}" if @resource[:source]
pkgadd "-r", @resource[:name]
end
end
diff --git a/lib/puppet/provider/package/gem.rb b/lib/puppet/provider/package/gem.rb
index 1c345097f..53677a9c5 100755
--- a/lib/puppet/provider/package/gem.rb
+++ b/lib/puppet/provider/package/gem.rb
@@ -69,9 +69,7 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d
def install(useversion = true)
command = [command(:gemcmd), "install"]
- if (! resource[:ensure].is_a? Symbol) and useversion
- command << "-v" << resource[:ensure]
- end
+ command << "-v" << resource[:ensure] if (! resource[:ensure].is_a? Symbol) and useversion
# Always include dependencies
command << "--include-dependencies"
@@ -101,9 +99,7 @@ Puppet::Type.type(:package).provide :gem, :parent => Puppet::Provider::Package d
output = execute(command)
# Apparently some stupid gem versions don't exit non-0 on failure
- if output.include?("ERROR")
- self.fail "Could not install: #{output.chomp}"
- end
+ self.fail "Could not install: #{output.chomp}" if output.include?("ERROR")
end
def latest
diff --git a/lib/puppet/provider/package/nim.rb b/lib/puppet/provider/package/nim.rb
index a798f338a..8b273767e 100644
--- a/lib/puppet/provider/package/nim.rb
+++ b/lib/puppet/provider/package/nim.rb
@@ -28,9 +28,7 @@ Puppet::Type.type(:package).provide :nim, :parent => :aix, :source => :aix do
pkg = @resource[:name]
- if (! @resource.should(:ensure).is_a? Symbol) and useversion
- pkg << " " << @resource.should(:ensure)
- end
+ pkg << " " << @resource.should(:ensure) if (! @resource.should(:ensure).is_a? Symbol) and useversion
nimclient "-o", "cust", "-a", "installp_flags=acgwXY", "-a", "lpp_source=#{source}", "-a", "filesets='#{pkg}'"
end
diff --git a/lib/puppet/provider/package/openbsd.rb b/lib/puppet/provider/package/openbsd.rb
index 149b557ae..f5f978056 100755
--- a/lib/puppet/provider/package/openbsd.rb
+++ b/lib/puppet/provider/package/openbsd.rb
@@ -65,9 +65,7 @@ Puppet::Type.type(:package).provide :openbsd, :parent => Puppet::Provider::Packa
if @resource[:source] =~ /\/$/
withenv :PKG_PATH => @resource[:source] do
- if (@resource[:ensure] = get_version) == nil
- @resource[:ensure] = old_ensure
- end
+ @resource[:ensure] = old_ensure if (@resource[:ensure] = get_version) == nil
full_name = [ @resource[:name], @resource[:ensure], @resource[:flavor] ]
pkgadd full_name.join('-').chomp('-')
end
diff --git a/lib/puppet/provider/package/pkg.rb b/lib/puppet/provider/package/pkg.rb
index c0767a7f0..ab8429864 100644
--- a/lib/puppet/provider/package/pkg.rb
+++ b/lib/puppet/provider/package/pkg.rb
@@ -100,9 +100,7 @@ Puppet::Type.type(:package).provide :pkg, :parent => Puppet::Provider::Package d
hash = self.class.parse_line(output) ||
{:ensure => :absent, :status => 'missing', :name => @resource[:name], :error => 'ok'}
- if hash[:error] != "ok"
- raise Puppet::Error.new( "Package #{hash[:name]}, version #{hash[:version]} is in error state: #{hash[:error]}")
- end
+ raise Puppet::Error.new( "Package #{hash[:name]}, version #{hash[:version]} is in error state: #{hash[:error]}") if hash[:error] != "ok"
return hash
end
diff --git a/lib/puppet/provider/package/pkgdmg.rb b/lib/puppet/provider/package/pkgdmg.rb
index ac4853d83..b533f1002 100644
--- a/lib/puppet/provider/package/pkgdmg.rb
+++ b/lib/puppet/provider/package/pkgdmg.rb
@@ -92,9 +92,7 @@ Puppet::Type.type(:package).provide :pkgdmg, :parent => Puppet::Provider::Packag
File.open(cached_source) do |dmg|
xml_str = hdiutil "mount", "-plist", "-nobrowse", "-readonly", "-noidme", "-mountrandom", "/tmp", dmg.path
hdiutil_info = Plist::parse_xml(xml_str)
- unless hdiutil_info.has_key?("system-entities")
- raise Puppet::Error.new("No disk entities returned by mount at #{dmg.path}")
- end
+ raise Puppet::Error.new("No disk entities returned by mount at #{dmg.path}") unless hdiutil_info.has_key?("system-entities")
mounts = hdiutil_info["system-entities"].collect { |entity|
entity["mount-point"]
}.compact
diff --git a/lib/puppet/provider/package/portage.rb b/lib/puppet/provider/package/portage.rb
index 7e1119a1a..a8d071f41 100644
--- a/lib/puppet/provider/package/portage.rb
+++ b/lib/puppet/provider/package/portage.rb
@@ -20,9 +20,7 @@ Puppet::Type.type(:package).provide :portage, :parent => Puppet::Provider::Packa
search_format = "<category> <name> [<installedversions:LASTVERSION>] [<bestversion:LASTVERSION>] <homepage> <description>\n"
begin
- if !FileUtils.uptodate?("/var/cache/eix", %w{/usr/bin/eix /usr/portage/metadata/timestamp})
- update_eix
- end
+ update_eix if !FileUtils.uptodate?("/var/cache/eix", %w{/usr/bin/eix /usr/portage/metadata/timestamp})
search_output = nil
Puppet::Util::Execution.withenv :LASTVERSION => version_format do
@@ -83,9 +81,7 @@ Puppet::Type.type(:package).provide :portage, :parent => Puppet::Provider::Packa
search_value = package_name
begin
- if !FileUtils.uptodate?("/var/cache/eix", %w{/usr/bin/eix /usr/portage/metadata/timestamp})
- update_eix
- end
+ update_eix if !FileUtils.uptodate?("/var/cache/eix", %w{/usr/bin/eix /usr/portage/metadata/timestamp})
search_output = nil
Puppet::Util::Execution.withenv :LASTVERSION => version_format do
diff --git a/lib/puppet/provider/package/ports.rb b/lib/puppet/provider/package/ports.rb
index 286aca8e1..4a925aa8d 100755
--- a/lib/puppet/provider/package/ports.rb
+++ b/lib/puppet/provider/package/ports.rb
@@ -10,9 +10,7 @@ Puppet::Type.type(:package).provide :ports, :parent => :freebsd, :source => :fre
# I hate ports
%w{INTERACTIVE UNAME}.each do |var|
- if ENV.include?(var)
- ENV.delete(var)
- end
+ ENV.delete(var) if ENV.include?(var)
end
def install
diff --git a/lib/puppet/provider/package/rpm.rb b/lib/puppet/provider/package/rpm.rb
index 6d5adf2ef..abcfbd3b6 100755
--- a/lib/puppet/provider/package/rpm.rb
+++ b/lib/puppet/provider/package/rpm.rb
@@ -94,9 +94,7 @@ Puppet::Type.type(:package).provide :rpm, :source => :rpm, :parent => Puppet::Pr
end
flag = "-i"
- if @property_hash[:ensure] and @property_hash[:ensure] != :absent
- flag = "-U"
- end
+ flag = "-U" if @property_hash[:ensure] and @property_hash[:ensure] != :absent
rpm flag, "--oldpackage", source
end
diff --git a/lib/puppet/provider/package/sun.rb b/lib/puppet/provider/package/sun.rb
index f0a1c6ac5..2d4e1ac3f 100755
--- a/lib/puppet/provider/package/sun.rb
+++ b/lib/puppet/provider/package/sun.rb
@@ -50,9 +50,7 @@ Puppet::Type.type(:package).provide :sun, :parent => Puppet::Provider::Package d
name = $1
value = $2
if names.include?(name)
- unless names[name].nil?
- hash[names[name]] = value
- end
+ hash[names[name]] = value unless names[name].nil?
end
when /\s+\d+.+/
# nothing; we're ignoring the FILES info
@@ -84,9 +82,7 @@ Puppet::Type.type(:package).provide :sun, :parent => Puppet::Provider::Package d
hash = {}
cmd = "#{command(:pkginfo)} -l"
- if device
- cmd += " -d #{device}"
- end
+ cmd += " -d #{device}" if device
cmd += " #{@resource[:name]}"
begin
@@ -101,9 +97,7 @@ Puppet::Type.type(:package).provide :sun, :parent => Puppet::Provider::Package d
name = $1
value = $2
if names.include?(name)
- unless names[name].nil?
- hash[names[name]] = value
- end
+ hash[names[name]] = value unless names[name].nil?
end
when /\s+\d+.+/
# nothing; we're ignoring the FILES info
@@ -119,18 +113,12 @@ Puppet::Type.type(:package).provide :sun, :parent => Puppet::Provider::Package d
end
def install
- unless @resource[:source]
- raise Puppet::Error, "Sun packages must specify a package source"
- end
+ raise Puppet::Error, "Sun packages must specify a package source" unless @resource[:source]
cmd = []
- if @resource[:adminfile]
- cmd << "-a" << @resource[:adminfile]
- end
+ cmd << "-a" << @resource[:adminfile] if @resource[:adminfile]
- if @resource[:responsefile]
- cmd << "-r" << @resource[:responsefile]
- end
+ cmd << "-r" << @resource[:responsefile] if @resource[:responsefile]
cmd << "-d" << @resource[:source]
cmd << "-n" << @resource[:name]
@@ -151,9 +139,7 @@ Puppet::Type.type(:package).provide :sun, :parent => Puppet::Provider::Package d
def uninstall
command = ["-n"]
- if @resource[:adminfile]
- command << "-a" << @resource[:adminfile]
- end
+ command << "-a" << @resource[:adminfile] if @resource[:adminfile]
command << @resource[:name]
pkgrm command
@@ -162,9 +148,7 @@ Puppet::Type.type(:package).provide :sun, :parent => Puppet::Provider::Package d
# Remove the old package, and install the new one. This will probably
# often fail.
def update
- if (@property_hash[:ensure] || info2hash()[:ensure]) != :absent
- self.uninstall
- end
+ self.uninstall if (@property_hash[:ensure] || info2hash()[:ensure]) != :absent
self.install
end
end
diff --git a/lib/puppet/provider/package/yum.rb b/lib/puppet/provider/package/yum.rb
index 4ff365de7..17981f03c 100755
--- a/lib/puppet/provider/package/yum.rb
+++ b/lib/puppet/provider/package/yum.rb
@@ -22,9 +22,7 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
defaultfor :operatingsystem => [:fedora, :centos, :redhat]
def self.prefetch(packages)
- if Process.euid != 0
- raise Puppet::Error, "The yum provider can only be used as root"
- end
+ raise Puppet::Error, "The yum provider can only be used as root" if Process.euid != 0
super
return unless packages.detect { |name, package| package.should(:ensure) == :latest }
@@ -68,15 +66,11 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
output = yum "-d", "0", "-e", "0", "-y", :install, wanted
is = self.query
- unless is
- raise Puppet::Error, "Could not find package #{self.name}"
- end
+ raise Puppet::Error, "Could not find package #{self.name}" unless is
# FIXME: Should we raise an exception even if should == :latest
# and yum updated us to a version other than @param_hash[:ensure] ?
- if should && should != is[:ensure]
- raise Puppet::Error, "Failed to update to version #{should}, got version #{is[:ensure]} instead"
- end
+ raise Puppet::Error, "Failed to update to version #{should}, got version #{is[:ensure]} instead" if should && should != is[:ensure]
end
# What's the latest package version available?
@@ -89,9 +83,7 @@ Puppet::Type.type(:package).provide :yum, :parent => :rpm, :source => :rpm do
else
# Yum didn't find updates, pretend the current
# version is the latest
- if properties[:ensure] == :absent
- raise Puppet::DevError, "Tried to get latest on a missing package"
- end
+ raise Puppet::DevError, "Tried to get latest on a missing package" if properties[:ensure] == :absent
return properties[:ensure]
end
end
diff --git a/lib/puppet/provider/parsedfile.rb b/lib/puppet/provider/parsedfile.rb
index e4d1e95f3..65842a28b 100755
--- a/lib/puppet/provider/parsedfile.rb
+++ b/lib/puppet/provider/parsedfile.rb
@@ -22,9 +22,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
def self.clean(hash)
newhash = hash.dup
[:record_type, :on_disk].each do |p|
- if newhash.include?(p)
- newhash.delete(p)
- end
+ newhash.delete(p) if newhash.include?(p)
end
return newhash
@@ -36,9 +34,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
end
def self.filetype
- unless defined?(@filetype)
- @filetype = Puppet::Util::FileType.filetype(:flat)
- end
+ @filetype = Puppet::Util::FileType.filetype(:flat) unless defined?(@filetype)
return @filetype
end
@@ -83,9 +79,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
def self.backup_target(target)
return nil unless target_object(target).respond_to?(:backup)
- unless defined?(@backup_stats)
- @backup_stats = {}
- end
+ @backup_stats = {} unless defined?(@backup_stats)
return nil if @backup_stats[target] == @records.object_id
target_object(target).backup
@@ -229,13 +223,9 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
r[:ensure] = :present
end
- if respond_to?(:prefetch_hook)
- target_records = prefetch_hook(target_records)
- end
+ target_records = prefetch_hook(target_records) if respond_to?(:prefetch_hook)
- unless target_records
- raise Puppet::DevError, "Prefetching #{target} for provider #{self.name} returned nil"
- end
+ raise Puppet::DevError, "Prefetching #{target} for provider #{self.name} returned nil" unless target_records
target_records
end
@@ -292,9 +282,7 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
def self.targets(resources = nil)
targets = []
# First get the default target
- unless self.default_target
- raise Puppet::DevError, "Parsed Providers must define a default target"
- end
+ raise Puppet::DevError, "Parsed Providers must define a default target" unless self.default_target
targets << self.default_target
# Then get each of the file objects
@@ -364,16 +352,12 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
# The 'record' could be a resource or a record, depending on how the provider
# is initialized. If we got an empty property hash (probably because the resource
# is just being initialized), then we want to set up some defualts.
- if @property_hash.empty?
- @property_hash = self.class.record?(resource[:name]) || {:record_type => self.class.name, :ensure => :absent}
- end
+ @property_hash = self.class.record?(resource[:name]) || {:record_type => self.class.name, :ensure => :absent} if @property_hash.empty?
end
# Retrieve the current state from disk.
def prefetch
- unless @resource
- raise Puppet::DevError, "Somehow got told to prefetch with no resource set"
- end
+ raise Puppet::DevError, "Somehow got told to prefetch with no resource set" unless @resource
self.class.prefetch(@resource[:name] => @resource)
end
@@ -388,8 +372,6 @@ class Puppet::Provider::ParsedFile < Puppet::Provider
if defined?(@resource) and restarget = @resource.should(:target) and restarget != @property_hash[:target]
self.class.modified(restarget)
end
- if @property_hash[:target] != :absent and @property_hash[:target]
- self.class.modified(@property_hash[:target])
- end
+ self.class.modified(@property_hash[:target]) if @property_hash[:target] != :absent and @property_hash[:target]
end
end
diff --git a/lib/puppet/provider/selboolean/getsetsebool.rb b/lib/puppet/provider/selboolean/getsetsebool.rb
index 940ce3b70..21604efd4 100644
--- a/lib/puppet/provider/selboolean/getsetsebool.rb
+++ b/lib/puppet/provider/selboolean/getsetsebool.rb
@@ -9,7 +9,7 @@ Puppet::Type.type(:selboolean).provide(:getsetsebool) do
status = getsebool(@resource[:name])
- if status =~ / off$/ then
+ if status =~ / off$/
return :off
elsif status =~ / on$/ then
return :on
diff --git a/lib/puppet/provider/selmodule/semodule.rb b/lib/puppet/provider/selmodule/semodule.rb
index 2f2416b4b..2f88d3dfe 100644
--- a/lib/puppet/provider/selmodule/semodule.rb
+++ b/lib/puppet/provider/selmodule/semodule.rb
@@ -39,7 +39,7 @@ Puppet::Type.type(:selmodule).provide(:semodule) do
if(loadver) then
filever = selmodversion_file
- if (filever == loadver) then
+ if (filever == loadver)
return :true
end
end
@@ -89,13 +89,9 @@ Puppet::Type.type(:selmodule).provide(:semodule) do
(hdr, ver, numsec) = mod.read(12).unpack('LLL')
- if hdr != magic
- raise Puppet::Error, "Found #{hdr} instead of magic #{magic} in #{filename}"
- end
+ raise Puppet::Error, "Found #{hdr} instead of magic #{magic} in #{filename}" if hdr != magic
- if ver != 1
- raise Puppet::Error, "Unknown policy file version #{ver} in #{filename}"
- end
+ raise Puppet::Error, "Unknown policy file version #{ver} in #{filename}" if ver != 1
# Read through (and throw away) the file section offsets, and also
# the magic header for the first section.
@@ -129,7 +125,7 @@ Puppet::Type.type(:selmodule).provide(:semodule) do
lines.each do |line|
line.chomp!
bits = line.split
- if bits[0] == @resource[:name] then
+ if bits[0] == @resource[:name]
self.debug "load version #{bits[1]}"
return bits[1]
end
diff --git a/lib/puppet/provider/service/base.rb b/lib/puppet/provider/service/base.rb
index 7428f266c..42f2ea01c 100755
--- a/lib/puppet/provider/service/base.rb
+++ b/lib/puppet/provider/service/base.rb
@@ -18,13 +18,9 @@ Puppet::Type.type(:service).provide :base do
# Get the process ID for a running process. Requires the 'pattern'
# parameter.
def getpid
- unless @resource[:pattern]
- @resource.fail "Either stop/status commands or a pattern must be specified"
- end
+ @resource.fail "Either stop/status commands or a pattern must be specified" unless @resource[:pattern]
ps = Facter["ps"].value
- unless ps and ps != ""
- @resource.fail "You must upgrade Facter to a version that includes 'ps'"
- end
+ @resource.fail "You must upgrade Facter to a version that includes 'ps'" unless ps and ps != ""
regex = Regexp.new(@resource[:pattern])
self.debug "Executing '#{ps}'"
IO.popen(ps) { |table|
diff --git a/lib/puppet/provider/service/bsd.rb b/lib/puppet/provider/service/bsd.rb
index fed65591d..814dbd340 100644
--- a/lib/puppet/provider/service/bsd.rb
+++ b/lib/puppet/provider/service/bsd.rb
@@ -17,17 +17,13 @@ Puppet::Type.type(:service).provide :bsd, :parent => :init do
# remove service file from rc.conf.d to disable it
def disable
rcfile = File.join(@@rcconf_dir, @model[:name])
- if File.exists?(rcfile)
- File.delete(rcfile)
- end
+ File.delete(rcfile) if File.exists?(rcfile)
end
# if the service file exists in rc.conf.d then it's already enabled
def enabled?
rcfile = File.join(@@rcconf_dir, @model[:name])
- if File.exists?(rcfile)
- return :true
- end
+ return :true if File.exists?(rcfile)
return :false
end
@@ -35,9 +31,7 @@ Puppet::Type.type(:service).provide :bsd, :parent => :init do
# enable service by creating a service file under rc.conf.d with the
# proper contents
def enable
- if not File.exists?(@@rcconf_dir)
- Dir.mkdir(@@rcconf_dir)
- end
+ Dir.mkdir(@@rcconf_dir) if not File.exists?(@@rcconf_dir)
rcfile = File.join(@@rcconf_dir, @model[:name])
open(rcfile, 'w') { |f| f << "%s_enable=\"YES\"\n" % @model[:name] }
end
diff --git a/lib/puppet/provider/service/freebsd.rb b/lib/puppet/provider/service/freebsd.rb
index 32f8abb7c..05383a998 100644
--- a/lib/puppet/provider/service/freebsd.rb
+++ b/lib/puppet/provider/service/freebsd.rb
@@ -56,9 +56,7 @@ Puppet::Type.type(:service).provide :freebsd, :parent => :init do
service = self.service_name
rcvar = self.rcvar_name
self.debug("Editing rc files: setting #{rcvar} to #{yesno} for #{service}")
- if not self.rc_replace(service, rcvar, yesno)
- self.rc_add(service, rcvar, yesno)
- end
+ self.rc_add(service, rcvar, yesno) if not self.rc_replace(service, rcvar, yesno)
end
# Try to find an existing setting in the rc files
@@ -106,7 +104,7 @@ Puppet::Type.type(:service).provide :freebsd, :parent => :init do
end
def enabled?
- if /YES$/ =~ self.rcvar_value then
+ if /YES$/ =~ self.rcvar_value
self.debug("Is enabled")
return :true
end
diff --git a/lib/puppet/provider/service/init.rb b/lib/puppet/provider/service/init.rb
index d5dc21477..17d3bad36 100755
--- a/lib/puppet/provider/service/init.rb
+++ b/lib/puppet/provider/service/init.rb
@@ -42,9 +42,7 @@ Puppet::Type.type(:service).provide :init, :parent => :base do
check = [:ensure]
- if public_method_defined? :enabled?
- check << :enable
- end
+ check << :enable if public_method_defined? :enabled?
Dir.entries(path).each do |name|
fullpath = File.join(path, name)
diff --git a/lib/puppet/provider/service/launchd.rb b/lib/puppet/provider/service/launchd.rb
index 635c30b49..1813f2cfb 100644
--- a/lib/puppet/provider/service/launchd.rb
+++ b/lib/puppet/provider/service/launchd.rb
@@ -75,9 +75,7 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
end
# if we didn't find the job above and we should have, error.
- if label
- raise Puppet::Error.new("Unable to find launchd plist for job: #{label}")
- end
+ raise Puppet::Error.new("Unable to find launchd plist for job: #{label}") if label
# if returning all jobs
label_to_path_map
end
@@ -92,9 +90,7 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
def self.get_macosx_version_major
- if defined?(@macosx_version_major)
- return @macosx_version_major
- end
+ return @macosx_version_major if defined?(@macosx_version_major)
begin
# Make sure we've loaded all of the facts
Facter.loadfacts
@@ -105,14 +101,10 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
# TODO: remove this code chunk once we require Facter 1.5.5 or higher.
Puppet.warning("DEPRECATION WARNING: Future versions of the launchd provider will require Facter 1.5.5 or newer.")
product_version = Facter.value(:macosx_productversion)
- if product_version.nil?
- fail("Could not determine OS X version from Facter")
- end
+ fail("Could not determine OS X version from Facter") if product_version.nil?
product_version_major = product_version.scan(/(\d+)\.(\d+)./).join(".")
end
- if %w{10.0 10.1 10.2 10.3}.include?(product_version_major)
- fail("#{product_version_major} is not supported by the launchd provider")
- end
+ fail("#{product_version_major} is not supported by the launchd provider") if %w{10.0 10.1 10.2 10.3}.include?(product_version_major)
@macosx_version_major = product_version_major
return @macosx_version_major
rescue Puppet::ExecutionFailure => detail
@@ -127,9 +119,7 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
job = self.class.jobsearch(label)
job_path = job[label]
job_plist = Plist::parse_xml(job_path)
- if not job_plist
- raise Puppet::Error.new("Unable to parse launchd plist at path: #{job_path}")
- end
+ raise Puppet::Error.new("Unable to parse launchd plist at path: #{job_path}") if not job_plist
[job_path, job_plist]
end
@@ -142,9 +132,7 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
# between 10.4 and 10.5, thus the necessity for splitting
begin
output = launchctl :list
- if output.nil?
- raise Puppet::Error.new("launchctl list failed to return any data.")
- end
+ raise Puppet::Error.new("launchctl list failed to return any data.") if output.nil?
output.split("\n").each do |j|
return :running if j.split(/\s/).last == resource[:name]
end
@@ -174,9 +162,7 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
raise Puppet::Error.new("Unable to start service: #{resource[:name]} at path: #{job_path}")
end
# As load -w clears the Disabled flag, we need to add it in after
- if did_enable_job and resource[:enable] == :false
- self.disable
- end
+ self.disable if did_enable_job and resource[:enable] == :false
end
@@ -196,9 +182,7 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
raise Puppet::Error.new("Unable to stop service: #{resource[:name]} at path: #{job_path}")
end
# As unload -w sets the Disabled flag, we need to add it in after
- if did_disable_job and resource[:enable] == :true
- self.enable
- end
+ self.enable if did_disable_job and resource[:enable] == :true
end
@@ -213,18 +197,14 @@ Puppet::Type.type(:service).provide :launchd, :parent => :base do
overrides_disabled = nil
job_path, job_plist = plist_from_label(resource[:name])
- if job_plist.has_key?("Disabled")
- job_plist_disabled = job_plist["Disabled"]
- end
+ job_plist_disabled = job_plist["Disabled"] if job_plist.has_key?("Disabled")
if self.class.get_macosx_version_major == "10.6":
overrides = Plist::parse_xml(Launchd_Overrides)
unless overrides.nil?
if overrides.has_key?(resource[:name])
- if overrides[resource[:name]].has_key?("Disabled")
- overrides_disabled = overrides[resource[:name]]["Disabled"]
- end
+ overrides_disabled = overrides[resource[:name]]["Disabled"] if overrides[resource[:name]].has_key?("Disabled")
end
end
end
diff --git a/lib/puppet/provider/user/ldap.rb b/lib/puppet/provider/user/ldap.rb
index 888d3bfd7..03fa0d376 100644
--- a/lib/puppet/provider/user/ldap.rb
+++ b/lib/puppet/provider/user/ldap.rb
@@ -39,9 +39,7 @@ Puppet::Type.type(:user).provide :ldap, :parent => Puppet::Provider::Ldap do
existing.each do |hash|
next unless value = hash[:uid]
num = value[0].to_i
- if num > largest
- largest = num
- end
+ largest = num if num > largest
end
end
largest + 1
@@ -49,9 +47,7 @@ Puppet::Type.type(:user).provide :ldap, :parent => Puppet::Provider::Ldap do
# Convert our gid to a group name, if necessary.
def gid=(value)
- unless [Fixnum, Bignum].include?(value.class)
- value = group2id(value)
- end
+ value = group2id(value) unless [Fixnum, Bignum].include?(value.class)
@property_hash[:gid] = value
end
diff --git a/lib/puppet/provider/user/pw.rb b/lib/puppet/provider/user/pw.rb
index a2fb52fa8..cee136ec8 100644
--- a/lib/puppet/provider/user/pw.rb
+++ b/lib/puppet/provider/user/pw.rb
@@ -31,13 +31,9 @@ Puppet::Type.type(:user).provide :pw, :parent => Puppet::Provider::NameService::
end
end
- if @resource.allowdupe?
- cmd << "-o"
- end
+ cmd << "-o" if @resource.allowdupe?
- if @resource.managehome?
- cmd << "-m"
- end
+ cmd << "-m" if @resource.managehome?
return cmd
end
diff --git a/lib/puppet/provider/user/user_role_add.rb b/lib/puppet/provider/user/user_role_add.rb
index 126b95e95..880a18b66 100644
--- a/lib/puppet/provider/user/user_role_add.rb
+++ b/lib/puppet/provider/user/user_role_add.rb
@@ -53,9 +53,7 @@ Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd, :source =>
end
def command(cmd)
- if is_role? or (!exists? and @resource[:ensure] == :role)
- cmd = ("role_#{cmd}").intern
- end
+ cmd = ("role_#{cmd}").intern if is_role? or (!exists? and @resource[:ensure] == :role)
super(cmd)
end
@@ -85,9 +83,7 @@ Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd, :source =>
run(addcmd, "create")
end
# added to handle case when password is specified
- if @resource[:password]
- self.password = @resource[:password]
- end
+ self.password = @resource[:password] if @resource[:password]
end
def destroy
@@ -103,27 +99,19 @@ Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd, :source =>
end
def roles
- if user_attributes
- user_attributes[:roles]
- end
+ user_attributes[:roles] if user_attributes
end
def auths
- if user_attributes
- user_attributes[:auths]
- end
+ user_attributes[:auths] if user_attributes
end
def profiles
- if user_attributes
- user_attributes[:profiles]
- end
+ user_attributes[:profiles] if user_attributes
end
def project
- if user_attributes
- user_attributes[:project]
- end
+ user_attributes[:project] if user_attributes
end
def managed_attributes
@@ -170,7 +158,7 @@ Puppet::Type.type(:user).provide :user_role_add, :parent => :useradd, :source =>
begin
File.open("/etc/shadow", "r") do |shadow|
File.open("/etc/shadow_tmp", "w", 0600) do |shadow_tmp|
- while line = shadow.gets do
+ while line = shadow.gets
line_arr = line.split(':')
if line_arr[0] == @resource[:name]
line_arr[1] = cryptopw
diff --git a/lib/puppet/provider/user/useradd.rb b/lib/puppet/provider/user/useradd.rb
index fc5eabcbc..e6c9aa5f4 100644
--- a/lib/puppet/provider/user/useradd.rb
+++ b/lib/puppet/provider/user/useradd.rb
@@ -19,9 +19,7 @@ Puppet::Type.type(:user).provide :useradd, :parent => Puppet::Provider::NameServ
has_features :manages_homedir, :allows_duplicates
- if Puppet.features.libshadow?
- has_feature :manages_passwords
- end
+ has_feature :manages_passwords if Puppet.features.libshadow?
def check_allow_dup
@resource.allowdupe? ? ["-o"] : []
diff --git a/lib/puppet/provider/zone/solaris.rb b/lib/puppet/provider/zone/solaris.rb
index a5345e457..e35db6f56 100644
--- a/lib/puppet/provider/zone/solaris.rb
+++ b/lib/puppet/provider/zone/solaris.rb
@@ -17,9 +17,7 @@ Puppet::Type.type(:zone).provide(:solaris) do
}
# Configured but not installed zones do not have IDs
- if properties[:id] == "-"
- properties.delete(:id)
- end
+ properties.delete(:id) if properties[:id] == "-"
properties[:ensure] = symbolize(properties[:ensure])
@@ -42,9 +40,7 @@ Puppet::Type.type(:zone).provide(:solaris) do
# Then perform all of our configuration steps. It's annoying
# that we need this much internal info on the resource.
@resource.send(:properties).each do |property|
- if property.is_a? ZoneConfigProperty and ! property.insync?(properties[property.name])
- str += property.configtext + "\n"
- end
+ str += property.configtext + "\n" if property.is_a? ZoneConfigProperty and ! property.insync?(properties[property.name])
end
str += "commit\n"
@@ -121,9 +117,7 @@ Puppet::Type.type(:zone).provide(:solaris) do
hash[$1.intern] = $2
when /^\s+(\S+):\s*(.+)$/
if name
- unless hash.include? name
- hash[name] = []
- end
+ hash[name] = [] unless hash.include? name
unless current
current = {}
@@ -171,9 +165,7 @@ Puppet::Type.type(:zone).provide(:solaris) do
f.puts cfg
end
rescue => detail
- if Puppet[:debug]
- puts detail.stacktrace
- end
+ puts detail.stacktrace if Puppet[:debug]
raise Puppet::Error, "Could not create sysidcfg: #{detail}"
end
end
diff --git a/lib/puppet/provider/zpool/solaris.rb b/lib/puppet/provider/zpool/solaris.rb
index a54af3df8..bfd37085a 100644
--- a/lib/puppet/provider/zpool/solaris.rb
+++ b/lib/puppet/provider/zpool/solaris.rb
@@ -46,9 +46,7 @@ Puppet::Type.type(:zpool).provide(:solaris) do
end
def current_pool
- unless (defined?(@current_pool) and @current_pool)
- @current_pool = process_zpool_data(get_pool_data)
- end
+ @current_pool = process_zpool_data(get_pool_data) unless (defined?(@current_pool) and @current_pool)
@current_pool
end
diff --git a/lib/puppet/rails.rb b/lib/puppet/rails.rb
index 33abe8d8a..43978ab39 100644
--- a/lib/puppet/rails.rb
+++ b/lib/puppet/rails.rb
@@ -33,9 +33,7 @@ module Puppet::Rails
Puppet.info "Connecting to #{args[:adapter]} database: #{args[:database]}"
ActiveRecord::Base.establish_connection(args)
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
raise Puppet::Error, "Could not connect to database: #{detail}"
end
end
@@ -78,9 +76,7 @@ module Puppet::Rails
# Set up our database connection. It'd be nice to have a "use" system
# that could make callbacks.
def self.init
- unless Puppet.features.rails?
- raise Puppet::DevError, "No activerecord, cannot init Puppet::Rails"
- end
+ raise Puppet::DevError, "No activerecord, cannot init Puppet::Rails" unless Puppet.features.rails?
connect()
@@ -89,9 +85,7 @@ module Puppet::Rails
Puppet::Rails::Schema.init
end
- if Puppet[:dbmigrate]
- migrate()
- end
+ migrate() if Puppet[:dbmigrate]
end
# Migrate to the latest db schema.
@@ -105,40 +99,30 @@ module Puppet::Rails
end
}
- unless dbdir
- raise Puppet::Error, "Could not find Puppet::Rails database dir"
- end
+ raise Puppet::Error, "Could not find Puppet::Rails database dir" unless dbdir
- unless ActiveRecord::Base.connection.tables.include?("resources")
- raise Puppet::Error, "Database has problems, can't migrate."
- end
+ raise Puppet::Error, "Database has problems, can't migrate." unless ActiveRecord::Base.connection.tables.include?("resources")
Puppet.notice "Migrating"
begin
ActiveRecord::Migrator.migrate(dbdir)
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
raise Puppet::Error, "Could not migrate database: #{detail}"
end
end
# Tear down the database. Mostly only used during testing.
def self.teardown
- unless Puppet.features.rails?
- raise Puppet::DevError, "No activerecord, cannot init Puppet::Rails"
- end
+ raise Puppet::DevError, "No activerecord, cannot init Puppet::Rails" unless Puppet.features.rails?
Puppet.settings.use(:master, :rails)
begin
ActiveRecord::Base.establish_connection(database_arguments())
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
raise Puppet::Error, "Could not connect to database: #{detail}"
end
@@ -148,7 +132,5 @@ module Puppet::Rails
end
end
-if Puppet.features.rails?
- require 'puppet/rails/host'
-end
+require 'puppet/rails/host' if Puppet.features.rails?
diff --git a/lib/puppet/rails/benchmark.rb b/lib/puppet/rails/benchmark.rb
index 72ffa7443..35e6fdcef 100644
--- a/lib/puppet/rails/benchmark.rb
+++ b/lib/puppet/rails/benchmark.rb
@@ -16,9 +16,7 @@ module Puppet::Rails::Benchmark
end
def debug_benchmark(message)
- unless Puppet::Rails::TIME_DEBUG
- return yield
- end
+ return yield unless Puppet::Rails::TIME_DEBUG
railsmark(message) { yield }
end
@@ -28,9 +26,7 @@ module Puppet::Rails::Benchmark
# These are always low-level debugging so we only
# print them if time_debug is enabled.
def accumulate_benchmark(message, label)
- unless time_debug?
- return yield
- end
+ return yield unless time_debug?
$benchmarks[:accumulated][message] ||= Hash.new(0)
$benchmarks[:accumulated][message][label] += Benchmark.realtime { yield }
@@ -40,9 +36,7 @@ module Puppet::Rails::Benchmark
def log_accumulated_marks(message)
return unless time_debug?
- if $benchmarks[:accumulated].empty? or $benchmarks[:accumulated][message].nil? or $benchmarks[:accumulated][message].empty?
- return
- end
+ return if $benchmarks[:accumulated].empty? or $benchmarks[:accumulated][message].nil? or $benchmarks[:accumulated][message].empty?
$benchmarks[:accumulated][message].each do |label, value|
Puppet.debug(message + ("(#{label})") + (" in %0.2f seconds" % value))
diff --git a/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb b/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb
index 138f9f151..65432a6b7 100644
--- a/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb
+++ b/lib/puppet/rails/database/001_add_created_at_to_all_tables.rb
@@ -1,17 +1,13 @@
class AddCreatedAtToAllTables < ActiveRecord::Migration
def self.up
ActiveRecord::Base.connection.tables.each do |t|
- unless ActiveRecord::Base.connection.columns(t).collect {|c| c.name}.include?("created_at")
- add_column t.to_s, :created_at, :datetime
- end
+ add_column t.to_s, :created_at, :datetime unless ActiveRecord::Base.connection.columns(t).collect {|c| c.name}.include?("created_at")
end
end
def self.down
ActiveRecord::Base.connection.tables.each do |t|
- unless ActiveRecord::Base.connection.columns(t).collect {|c| c.name}.include?("created_at")
- remove_column t.to_s, :created_at
- end
+ remove_column t.to_s, :created_at unless ActiveRecord::Base.connection.columns(t).collect {|c| c.name}.include?("created_at")
end
end
end
diff --git a/lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb b/lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb
index 050ca7f43..c1e60db14 100644
--- a/lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb
+++ b/lib/puppet/rails/database/002_remove_duplicated_index_on_all_tables.rb
@@ -1,17 +1,13 @@
class RemoveDuplicatedIndexOnAllTables < ActiveRecord::Migration
def self.up
ActiveRecord::Base.connection.tables.each do |t|
- if ActiveRecord::Base.connection.indexes(t).collect {|c| c.columns}.include?("id")
- remove_index t.to_s, :id
- end
+ remove_index t.to_s, :id if ActiveRecord::Base.connection.indexes(t).collect {|c| c.columns}.include?("id")
end
end
def self.down
ActiveRecord::Base.connection.tables.each do |t|
- unless ActiveRecord::Base.connection.indexes(t).collect {|c| c.columns}.include?("id")
- add_index t.to_s, :id, :integer => true
- end
+ add_index t.to_s, :id, :integer => true unless ActiveRecord::Base.connection.indexes(t).collect {|c| c.columns}.include?("id")
end
end
end
diff --git a/lib/puppet/rails/database/003_add_environment_to_host.rb b/lib/puppet/rails/database/003_add_environment_to_host.rb
index 4ab2fbc63..95f036d11 100644
--- a/lib/puppet/rails/database/003_add_environment_to_host.rb
+++ b/lib/puppet/rails/database/003_add_environment_to_host.rb
@@ -1,13 +1,9 @@
class AddEnvironmentToHost < ActiveRecord::Migration
def self.up
- unless ActiveRecord::Base.connection.columns(:hosts).collect {|c| c.name}.include?("environment")
- add_column :hosts, :environment, :string
- end
+ add_column :hosts, :environment, :string unless ActiveRecord::Base.connection.columns(:hosts).collect {|c| c.name}.include?("environment")
end
def self.down
- if ActiveRecord::Base.connection.columns(:hosts).collect {|c| c.name}.include?("environment")
- remove_column :hosts, :environment
- end
+ remove_column :hosts, :environment if ActiveRecord::Base.connection.columns(:hosts).collect {|c| c.name}.include?("environment")
end
end
diff --git a/lib/puppet/rails/database/schema.rb b/lib/puppet/rails/database/schema.rb
index a2477f2e6..8cb7350eb 100644
--- a/lib/puppet/rails/database/schema.rb
+++ b/lib/puppet/rails/database/schema.rb
@@ -52,9 +52,7 @@ class Puppet::Rails::Schema
end
# Oracle automatically creates a primary key index
- if Puppet[:dbadapter] != "oracle_enhanced"
- add_index :puppet_tags, :id, :integer => true
- end
+ add_index :puppet_tags, :id, :integer => true if Puppet[:dbadapter] != "oracle_enhanced"
create_table :hosts do |t|
t.column :name, :string, :null => false
diff --git a/lib/puppet/rails/resource.rb b/lib/puppet/rails/resource.rb
index f2c41c17e..0a9172a42 100644
--- a/lib/puppet/rails/resource.rb
+++ b/lib/puppet/rails/resource.rb
@@ -102,15 +102,11 @@ class Puppet::Rails::Resource < ActiveRecord::Base
def merge_attributes(resource)
args = self.class.rails_resource_initial_args(resource)
args.each do |param, value|
- unless resource[param] == value
- self[param] = value
- end
+ self[param] = value unless resource[param] == value
end
# Handle file specially
- if (resource.file and (!resource.file or self.file != resource.file))
- self.file = resource.file
- end
+ self.file = resource.file if (resource.file and (!resource.file or self.file != resource.file))
end
def merge_parameters(resource)
@@ -138,9 +134,7 @@ class Puppet::Rails::Resource < ActiveRecord::Base
db_params.each do |name, value_hashes|
values = value_hashes.collect { |v| v['value'] }
- unless value_compare(catalog_params[name], values)
- value_hashes.each { |v| deletions << v['id'] }
- end
+ value_hashes.each { |v| deletions << v['id'] } unless value_compare(catalog_params[name], values)
end
# Perform our deletions.
diff --git a/lib/puppet/reference/providers.rb b/lib/puppet/reference/providers.rb
index cc47876d6..b19549350 100644
--- a/lib/puppet/reference/providers.rb
+++ b/lib/puppet/reference/providers.rb
@@ -9,9 +9,7 @@ providers = Puppet::Util::Reference.newreference :providers, :title => "Provider
types.sort! { |a,b| a.name.to_s <=> b.name.to_s }
command_line = Puppet::Util::CommandLine.new
- unless command_line.args.empty?
- types.reject! { |type| ! command_line.args.include?(type.name.to_s) }
- end
+ types.reject! { |type| ! command_line.args.include?(type.name.to_s) } unless command_line.args.empty?
ret = "Details about this host:\n\n"
diff --git a/lib/puppet/reference/type.rb b/lib/puppet/reference/type.rb
index 6bd8be835..c52e764d6 100644
--- a/lib/puppet/reference/type.rb
+++ b/lib/puppet/reference/type.rb
@@ -78,9 +78,7 @@ type = Puppet::Util::Reference.newreference :type, :doc => "All Puppet resource
}.each { |sname|
property = type.propertybyname(sname)
- unless property
- raise "Could not retrieve property #{sname} on type #{type.name}"
- end
+ raise "Could not retrieve property #{sname} on type #{type.name}" unless property
doc = nil
unless doc = property.doc
diff --git a/lib/puppet/relationship.rb b/lib/puppet/relationship.rb
index ea91d0e69..b3908701c 100644
--- a/lib/puppet/relationship.rb
+++ b/lib/puppet/relationship.rb
@@ -33,9 +33,7 @@ class Puppet::Relationship
end
def event=(event)
- if event != :NONE and ! callback
- raise ArgumentError, "You must pass a callback for non-NONE events"
- end
+ raise ArgumentError, "You must pass a callback for non-NONE events" if event != :NONE and ! callback
@event = event
end
diff --git a/lib/puppet/reports.rb b/lib/puppet/reports.rb
index 8407d67de..2e1f1e2ce 100755
--- a/lib/puppet/reports.rb
+++ b/lib/puppet/reports.rb
@@ -18,9 +18,7 @@ class Puppet::Reports
mod = genmodule(name, :extend => Puppet::Util::Docs, :hash => instance_hash(:report), :block => block)
- if options[:useyaml]
- mod.useyaml = true
- end
+ mod.useyaml = true if options[:useyaml]
mod.send(:define_method, :report_name) do
name
diff --git a/lib/puppet/reports/rrdgraph.rb b/lib/puppet/reports/rrdgraph.rb
index 4e618d5ee..e478912b2 100644
--- a/lib/puppet/reports/rrdgraph.rb
+++ b/lib/puppet/reports/rrdgraph.rb
@@ -22,9 +22,7 @@ Puppet::Reports.register_report(:rrdgraph) do
which defaults to the ``runinterval``."
def hostdir
- unless defined?(@hostdir)
- @hostdir = File.join(Puppet[:rrddir], self.host)
- end
+ @hostdir = File.join(Puppet[:rrddir], self.host) unless defined?(@hostdir)
@hostdir
end
@@ -118,9 +116,7 @@ Puppet::Reports.register_report(:rrdgraph) do
metric.graph
end
- unless FileTest.exists?(File.join(hostdir, "index.html"))
- mkhtml()
- end
+ mkhtml() unless FileTest.exists?(File.join(hostdir, "index.html"))
end
# Unfortunately, RRD does not deal well with changing lists of values,
diff --git a/lib/puppet/reports/store.rb b/lib/puppet/reports/store.rb
index 547b45a33..aa99a7260 100644
--- a/lib/puppet/reports/store.rb
+++ b/lib/puppet/reports/store.rb
@@ -33,9 +33,7 @@ Puppet::Reports.register_report(:store) do
dir = File.join(Puppet[:reportdir], client)
- unless FileTest.exists?(dir)
- mkclientdir(client, dir)
- end
+ mkclientdir(client, dir) unless FileTest.exists?(dir)
# Now store the report.
now = Time.now.gmtime
@@ -51,9 +49,7 @@ Puppet::Reports.register_report(:store) do
f.print to_yaml
end
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.warning "Could not write report for #{client} at #{file}: #{detail}"
end
diff --git a/lib/puppet/reports/tagmail.rb b/lib/puppet/reports/tagmail.rb
index 270cadb91..1e6c52bfc 100644
--- a/lib/puppet/reports/tagmail.rb
+++ b/lib/puppet/reports/tagmail.rb
@@ -53,9 +53,7 @@ Puppet::Reports.register_report(:tagmail) do
# Now go through and remove any messages that match our negative tags
messages = messages.reject do |log|
- if neg.detect do |tag| log.tagged?(tag) end
- true
- end
+ true if neg.detect do |tag| log.tagged?(tag) end
end
if messages.empty?
@@ -138,9 +136,7 @@ Puppet::Reports.register_report(:tagmail) do
end
end
rescue => detail
- if Puppet[:debug]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:debug]
raise Puppet::Error,
"Could not send report emails through smtp: #{detail}"
end
@@ -157,9 +153,7 @@ Puppet::Reports.register_report(:tagmail) do
end
end
rescue => detail
- if Puppet[:debug]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:debug]
raise Puppet::Error,
"Could not send report emails via sendmail: #{detail}"
end
diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
index 8d1fb39a2..6cd35b0a2 100644
--- a/lib/puppet/resource.rb
+++ b/lib/puppet/resource.rb
@@ -174,9 +174,7 @@ class Puppet::Resource
tag(self.type)
tag(self.title) if valid_tag?(self.title)
- if strict? and ! resource_type
- raise ArgumentError, "Invalid resource type #{type}"
- end
+ raise ArgumentError, "Invalid resource type #{type}" if strict? and ! resource_type
end
def ref
@@ -275,9 +273,7 @@ class Puppet::Resource
v = v.to_trans_ref
elsif v.is_a?(Array)
v = v.collect { |av|
- if av.is_a?(Puppet::Resource)
- av = av.to_trans_ref
- end
+ av = av.to_trans_ref if av.is_a?(Puppet::Resource)
av
}
end
diff --git a/lib/puppet/resource/catalog.rb b/lib/puppet/resource/catalog.rb
index 98a380e87..12bbffcc5 100644
--- a/lib/puppet/resource/catalog.rb
+++ b/lib/puppet/resource/catalog.rb
@@ -70,9 +70,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
# * Add any aliases that make sense for the resource (e.g., name != title)
def add_resource(*resources)
resources.each do |resource|
- unless resource.respond_to?(:ref)
- raise ArgumentError, "Can only add objects that respond to :ref, not instances of #{resource.class}"
- end
+ raise ArgumentError, "Can only add objects that respond to :ref, not instances of #{resource.class}" unless resource.respond_to?(:ref)
end.each { |resource| fail_on_duplicate_type_and_title(resource) }.each do |resource|
title_key = title_key_for_ref(resource.ref)
@@ -89,9 +87,7 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
add_vertex(resource)
- if @relationship_graph
- @relationship_graph.add_vertex(resource)
- end
+ @relationship_graph.add_vertex(resource) if @relationship_graph
yield(resource) if block_given?
end
@@ -237,16 +233,12 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
end
bucket = tmp || bucket
if child = target.to_trans
- unless bucket
- raise "No bucket created for #{source}"
- end
+ raise "No bucket created for #{source}" unless bucket
bucket.push child
# It's important that we keep a reference to any TransBuckets we've created, so
# we don't create multiple buckets for children.
- unless target.builtin?
- buckets[target.to_s] = child
- end
+ buckets[target.to_s] = child unless target.builtin?
end
end
@@ -518,13 +510,9 @@ class Puppet::Resource::Catalog < Puppet::SimpleGraph
# If we've gotten this far, it's a real conflict
msg = "Duplicate definition: #{resource.ref} is already defined"
- if existing_resource.file and existing_resource.line
- msg << " in file #{existing_resource.file} at line #{existing_resource.line}"
- end
+ msg << " in file #{existing_resource.file} at line #{existing_resource.line}" if existing_resource.file and existing_resource.line
- if resource.line or resource.file
- msg << "; cannot redefine"
- end
+ msg << "; cannot redefine" if resource.line or resource.file
raise DuplicateResourceError.new(msg)
end
diff --git a/lib/puppet/resource/type.rb b/lib/puppet/resource/type.rb
index a6cab8b8b..684d2c2f9 100644
--- a/lib/puppet/resource/type.rb
+++ b/lib/puppet/resource/type.rb
@@ -129,9 +129,7 @@ class Puppet::Resource::Type
end
array_class = Puppet::Parser::AST::ASTArray
- unless self.code.is_a?(array_class)
- self.code = array_class.new(:children => [self.code])
- end
+ self.code = array_class.new(:children => [self.code]) unless self.code.is_a?(array_class)
if other.code.is_a?(array_class)
code.children += other.code.children
@@ -148,9 +146,7 @@ class Puppet::Resource::Type
resource_type = type == :hostclass ? :class : :node
# Make sure our parent class has been evaluated, if we have one.
- if parent and ! scope.catalog.resource(resource_type, parent)
- parent_type.mk_plain_resource(scope)
- end
+ parent_type.mk_plain_resource(scope) if parent and ! scope.catalog.resource(resource_type, parent)
# Do nothing if the resource already exists; this makes sure we don't
# get multiple copies of the class resource, which helps provide the
diff --git a/lib/puppet/run.rb b/lib/puppet/run.rb
index 1a1a98332..028545961 100644
--- a/lib/puppet/run.rb
+++ b/lib/puppet/run.rb
@@ -38,9 +38,7 @@ class Puppet::Run
msg += " with tags #{options[:tags].inspect}"
end
- if options[:ignoreschedules]
- msg += " ignoring schedules"
- end
+ msg += " ignoring schedules" if options[:ignoreschedules]
Puppet.notice msg
end
diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb
index aeb70af2e..ea189466f 100644
--- a/lib/puppet/simple_graph.rb
+++ b/lib/puppet/simple_graph.rb
@@ -28,9 +28,7 @@ class Puppet::SimpleGraph
direction = options[:direction] || :out
options[:type] ||= :vertices
- if options[:type] == :edges
- return send(direction.to_s + "_edges")
- end
+ return send(direction.to_s + "_edges") if options[:type] == :edges
return @adjacencies[direction].keys.reject { |vertex| @adjacencies[direction][vertex].empty? }
end
@@ -122,9 +120,7 @@ class Puppet::SimpleGraph
def dependencies(resource)
# Cache the reversal graph, because it's somewhat expensive
# to create.
- unless defined?(@reversal) and @reversal
- @reversal = reversal
- end
+ @reversal = reversal unless defined?(@reversal) and @reversal
# Strangely, it's significantly faster to search a reversed
# tree in the :out direction than to search a normal tree
# in the :in direction.
@@ -196,7 +192,7 @@ class Puppet::SimpleGraph
# Iterate over each 0-degree vertex, decrementing the degree of
# each of its out-edges.
- while wrapper = zeros.pop do
+ while wrapper = zeros.pop
result << wrapper.vertex
wrapper.out_edges.each do |edge|
degree[edge.target].delete(edge)
diff --git a/lib/puppet/ssl/certificate_authority.rb b/lib/puppet/ssl/certificate_authority.rb
index b66725cbf..8a3d0b4d5 100644
--- a/lib/puppet/ssl/certificate_authority.rb
+++ b/lib/puppet/ssl/certificate_authority.rb
@@ -50,9 +50,7 @@ class Puppet::SSL::CertificateAuthority
# Create and run an applicator. I wanted to build an interface where you could do
# something like 'ca.apply(:generate).to(:all) but I don't think it's really possible.
def apply(method, options)
- unless options[:to]
- raise ArgumentError, "You must specify the hosts to apply to; valid values are an array or the symbol :all"
- end
+ raise ArgumentError, "You must specify the hosts to apply to; valid values are an array or the symbol :all" unless options[:to]
applier = Interface.new(method, options)
applier.apply(self)
@@ -63,9 +61,7 @@ class Puppet::SSL::CertificateAuthority
return unless auto = autosign?
store = nil
- if auto != true
- store = autosign_store(auto)
- end
+ store = autosign_store(auto) if auto != true
Puppet::SSL::CertificateRequest.search("*").each do |csr|
sign(csr.name) if auto == true or store.allowed?(csr.name, "127.1.1.1")
@@ -156,9 +152,7 @@ class Puppet::SSL::CertificateAuthority
# Retrieve (or create, if necessary) our inventory manager.
def inventory
- unless defined?(@inventory)
- @inventory = Puppet::SSL::Inventory.new
- end
+ @inventory = Puppet::SSL::Inventory.new unless defined?(@inventory)
@inventory
end
@@ -191,14 +185,10 @@ class Puppet::SSL::CertificateAuthority
# This is slightly odd. If the file doesn't exist, our readwritelock creates
# it, but with a mode we can't actually read in some cases. So, use
# a default before the lock.
- unless FileTest.exist?(Puppet[:serial])
- serial = 0x1
- end
+ serial = 0x1 unless FileTest.exist?(Puppet[:serial])
Puppet.settings.readwritelock(:serial) { |f|
- if FileTest.exist?(Puppet[:serial])
- serial ||= File.read(Puppet.settings[:serial]).chomp.hex
- end
+ serial ||= File.read(Puppet.settings[:serial]).chomp.hex if FileTest.exist?(Puppet[:serial])
# We store the next valid serial, not the one we just used.
f << "%04X" % (serial + 1)
@@ -286,9 +276,7 @@ class Puppet::SSL::CertificateAuthority
store.purpose = OpenSSL::X509::PURPOSE_SSL_CLIENT
store.flags = OpenSSL::X509::V_FLAG_CRL_CHECK_ALL|OpenSSL::X509::V_FLAG_CRL_CHECK if Puppet.settings[:certificate_revocation]
- unless store.verify(cert.content)
- raise CertificateVerificationError.new(store.error), store.error_string
- end
+ raise CertificateVerificationError.new(store.error), store.error_string unless store.verify(cert.content)
end
def fingerprint(name, md = :MD5)
diff --git a/lib/puppet/ssl/certificate_authority/interface.rb b/lib/puppet/ssl/certificate_authority/interface.rb
index 64e983cf6..e5ede3c6c 100644
--- a/lib/puppet/ssl/certificate_authority/interface.rb
+++ b/lib/puppet/ssl/certificate_authority/interface.rb
@@ -18,9 +18,7 @@ module Puppet
end
begin
- if respond_to?(method)
- return send(method, ca)
- end
+ return send(method, ca) if respond_to?(method)
(subjects == :all ? ca.list : subjects).each do |host|
ca.send(method, host)
@@ -125,9 +123,7 @@ module Puppet
raise ArgumentError, "Subjects must be an array or :all; not #{value}"
end
- if value.is_a?(Array) and value.empty?
- value = nil
- end
+ value = nil if value.is_a?(Array) and value.empty?
@subjects = value
end
diff --git a/lib/puppet/ssl/host.rb b/lib/puppet/ssl/host.rb
index 6d1ae1a16..2b1db7e42 100644
--- a/lib/puppet/ssl/host.rb
+++ b/lib/puppet/ssl/host.rb
@@ -246,7 +246,7 @@ class Puppet::SSL::Host
exit(1)
end
- while true do
+ while true
sleep time
begin
break if certificate
diff --git a/lib/puppet/sslcertificates.rb b/lib/puppet/sslcertificates.rb
index 6a0d19ca2..2ce782293 100755
--- a/lib/puppet/sslcertificates.rb
+++ b/lib/puppet/sslcertificates.rb
@@ -8,9 +8,7 @@ module Puppet::SSLCertificates
#def self.mkcert(type, name, dnsnames, ttl, issuercert, issuername, serial, publickey)
def self.mkcert(hash)
[:type, :name, :ttl, :issuer, :serial, :publickey].each { |param|
- unless hash.include?(param)
- raise ArgumentError, "mkcert called without #{param}"
- end
+ raise ArgumentError, "mkcert called without #{param}" unless hash.include?(param)
}
cert = OpenSSL::X509::Certificate.new
diff --git a/lib/puppet/sslcertificates/ca.rb b/lib/puppet/sslcertificates/ca.rb
index c2ed7349f..22e14b9b9 100644
--- a/lib/puppet/sslcertificates/ca.rb
+++ b/lib/puppet/sslcertificates/ca.rb
@@ -63,9 +63,7 @@ class Puppet::SSLCertificates::CA
@config[:password] = self.getpass
else
# Don't create a password if the cert already exists
- unless FileTest.exists?(@config[:cacert])
- @config[:password] = self.genpass
- end
+ @config[:password] = self.genpass unless FileTest.exists?(@config[:cacert])
end
end
@@ -114,9 +112,7 @@ class Puppet::SSLCertificates::CA
# Retrieve a client's CSR.
def getclientcsr(host)
csrfile = host2csrfile(host)
- unless File.exists?(csrfile)
- return nil
- end
+ return nil unless File.exists?(csrfile)
return OpenSSL::X509::Request.new(File.read(csrfile))
end
@@ -124,9 +120,7 @@ class Puppet::SSLCertificates::CA
# Retrieve a client's certificate.
def getclientcert(host)
certfile = host2certfile(host)
- unless File.exists?(certfile)
- return [nil, nil]
- end
+ return [nil, nil] unless File.exists?(certfile)
return [OpenSSL::X509::Certificate.new(File.read(certfile)), @cert]
end
@@ -186,9 +180,7 @@ class Puppet::SSLCertificates::CA
def removeclientcsr(host)
csrfile = host2csrfile(host)
- unless File.exists?(csrfile)
- raise Puppet::Error, "No certificate request for #{host}"
- end
+ raise Puppet::Error, "No certificate request for #{host}" unless File.exists?(csrfile)
File.unlink(csrfile)
end
@@ -226,14 +218,10 @@ class Puppet::SSLCertificates::CA
hash.delete(:password)
end
- if hash.length > 0
- raise ArgumentError, "Unknown parameters #{hash.keys.join(",")}"
- end
+ raise ArgumentError, "Unknown parameters #{hash.keys.join(",")}" if hash.length > 0
[:cadir, :csrdir, :signeddir].each { |dir|
- unless @config[dir]
- raise Puppet::DevError, "#{dir} is undefined"
- end
+ raise Puppet::DevError, "#{dir} is undefined" unless @config[dir]
}
end
@@ -244,9 +232,7 @@ class Puppet::SSLCertificates::CA
"CA#sign only accepts OpenSSL::X509::Request objects, not #{csr.class}"
end
- unless csr.verify(csr.public_key)
- raise Puppet::Error, "CSR sign verification failed"
- end
+ raise Puppet::Error, "CSR sign verification failed" unless csr.verify(csr.public_key)
serial = nil
Puppet.settings.readwritelock(:serial) { |f|
@@ -282,9 +268,7 @@ class Puppet::SSLCertificates::CA
host = thing2name(csr)
csrfile = host2csrfile(host)
- if File.exists?(csrfile)
- raise Puppet::Error, "Certificate request for #{host} already exists"
- end
+ raise Puppet::Error, "Certificate request for #{host} already exists" if File.exists?(csrfile)
Puppet.settings.writesub(:csrdir, csrfile) do |f|
f.print csr.to_pem
@@ -296,9 +280,7 @@ class Puppet::SSLCertificates::CA
host = thing2name(cert)
certfile = host2certfile(host)
- if File.exists?(certfile)
- Puppet.notice "Overwriting signed certificate #{certfile} for #{host}"
- end
+ Puppet.notice "Overwriting signed certificate #{certfile} for #{host}" if File.exists?(certfile)
Puppet::SSLCertificates::Inventory::add(cert)
Puppet.settings.writesub(:signeddir, certfile) do |f|
@@ -391,9 +373,7 @@ class Puppet::SSLCertificates::CA
)
end
- unless @cert.check_private_key(cakey)
- raise Puppet::Error, "CA Certificate is invalid"
- end
+ raise Puppet::Error, "CA Certificate is invalid" unless @cert.check_private_key(cakey)
signable.sign(cakey, digest)
end
diff --git a/lib/puppet/sslcertificates/certificate.rb b/lib/puppet/sslcertificates/certificate.rb
index 8df7605d7..11276bfeb 100644
--- a/lib/puppet/sslcertificates/certificate.rb
+++ b/lib/puppet/sslcertificates/certificate.rb
@@ -20,15 +20,11 @@ class Puppet::SSLCertificates::Certificate
def delete
[@certfile,@keyfile].each { |file|
- if FileTest.exists?(file)
- File.unlink(file)
- end
+ File.unlink(file) if FileTest.exists?(file)
}
if defined?(@hash) and @hash
- if FileTest.symlink?(@hash)
- File.unlink(@hash)
- end
+ File.unlink(@hash) if FileTest.symlink?(@hash)
end
end
@@ -37,9 +33,7 @@ class Puppet::SSLCertificates::Certificate
end
def getkey
- unless FileTest.exists?(@keyfile)
- self.mkkey()
- end
+ self.mkkey() unless FileTest.exists?(@keyfile)
if @password
@key = OpenSSL::PKey::RSA.new(
@@ -56,9 +50,7 @@ class Puppet::SSLCertificates::Certificate
end
def initialize(hash)
- unless hash.include?(:name)
- raise Puppet::Error, "You must specify the common name for the certificate"
- end
+ raise Puppet::Error, "You must specify the common name for the certificate" unless hash.include?(:name)
@name = hash[:name]
# init a few variables
@@ -74,9 +66,7 @@ class Puppet::SSLCertificates::Certificate
@cacertfile ||= File.join(Puppet[:certdir], "ca.pem")
- unless FileTest.directory?(@dir)
- Puppet.recmkdir(@dir)
- end
+ Puppet.recmkdir(@dir) unless FileTest.directory?(@dir)
unless @certfile =~ /\.pem$/
@certfile += ".pem"
@@ -84,16 +74,12 @@ class Puppet::SSLCertificates::Certificate
@keyfile = hash[:key] || File.join(
Puppet[:privatekeydir], [@name,"pem"].join(".")
)
- unless FileTest.directory?(@dir)
- Puppet.recmkdir(@dir)
- end
+ Puppet.recmkdir(@dir) unless FileTest.directory?(@dir)
[@keyfile].each { |file|
dir = File.dirname(file)
- unless FileTest.directory?(dir)
- Puppet.recmkdir(dir)
- end
+ Puppet.recmkdir(dir) unless FileTest.directory?(dir)
}
@ttl = hash[:ttl] || 365 * 24 * 60 * 60
@@ -114,9 +100,7 @@ class Puppet::SSLCertificates::Certificate
@params = {:name => @name}
[:state, :country, :email, :org, :ou].each { |param|
- if hash.include?(param)
- @params[param] = hash[param]
- end
+ @params[param] = hash[param] if hash.include?(param)
}
if @encrypt
@@ -140,9 +124,7 @@ class Puppet::SSLCertificates::Certificate
# this only works for servers, not for users
def mkcsr
- unless defined?(@key) and @key
- self.getkey
- end
+ self.getkey unless defined?(@key) and @key
name = OpenSSL::X509::Name.new self.subject
@@ -156,9 +138,7 @@ class Puppet::SSLCertificates::Certificate
# f << @csr.to_pem
#}
- unless @csr.verify(@key.public_key)
- raise Puppet::Error, "CSR sign verification failed"
- end
+ raise Puppet::Error, "CSR sign verification failed" unless @csr.verify(@key.public_key)
return @csr
end
@@ -202,13 +182,9 @@ class Puppet::SSLCertificates::Certificate
end
def mkselfsigned
- unless defined?(@key) and @key
- self.getkey
- end
+ self.getkey unless defined?(@key) and @key
- if defined?(@cert) and @cert
- raise Puppet::Error, "Cannot replace existing certificate"
- end
+ raise Puppet::Error, "Cannot replace existing certificate" if defined?(@cert) and @cert
args = {
:name => self.certname,
@@ -231,9 +207,7 @@ class Puppet::SSLCertificates::Certificate
def subject(string = false)
subj = @@params2names.collect { |param, name|
- if @params.include?(param)
- [name, @params[param]]
- end
+ [name, @params[param]] if @params.include?(param)
}.reject { |ary| ary.nil? }
if string
@@ -255,15 +229,11 @@ class Puppet::SSLCertificates::Certificate
@certfile => @cert,
@keyfile => @key,
}
- if defined?(@cacert)
- files[@cacertfile] = @cacert
- end
+ files[@cacertfile] = @cacert if defined?(@cacert)
files.each { |file,thing|
if defined?(thing) and thing
- if FileTest.exists?(file)
- next
- end
+ next if FileTest.exists?(file)
text = nil
@@ -283,9 +253,7 @@ class Puppet::SSLCertificates::Certificate
end
}
- if defined?(@cacert)
- SSLCertificates.mkhash(Puppet[:certdir], @cacert, @cacertfile)
- end
+ SSLCertificates.mkhash(Puppet[:certdir], @cacert, @cacertfile) if defined?(@cacert)
end
end
diff --git a/lib/puppet/sslcertificates/inventory.rb b/lib/puppet/sslcertificates/inventory.rb
index b86ee0b90..13f4e7f6a 100644
--- a/lib/puppet/sslcertificates/inventory.rb
+++ b/lib/puppet/sslcertificates/inventory.rb
@@ -8,9 +8,7 @@ module Puppet::SSLCertificates
# certificates that have been signed so far
def self.add(cert)
inited = false
- if FileTest.exists?(Puppet[:cert_inventory])
- inited = true
- end
+ inited = true if FileTest.exists?(Puppet[:cert_inventory])
Puppet.settings.write(:cert_inventory, "a") do |f|
f.puts((inited ? nil : self.init).to_s + format(cert))
diff --git a/lib/puppet/sslcertificates/support.rb b/lib/puppet/sslcertificates/support.rb
index fc40d3538..a32d9f00e 100644
--- a/lib/puppet/sslcertificates/support.rb
+++ b/lib/puppet/sslcertificates/support.rb
@@ -92,9 +92,7 @@ module Puppet::SSLCertificates::Support
begin
cert, cacert = caclient.getcert(@csr.to_pem)
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
raise Puppet::Error.new("Certificate retrieval failed: #{detail}")
end
@@ -115,9 +113,7 @@ module Puppet::SSLCertificates::Support
)
end
- unless @cert.check_private_key(@key)
- raise Puppet::DevError, "Received invalid certificate"
- end
+ raise Puppet::DevError, "Received invalid certificate" unless @cert.check_private_key(@key)
return retrieved
end
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 75b3140bb..bc2cc9c86 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -143,9 +143,7 @@ class Puppet::Transaction
ret = eval_resource(resource)
end
- if Puppet[:evaltrace] and @catalog.host_config?
- resource.info "Evaluated in %0.2f seconds" % seconds
- end
+ resource.info "Evaluated in %0.2f seconds" % seconds if Puppet[:evaltrace] and @catalog.host_config?
ret
end
ensure
@@ -264,9 +262,7 @@ class Puppet::Transaction
begin
provider.prefetch(resources)
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err "Could not prefetch #{provider.resource_type.name} provider '#{provider.name}': #{detail}"
end
end
@@ -298,9 +294,7 @@ class Puppet::Transaction
return
end
- if Puppet[:summarize]
- puts report.summary
- end
+ puts report.summary if Puppet[:summarize]
if Puppet[:report]
begin
@@ -342,9 +336,7 @@ class Puppet::Transaction
# The tags we should be checking.
def tags
- unless defined?(@tags)
- self.tags = Puppet[:tags]
- end
+ self.tags = Puppet[:tags] unless defined?(@tags)
super
end
diff --git a/lib/puppet/transaction/event_manager.rb b/lib/puppet/transaction/event_manager.rb
index 9c5c166c4..34a434248 100644
--- a/lib/puppet/transaction/event_manager.rb
+++ b/lib/puppet/transaction/event_manager.rb
@@ -54,9 +54,7 @@ class Puppet::Transaction::EventManager
queue_events_for_resource(resource, edge.target, method, list)
end
- if resource.self_refresh? and ! resource.deleting?
- queue_events_for_resource(resource, resource, :refresh, [event])
- end
+ queue_events_for_resource(resource, resource, :refresh, [event]) if resource.self_refresh? and ! resource.deleting?
end
end
diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb
index 24e69ea7a..f9dfab3a3 100644
--- a/lib/puppet/transaction/report.rb
+++ b/lib/puppet/transaction/report.rb
@@ -79,9 +79,7 @@ class Puppet::Transaction::Report
end
}.each do |name, label, value|
next if value == 0
- if value.is_a?(Float)
- value = "%0.2f" % value
- end
+ value = "%0.2f" % value if value.is_a?(Float)
ret += " %15s %s\n" % [label + ":", value]
end
end
diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb
index d6076681a..36bb6029d 100644
--- a/lib/puppet/transaction/resource_harness.rb
+++ b/lib/puppet/transaction/resource_harness.rb
@@ -20,9 +20,7 @@ class Puppet::Transaction::ResourceHarness
changes.each do |change|
status << change.apply
- if change.auditing?
- cache(change.property.resource, change.property.name, change.is)
- end
+ cache(change.property.resource, change.property.name, change.is) if change.auditing?
end
status.changed = true
end
diff --git a/lib/puppet/transportable.rb b/lib/puppet/transportable.rb
index 01045243d..876a8a222 100644
--- a/lib/puppet/transportable.rb
+++ b/lib/puppet/transportable.rb
@@ -34,9 +34,7 @@ module Puppet
end
def ref
- unless defined?(@ref)
- @ref = Puppet::Resource.new(@type, @name)
- end
+ @ref = Puppet::Resource.new(@type, @name) unless defined?(@ref)
@ref.to_s
end
@@ -159,9 +157,7 @@ module Puppet
# Convert to a parseable manifest
def to_manifest
unless self.top
- unless defined?(@keyword) and @keyword
- raise Puppet::DevError, "No keyword; cannot convert to manifest"
- end
+ raise Puppet::DevError, "No keyword; cannot convert to manifest" unless defined?(@keyword) and @keyword
end
str = "#{@keyword} #{@name} {\n%s\n}"
@@ -201,9 +197,7 @@ module Puppet
end
catalog.add_edge(container, resource)
- if child.is_a?(self.class)
- delver.call(child)
- end
+ delver.call(child) if child.is_a?(self.class)
end
end
@@ -245,9 +239,7 @@ module Puppet
end
def param(param,value)
- unless defined?(@parameters)
- @parameters = {}
- end
+ @parameters = {} unless defined?(@parameters)
@parameters[param] = value
end
diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb
index 28afab3ef..b063e1dd3 100644
--- a/lib/puppet/type.rb
+++ b/lib/puppet/type.rb
@@ -167,9 +167,7 @@ class Type
)
# Grr.
- if options[:required_features]
- param.required_features = options[:required_features]
- end
+ param.required_features = options[:required_features] if options[:required_features]
handle_param_options(name, options)
@@ -224,9 +222,7 @@ class Type
handle_param_options(name, options)
# Grr.
- if options[:required_features]
- param.required_features = options[:required_features]
- end
+ param.required_features = options[:required_features] if options[:required_features]
param.isnamevar if options[:namevar]
@@ -254,9 +250,7 @@ class Type
"Options must be a hash, not #{options.inspect}"
end
- if @validproperties.include?(name)
- raise Puppet::DevError, "Class #{self.name} already has a property named #{name}"
- end
+ raise Puppet::DevError, "Class #{self.name} already has a property named #{name}" if @validproperties.include?(name)
if parent = options[:parent]
options.delete(:parent)
@@ -276,9 +270,7 @@ class Type
end
end
- if block
- class_eval(&block)
- end
+ class_eval(&block) if block
end
# If it's the 'ensure' property, always put it first.
@@ -346,9 +338,7 @@ class Type
# does the name reflect a valid parameter?
def self.validparameter?(name)
- unless defined?(@parameters)
- raise Puppet::DevError, "Class #{self} has not defined parameters"
- end
+ raise Puppet::DevError, "Class #{self} has not defined parameters" unless defined?(@parameters)
if @paramhash.include?(name) or @@metaparamhash.include?(name)
return true
else
@@ -402,9 +392,7 @@ class Type
def [](name)
name = attr_alias(name)
- unless self.class.validattr?(name)
- fail("Invalid parameter #{name}(#{name.inspect})")
- end
+ fail("Invalid parameter #{name}(#{name.inspect})") unless self.class.validattr?(name)
if name == :name
name = name_var
@@ -425,16 +413,12 @@ class Type
def []=(name,value)
name = attr_alias(name)
- unless self.class.validattr?(name)
- fail("Invalid parameter #{name}")
- end
+ fail("Invalid parameter #{name}") unless self.class.validattr?(name)
if name == :name
name = name_var
end
- if value.nil?
- raise Puppet::Error.new("Got nil value for #{name}")
- end
+ raise Puppet::Error.new("Got nil value for #{name}") if value.nil?
property = self.newattr(name)
@@ -504,9 +488,7 @@ class Type
raise Puppet::Error, "Resource type #{self.class.name} does not support parameter #{name}"
end
- if @parameters.include?(name)
- return @parameters[name]
- end
+ return @parameters[name] if @parameters.include?(name)
return @parameters[name] = klass.new(:resource => self)
end
@@ -522,9 +504,7 @@ class Type
# Is the named property defined?
def propertydefined?(name)
- unless name.is_a? Symbol
- name = name.intern
- end
+ name = name.intern unless name.is_a? Symbol
return @parameters.include?(name)
end
@@ -673,9 +653,7 @@ class Type
# Flush the provider, if it supports it. This is called by the
# transaction.
def flush
- if self.provider and self.provider.respond_to?(:flush)
- self.provider.flush
- end
+ self.provider.flush if self.provider and self.provider.respond_to?(:flush)
end
# if all contained objects are in sync, then we're in sync
@@ -716,9 +694,7 @@ class Type
# retrieve the current value of all contained properties
def retrieve
- if self.provider.is_a?(Puppet::Provider) and ! provider.class.suitable?
- fail "Provider #{provider.class.name} is not functional on this host"
- end
+ fail "Provider #{provider.class.name} is not functional on this host" if self.provider.is_a?(Puppet::Provider) and ! provider.class.suitable?
result = Puppet::Resource.new(type, title)
@@ -745,9 +721,7 @@ class Type
def retrieve_resource
resource = retrieve
- if resource.is_a? Hash
- resource = Resource.new(type, title, :parameters => resource)
- end
+ resource = Resource.new(type, title, :parameters => resource) if resource.is_a? Hash
resource
end
@@ -811,12 +785,8 @@ class Type
if exobj = @objects[name] and self.isomorphic?
msg = "Object '#{newobj.class.name}[#{name}]' already exists"
- if exobj.file and exobj.line
- msg += ("in file #{object.file} at line #{object.line}")
- end
- if object.file and object.line
- msg += ("and cannot be redefined in file #{object.file} at line #{object.line}")
- end
+ msg += ("in file #{object.file} at line #{object.line}") if exobj.file and exobj.line
+ msg += ("and cannot be redefined in file #{object.file} at line #{object.line}") if object.file and object.line
error = Puppet::Error.new(msg)
raise error
else
@@ -858,9 +828,7 @@ class Type
end
@objects.clear
end
- if defined?(@aliases)
- @aliases.clear
- end
+ @aliases.clear if defined?(@aliases)
end
# Force users to call this, so that we can merge objects if
@@ -875,12 +843,8 @@ class Type
def self.delete(resource)
raise "Global resource removal is deprecated"
return unless defined?(@objects)
- if @objects.include?(resource.title)
- @objects.delete(resource.title)
- end
- if @aliases.include?(resource.title)
- @aliases.delete(resource.title)
- end
+ @objects.delete(resource.title) if @objects.include?(resource.title)
+ @aliases.delete(resource.title) if @aliases.include?(resource.title)
if @aliases.has_value?(resource)
names = []
@aliases.each do |name, otherres|
@@ -909,9 +873,7 @@ class Type
# Retrieve all known instances. Either requires providers or must be overridden.
def self.instances
- if provider_hash.empty?
- raise Puppet::DevError, "#{self.name} has no providers and has not overridden 'instances'"
- end
+ raise Puppet::DevError, "#{self.name} has no providers and has not overridden 'instances'" if provider_hash.empty?
# Put the default provider first, then the rest of the suitable providers.
provider_instances = {}
@@ -1120,9 +1082,7 @@ class Type
"
munge do |aliases|
- unless aliases.is_a?(Array)
- aliases = [aliases]
- end
+ aliases = [aliases] unless aliases.is_a?(Array)
raise(ArgumentError, "Cannot add aliases without a catalog") unless @resource.catalog
@@ -1439,9 +1399,7 @@ class Type
name = Puppet::Util.symbolize(name)
# If we don't have it yet, try loading it.
- unless provider_hash.has_key?(name)
- @providerloader.load(name)
- end
+ @providerloader.load(name) unless provider_hash.has_key?(name)
return provider_hash[name]
end
@@ -1533,9 +1491,7 @@ class Type
validate do |provider_class|
provider_class = provider_class[0] if provider_class.is_a? Array
- if provider_class.is_a?(Puppet::Provider)
- provider_class = provider_class.class.name
- end
+ provider_class = provider_class.class.name if provider_class.is_a?(Puppet::Provider)
unless provider = @resource.class.provider(provider_class)
raise ArgumentError, "Invalid #{@resource.class.name} provider '#{provider_class}'"
@@ -1544,9 +1500,7 @@ class Type
munge do |provider|
provider = provider[0] if provider.is_a? Array
- if provider.is_a? String
- provider = provider.intern
- end
+ provider = provider.intern if provider.is_a? String
@resource.provider = provider
if provider.is_a?(Puppet::Provider)
@@ -1575,9 +1529,7 @@ class Type
# Return an array of all of the suitable providers.
def self.suitableprovider
- if provider_hash.empty?
- providerloader.loadall
- end
+ providerloader.loadall if provider_hash.empty?
provider_hash.find_all { |name, provider|
provider.suitable?
}.collect { |name, provider|
@@ -1628,9 +1580,7 @@ class Type
# Retrieve the list of names from the block.
next unless list = self.instance_eval(&block)
- unless list.is_a?(Array)
- list = [list]
- end
+ list = [list] unless list.is_a?(Array)
# Collect the current prereqs
list.each { |dep|
@@ -1702,9 +1652,7 @@ class Type
@defaults = {}
- unless defined?(@parameters)
- @parameters = []
- end
+ @parameters = [] unless defined?(@parameters)
@validproperties = {}
@properties = []
@@ -1714,9 +1662,7 @@ class Type
@attr_aliases = {}
@paramdoc = Hash.new { |hash,key|
- if key.is_a?(String)
- key = key.intern
- end
+ key = key.intern if key.is_a?(String)
if hash.include?(key)
hash[key]
else
@@ -1724,9 +1670,7 @@ class Type
end
}
- unless defined?(@doc)
- @doc = ""
- end
+ @doc = "" unless defined?(@doc)
end
diff --git a/lib/puppet/type/augeas.rb b/lib/puppet/type/augeas.rb
index d29bf30cb..0a83865c8 100644
--- a/lib/puppet/type/augeas.rb
+++ b/lib/puppet/type/augeas.rb
@@ -146,9 +146,7 @@ Puppet::Type.newtype(:augeas) do
validate do
has_lens = !self[:lens].nil?
has_incl = !self[:incl].nil?
- if has_lens != has_incl
- self.fail "You must specify both the lens and incl parameters, or neither"
- end
+ self.fail "You must specify both the lens and incl parameters, or neither" if has_lens != has_incl
end
# This is the acutal meat of the code. It forces
diff --git a/lib/puppet/type/component.rb b/lib/puppet/type/component.rb
index 9fc05c115..9e885233c 100644
--- a/lib/puppet/type/component.rb
+++ b/lib/puppet/type/component.rb
@@ -30,9 +30,7 @@ Puppet::Type.newtype(:component) do
@extra_parameters = {}
super
- if catalog and ! catalog.resource(ref)
- catalog.alias(self, ref)
- end
+ catalog.alias(self, ref) if catalog and ! catalog.resource(ref)
end
# Component paths are special because they function as containers.
diff --git a/lib/puppet/type/cron.rb b/lib/puppet/type/cron.rb
index dee0dc3f1..0a6788ebf 100755
--- a/lib/puppet/type/cron.rb
+++ b/lib/puppet/type/cron.rb
@@ -99,9 +99,7 @@ Puppet::Type.newtype(:cron) do
end
}
else
- if ary.include?(tmp)
- return ary.index(tmp)
- end
+ return ary.index(tmp) if ary.include?(tmp)
end
return false
@@ -109,9 +107,7 @@ Puppet::Type.newtype(:cron) do
def should_to_s(newvalue = @should)
if newvalue
- unless newvalue.is_a?(Array)
- newvalue = [newvalue]
- end
+ newvalue = [newvalue] unless newvalue.is_a?(Array)
if self.name == :command or newvalue[0].is_a? Symbol
newvalue[0]
else
@@ -124,9 +120,7 @@ Puppet::Type.newtype(:cron) do
def is_to_s(currentvalue = @is)
if currentvalue
- unless currentvalue.is_a?(Array)
- return currentvalue
- end
+ return currentvalue unless currentvalue.is_a?(Array)
if self.name == :command or currentvalue[0].is_a? Symbol
currentvalue[0]
@@ -221,9 +215,7 @@ Puppet::Type.newtype(:cron) do
def retrieve
return_value = super
- if return_value && return_value.is_a?(Array)
- return_value = return_value[0]
- end
+ return_value = return_value[0] if return_value && return_value.is_a?(Array)
return return_value
end
@@ -249,9 +241,7 @@ Puppet::Type.newtype(:cron) do
end
validate do |value|
- unless specials().include?(value)
- raise ArgumentError, "Invalid special schedule #{value.inspect}"
- end
+ raise ArgumentError, "Invalid special schedule #{value.inspect}" unless specials().include?(value)
end
end
@@ -401,9 +391,7 @@ Puppet::Type.newtype(:cron) do
if obj = @parameters[name]
ret = obj.should
- if ret.nil?
- ret = obj.retrieve
- end
+ ret = obj.retrieve if ret.nil?
if ret == :absent
ret = nil
diff --git a/lib/puppet/type/exec.rb b/lib/puppet/type/exec.rb
index ce662f152..ee1ed9952 100755
--- a/lib/puppet/type/exec.rb
+++ b/lib/puppet/type/exec.rb
@@ -192,9 +192,7 @@ module Puppet
# Most validation is handled by the SUIDManager class.
validate do |user|
- unless Puppet.features.root?
- self.fail "Only root can execute commands as other users"
- end
+ self.fail "Only root can execute commands as other users" unless Puppet.features.root?
end
end
@@ -217,9 +215,7 @@ module Puppet
end
munge do |dir|
- if dir.is_a?(Array)
- dir = dir[0]
- end
+ dir = dir[0] if dir.is_a?(Array)
dir
end
@@ -305,9 +301,7 @@ module Puppet
end
value = Integer(value)
end
- if value < 1
- raise ArgumentError, "Tries must be an integer >= 1"
- end
+ raise ArgumentError, "Tries must be an integer >= 1" if value < 1
value
end
@@ -324,9 +318,7 @@ module Puppet
end
value = Float(value)
end
- if value < 0
- raise ArgumentError, "try_sleep cannot be a negative number"
- end
+ raise ArgumentError, "try_sleep cannot be a negative number" if value < 0
value
end
@@ -494,9 +486,7 @@ module Puppet
reqs = []
# Stick the cwd in there if we have it
- if self[:cwd]
- reqs << self[:cwd]
- end
+ reqs << self[:cwd] if self[:cwd]
self[:command].scan(/^(#{File::SEPARATOR}\S+)/) { |str|
reqs << str
@@ -548,9 +538,7 @@ module Puppet
val = @parameters[check].value
val = [val] unless val.is_a? Array
val.each do |value|
- unless @parameters[check].check(value)
- return false
- end
+ return false unless @parameters[check].check(value)
end
end
}
@@ -583,9 +571,7 @@ module Puppet
end
end
- unless FileTest.exists?(exe)
- raise ArgumentError, "Could not find executable '#{exe}'"
- end
+ raise ArgumentError, "Could not find executable '#{exe}'" unless FileTest.exists?(exe)
unless FileTest.executable?(exe)
raise ArgumentError,
"'#{exe}' is not executable"
@@ -642,9 +628,7 @@ module Puppet
Dir.chdir(dir) do
environment = {}
- if self[:path]
- environment[:PATH] = self[:path].join(":")
- end
+ environment[:PATH] = self[:path].join(":") if self[:path]
if envlist = self[:environment]
envlist = [envlist] unless envlist.is_a? Array
@@ -686,9 +670,7 @@ module Puppet
def validatecmd(cmd)
exe = extractexe(cmd)
# if we're not fully qualified, require a path
- if File.expand_path(exe) != exe and self[:path].nil?
- self.fail "'#{cmd}' is both unqualifed and specified no search path"
- end
+ self.fail "'#{cmd}' is both unqualifed and specified no search path" if File.expand_path(exe) != exe and self[:path].nil?
end
def extractexe(cmd)
diff --git a/lib/puppet/type/file.rb b/lib/puppet/type/file.rb
index 6a9ec08e7..bf798936a 100644
--- a/lib/puppet/type/file.rb
+++ b/lib/puppet/type/file.rb
@@ -277,20 +277,12 @@ Puppet::Type.newtype(:file) do
CREATORS.each do |param|
count += 1 if self.should(param)
end
- if @parameters.include?(:source)
- count += 1
- end
- if count > 1
- self.fail "You cannot specify more than one of #{CREATORS.collect { |p| p.to_s}.join(", ")}"
- end
+ count += 1 if @parameters.include?(:source)
+ self.fail "You cannot specify more than one of #{CREATORS.collect { |p| p.to_s}.join(", ")}" if count > 1
- if !self[:source] and self[:recurse] == :remote
- self.fail "You cannot specify a remote recursion without a source"
- end
+ self.fail "You cannot specify a remote recursion without a source" if !self[:source] and self[:recurse] == :remote
- if !self[:recurse] and self[:recurselimit]
- self.warning "Possible error: recurselimit is set but not recurse, no recursion will happen"
- end
+ self.warning "Possible error: recurselimit is set but not recurse, no recursion will happen" if !self[:recurse] and self[:recurselimit]
end
def self.[](path)
@@ -300,9 +292,7 @@ Puppet::Type.newtype(:file) do
# List files, but only one level deep.
def self.instances(base = "/")
- unless FileTest.directory?(base)
- return []
- end
+ return [] unless FileTest.directory?(base)
files = []
Dir.entries(base).reject { |e|
@@ -333,9 +323,7 @@ Puppet::Type.newtype(:file) do
# If the parent directory is writeable, then we execute
# as the user in question. Otherwise we'll rely on
# the 'owner' property to do things.
- if writeable
- asuser = self.should(:owner)
- end
+ asuser = self.should(:owner) if writeable
end
return asuser
@@ -485,9 +473,7 @@ Puppet::Type.newtype(:file) do
# to map to another directory.
def recurse
children = {}
- if self[:recurse] != :remote
- children = recurse_local
- end
+ children = recurse_local if self[:recurse] != :remote
if self[:target]
recurse_link(children)
@@ -718,9 +704,7 @@ Puppet::Type.newtype(:file) do
# the far side.
def to_trans(retrieve = true)
obj = super
- if obj[:target] == :notlink
- obj.delete(:target)
- end
+ obj.delete(:target) if obj[:target] == :notlink
obj
end
@@ -732,9 +716,7 @@ Puppet::Type.newtype(:file) do
use_temporary_file = write_temporary_file?
if use_temporary_file
path = "#{self[:path]}.puppettmp_#{rand(10000)}"
- while File.exists?(path) or File.symlink?(path)
- path = "#{self[:path]}.puppettmp_#{rand(10000)}"
- end
+ path = "#{self[:path]}.puppettmp_#{rand(10000)}" while File.exists?(path) or File.symlink?(path)
else
path = self[:path]
end
@@ -801,9 +783,7 @@ Puppet::Type.newtype(:file) do
# Make sure we get a new stat objct
expire
currentvalue = thing.retrieve
- unless thing.insync?(currentvalue)
- thing.sync
- end
+ thing.sync unless thing.insync?(currentvalue)
end
end
end
diff --git a/lib/puppet/type/file/mode.rb b/lib/puppet/type/file/mode.rb
index da54b9fdd..6a73822f0 100755
--- a/lib/puppet/type/file/mode.rb
+++ b/lib/puppet/type/file/mode.rb
@@ -76,15 +76,9 @@ module Puppet
# that are readable. This should probably be selectable, but eh.
def dirmask(value)
if FileTest.directory?(@resource[:path])
- if value & 0400 != 0
- value |= 0100
- end
- if value & 040 != 0
- value |= 010
- end
- if value & 04 != 0
- value |= 01
- end
+ value |= 0100 if value & 0400 != 0
+ value |= 010 if value & 040 != 0
+ value |= 01 if value & 04 != 0
end
return value
@@ -105,9 +99,7 @@ module Puppet
if stat = @resource.stat(false)
unless defined?(@fixed)
- if defined?(@should) and @should
- @should = @should.collect { |s| self.dirmask(s) }
- end
+ @should = @should.collect { |s| self.dirmask(s) } if defined?(@should) and @should
end
return stat.mode & 007777
else
diff --git a/lib/puppet/type/file/selcontext.rb b/lib/puppet/type/file/selcontext.rb
index dc94cb9da..71ce30133 100644
--- a/lib/puppet/type/file/selcontext.rb
+++ b/lib/puppet/type/file/selcontext.rb
@@ -26,9 +26,7 @@ module Puppet
include Puppet::Util::SELinux
def retrieve
- unless @resource.stat(false)
- return :absent
- end
+ return :absent unless @resource.stat(false)
context = self.get_selinux_current_context(@resource[:path])
return parse_selinux_context(name, context)
end
@@ -38,9 +36,7 @@ module Puppet
return nil
end
property_default = self.parse_selinux_context(property, context)
- if not property_default.nil?
- self.debug "Found #{property} default '#{property_default}' for #{@resource[:path]}"
- end
+ self.debug "Found #{property} default '#{property_default}' for #{@resource[:path]}" if not property_default.nil?
return property_default
end
diff --git a/lib/puppet/type/file/source.rb b/lib/puppet/type/file/source.rb
index 74cd4c028..9d1766c52 100755
--- a/lib/puppet/type/file/source.rb
+++ b/lib/puppet/type/file/source.rb
@@ -72,9 +72,7 @@ module Puppet
self.fail "Could not understand source #{source}: #{detail}"
end
- unless uri.scheme.nil? or %w{file puppet}.include?(uri.scheme)
- self.fail "Cannot use URLs of type '#{uri.scheme}' as source for fileserving"
- end
+ self.fail "Cannot use URLs of type '#{uri.scheme}' as source for fileserving" unless uri.scheme.nil? or %w{file puppet}.include?(uri.scheme)
end
end
@@ -171,9 +169,7 @@ module Puppet
end
def full_path
- if found? and uri
- return URI.unescape(uri.path)
- end
+ return URI.unescape(uri.path) if found? and uri
end
def server
diff --git a/lib/puppet/type/file/target.rb b/lib/puppet/type/file/target.rb
index e4a188c85..ab7b847a7 100644
--- a/lib/puppet/type/file/target.rb
+++ b/lib/puppet/type/file/target.rb
@@ -10,15 +10,11 @@ module Puppet
# Anything else, basically
newvalue(/./) do
- if ! @resource.should(:ensure)
- @resource[:ensure] = :link
- end
+ @resource[:ensure] = :link if ! @resource.should(:ensure)
# Only call mklink if ensure() didn't call us in the first place.
currentensure = @resource.property(:ensure).retrieve
- if @resource.property(:ensure).insync?(currentensure)
- mklink()
- end
+ mklink() if @resource.property(:ensure).insync?(currentensure)
end
# Create our link.
@@ -31,9 +27,7 @@ module Puppet
# it doesn't determine what's removed.
@resource.remove_existing(target)
- if FileTest.exists?(@resource[:path])
- raise Puppet::Error, "Could not remove existing file"
- end
+ raise Puppet::Error, "Could not remove existing file" if FileTest.exists?(@resource[:path])
Dir.chdir(File.dirname(@resource[:path])) do
Puppet::Util::SUIDManager.asuser(@resource.asuser()) do
diff --git a/lib/puppet/type/mount.rb b/lib/puppet/type/mount.rb
index 342c84377..5772e44a1 100755
--- a/lib/puppet/type/mount.rb
+++ b/lib/puppet/type/mount.rb
@@ -40,9 +40,7 @@ module Puppet
end
newvalue(:absent, :event => :mount_deleted) do
- if provider.mounted?
- provider.unmount
- end
+ provider.unmount if provider.mounted?
provider.destroy
end
@@ -94,9 +92,7 @@ module Puppet
! prop.insync?(currentvalues[prop])
end
end.each { |prop| prop.sync }.length
- if oos > 0
- @resource.flush
- end
+ @resource.flush if oos > 0
end
end
@@ -142,9 +138,7 @@ module Puppet
desc "The pass in which the mount is checked."
defaultto {
- if @resource.managed?
- 0
- end
+ 0 if @resource.managed?
}
end
@@ -166,9 +160,7 @@ module Puppet
newvalue(%r{(0|1)})
defaultto {
- if @resource.managed?
- 0
- end
+ 0 if @resource.managed?
}
end
diff --git a/lib/puppet/type/resources.rb b/lib/puppet/type/resources.rb
index 1fb866043..dc620bb57 100644
--- a/lib/puppet/type/resources.rb
+++ b/lib/puppet/type/resources.rb
@@ -14,9 +14,7 @@ Puppet::Type.newtype(:resources) do
desc "The name of the type to be managed."
validate do |name|
- unless Puppet::Type.type(name)
- raise ArgumentError, "Could not find resource type '#{name}'"
- end
+ raise ArgumentError, "Could not find resource type '#{name}'" unless Puppet::Type.type(name)
end
munge { |v| v.to_s }
@@ -34,9 +32,7 @@ Puppet::Type.newtype(:resources) do
unless @resource.resource_type.respond_to?(:instances)
raise ArgumentError, "Purging resources of type #{@resource[:name]} is not supported, since they cannot be queried from the system"
end
- unless @resource.resource_type.validproperty?(:ensure)
- raise ArgumentError, "Purging is only supported on types that accept 'ensure'"
- end
+ raise ArgumentError, "Purging is only supported on types that accept 'ensure'" unless @resource.resource_type.validproperty?(:ensure)
end
end
end
@@ -72,12 +68,8 @@ Puppet::Type.newtype(:resources) do
end
def check(resource)
- unless defined?(@checkmethod)
- @checkmethod = "#{self[:name]}_check"
- end
- unless defined?(@hascheck)
- @hascheck = respond_to?(@checkmethod)
- end
+ @checkmethod = "#{self[:name]}_check" unless defined?(@checkmethod)
+ @hascheck = respond_to?(@checkmethod) unless defined?(@hascheck)
if @hascheck
return send(@checkmethod, resource)
else
@@ -133,9 +125,7 @@ Puppet::Type.newtype(:resources) do
resource[:audit] = :uid
current_values = resource.retrieve_resource
- if system_users().include?(resource[:name])
- return false
- end
+ return false if system_users().include?(resource[:name])
if current_values[resource.property(:uid)] <= self[:unless_system_user]
return false
diff --git a/lib/puppet/type/schedule.rb b/lib/puppet/type/schedule.rb
index c35c97ab3..dcc7359e2 100755
--- a/lib/puppet/type/schedule.rb
+++ b/lib/puppet/type/schedule.rb
@@ -98,21 +98,15 @@ module Puppet
range << val.split(":").collect { |n| n.to_i }
}
- if range.length != 2
- self.fail "Invalid range #{value}"
- end
+ self.fail "Invalid range #{value}" if range.length != 2
# Make sure the hours are valid
[range[0][0], range[1][0]].each do |n|
- if n < 0 or n > 23
- raise ArgumentError, "Invalid hour '#{n}'"
- end
+ raise ArgumentError, "Invalid hour '#{n}'" if n < 0 or n > 23
end
[range[0][1], range[1][1]].each do |n|
- if n and (n < 0 or n > 59)
- raise ArgumentError, "Invalid minute '#{n}'"
- end
+ raise ArgumentError, "Invalid minute '#{n}'" if n and (n < 0 or n > 59)
end
if range[0][0] > range[1][0]
self.fail(("Invalid range #{value}; ") +
@@ -130,9 +124,7 @@ module Puppet
# The lowest-level array is of the hour, minute, second triad
# then it's an array of two of those, to present the limits
# then it's array of those ranges
- unless @value[0][0].is_a?(Array)
- @value = [@value]
- end
+ @value = [@value] unless @value[0][0].is_a?(Array)
@value.each do |value|
limits = value.collect do |range|
@@ -296,9 +288,7 @@ module Puppet
end
munge do |value|
- unless value.is_a?(Integer)
- value = Integer(value)
- end
+ value = Integer(value) unless value.is_a?(Integer)
value
end
@@ -341,9 +331,7 @@ module Puppet
def match?(previous = nil, now = nil)
# If we've got a value, then convert it to a Time instance
- if previous
- previous = Time.at(previous)
- end
+ previous = Time.at(previous) if previous
now ||= Time.now
diff --git a/lib/puppet/type/ssh_authorized_key.rb b/lib/puppet/type/ssh_authorized_key.rb
index ac59823ce..306af8973 100644
--- a/lib/puppet/type/ssh_authorized_key.rb
+++ b/lib/puppet/type/ssh_authorized_key.rb
@@ -40,9 +40,7 @@ module Puppet
defaultto :absent
def should
- if defined?(@should) and @should[0] != :absent
- return super
- end
+ return super if defined?(@should) and @should[0] != :absent
return nil unless user = resource[:user]
@@ -83,9 +81,7 @@ module Puppet
end
autorequire(:user) do
- if should(:user)
- should(:user)
- end
+ should(:user) if should(:user)
end
validate do
diff --git a/lib/puppet/type/tidy.rb b/lib/puppet/type/tidy.rb
index 63b2ae244..d1235b1cc 100755
--- a/lib/puppet/type/tidy.rb
+++ b/lib/puppet/type/tidy.rb
@@ -221,9 +221,7 @@ Puppet::Type.newtype(:tidy) do
super
# only allow backing up into filebuckets
- unless self[:backup].is_a? Puppet::FileBucket::Dipper
- self[:backup] = false
- end
+ self[:backup] = false unless self[:backup].is_a? Puppet::FileBucket::Dipper
end
# Make a file resource to remove a given file.
diff --git a/lib/puppet/type/user.rb b/lib/puppet/type/user.rb
index 5788c39de..1746baab0 100755
--- a/lib/puppet/type/user.rb
+++ b/lib/puppet/type/user.rb
@@ -167,9 +167,7 @@ module Puppet
if value =~ /^\d+$/
raise ArgumentError, "Group names must be provided, not numbers"
end
- if value.include?(",")
- raise ArgumentError, "Group names must be provided as an array, not a comma-separated list"
- end
+ raise ArgumentError, "Group names must be provided as an array, not a comma-separated list" if value.include?(",")
end
end
@@ -207,9 +205,7 @@ module Puppet
validate do |val|
if val.to_s == "true"
- unless provider.class.manages_homedir?
- raise ArgumentError, "User provider #{provider.class.name} can not manage home directories"
- end
+ raise ArgumentError, "User provider #{provider.class.name} can not manage home directories" unless provider.class.manages_homedir?
end
end
end
@@ -281,9 +277,7 @@ module Puppet
if value =~ /^\d+$/
raise ArgumentError, "Role names must be provided, not numbers"
end
- if value.include?(",")
- raise ArgumentError, "Role names must be provided as an array, not a comma-separated list"
- end
+ raise ArgumentError, "Role names must be provided as an array, not a comma-separated list" if value.include?(",")
end
end
@@ -320,9 +314,7 @@ module Puppet
if value =~ /^\d+$/
raise ArgumentError, "Auth names must be provided, not numbers"
end
- if value.include?(",")
- raise ArgumentError, "Auth names must be provided as an array, not a comma-separated list"
- end
+ raise ArgumentError, "Auth names must be provided as an array, not a comma-separated list" if value.include?(",")
end
end
@@ -348,9 +340,7 @@ module Puppet
if value =~ /^\d+$/
raise ArgumentError, "Profile names must be provided, not numbers"
end
- if value.include?(",")
- raise ArgumentError, "Profile names must be provided as an array, not a comma-separated list"
- end
+ raise ArgumentError, "Profile names must be provided as an array, not a comma-separated list" if value.include?(",")
end
end
@@ -372,9 +362,7 @@ module Puppet
end
validate do |value|
- unless value.include?("=")
- raise ArgumentError, "key value pairs must be seperated by an ="
- end
+ raise ArgumentError, "key value pairs must be seperated by an =" unless value.include?("=")
end
end
diff --git a/lib/puppet/type/yumrepo.rb b/lib/puppet/type/yumrepo.rb
index d430089fa..aa685f033 100644
--- a/lib/puppet/type/yumrepo.rb
+++ b/lib/puppet/type/yumrepo.rb
@@ -105,17 +105,13 @@ module Puppet
if @inifile.nil?
@inifile = read()
main = @inifile['main']
- if main.nil?
- raise Puppet::Error, "File #{yumconf} does not contain a main section"
- end
+ raise Puppet::Error, "File #{yumconf} does not contain a main section" if main.nil?
reposdir = main['reposdir']
reposdir ||= "/etc/yum.repos.d, /etc/yum/repos.d"
reposdir.gsub!(/[\n,]/, " ")
reposdir.split.each do |dir|
Dir::glob("#{dir}/*.repo").each do |file|
- if File.file?(file)
- @inifile.read(file)
- end
+ @inifile.read(file) if File.file?(file)
end
end
reposdir.split.each do |dir|
@@ -135,17 +131,13 @@ module Puppet
result = Puppet::Util::IniConfig::File.new()
result.read(yumconf)
main = result['main']
- if main.nil?
- raise Puppet::Error, "File #{yumconf} does not contain a main section"
- end
+ raise Puppet::Error, "File #{yumconf} does not contain a main section" if main.nil?
reposdir = main['reposdir']
reposdir ||= "/etc/yum.repos.d, /etc/yum/repos.d"
reposdir.gsub!(/[\n,]/, " ")
reposdir.split.each do |dir|
Dir::glob("#{dir}/*.repo").each do |file|
- if File.file?(file)
- result.read(file)
- end
+ result.read(file) if File.file?(file)
end
end
if @defaultrepodir.nil?
@@ -166,9 +158,7 @@ module Puppet
if result.nil?
# Brand new section
path = yumconf
- unless @defaultrepodir.nil?
- path = File::join(@defaultrepodir, "#{name}.repo")
- end
+ path = File::join(@defaultrepodir, "#{name}.repo") unless @defaultrepodir.nil?
Puppet::info "create new repo #{name} in file #{path}"
result = inifile.add_section(name, path)
end
diff --git a/lib/puppet/type/zone.rb b/lib/puppet/type/zone.rb
index 5573241ed..d4d9c9e9c 100644
--- a/lib/puppet/type/zone.rb
+++ b/lib/puppet/type/zone.rb
@@ -22,9 +22,7 @@ Puppet::Type.newtype(:zone) do
if current_value.is_a? Array
list += current_value
else
- if current_value
- list << current_value
- end
+ list << current_value if current_value
end
end
@@ -87,9 +85,7 @@ Puppet::Type.newtype(:zone) do
end
def self.newvalue(name, hash)
- if @parametervalues.is_a? Hash
- @parametervalues = []
- end
+ @parametervalues = [] if @parametervalues.is_a? Hash
@parametervalues << name
@@ -410,9 +406,7 @@ Puppet::Type.newtype(:zone) do
self.fail "ip must contain interface name and ip address separated by a \":\""
end
else
- unless interface && address.nil? && defrouter.nil?
- self.fail "only interface may be specified when using exclusive IP stack: #{value}"
- end
+ self.fail "only interface may be specified when using exclusive IP stack: #{value}" unless interface && address.nil? && defrouter.nil?
end
self.fail "zone path is required" unless self[:path]
diff --git a/lib/puppet/type/zpool.rb b/lib/puppet/type/zpool.rb
index 48fe9a227..e6dec62fc 100755
--- a/lib/puppet/type/zpool.rb
+++ b/lib/puppet/type/zpool.rb
@@ -48,9 +48,7 @@ module Puppet
mirror => [\"disk1 disk2\", \"disk3 disk4\"]"
validate do |value|
- if value.include?(",")
- raise ArgumentError, "mirror names must be provided as string separated, not a comma-separated list"
- end
+ raise ArgumentError, "mirror names must be provided as string separated, not a comma-separated list" if value.include?(",")
end
end
@@ -59,9 +57,7 @@ module Puppet
raidz => [\"disk1 disk2\", \"disk3 disk4\"]"
validate do |value|
- if value.include?(",")
- raise ArgumentError, "raid names must be provided as string separated, not a comma-separated list"
- end
+ raise ArgumentError, "raid names must be provided as string separated, not a comma-separated list" if value.include?(",")
end
end
@@ -84,9 +80,7 @@ module Puppet
validate do
has_should = [:disk, :mirror, :raidz].select { |prop| self.should(prop) }
- if has_should.length > 1
- self.fail "You cannot specify #{has_should.join(" and ")} on this type (only one)"
- end
+ self.fail "You cannot specify #{has_should.join(" and ")} on this type (only one)" if has_should.length > 1
end
end
end
diff --git a/lib/puppet/util.rb b/lib/puppet/util.rb
index 02bac1b88..e7b4f24f7 100644
--- a/lib/puppet/util.rb
+++ b/lib/puppet/util.rb
@@ -30,9 +30,7 @@ module Util
def self.chuser
if group = Puppet[:group]
group = self.gid(group)
- unless group
- raise Puppet::Error, "No such group #{Puppet[:group]}"
- end
+ raise Puppet::Error, "No such group #{Puppet[:group]}" unless group
unless Puppet::Util::SUIDManager.gid == group
begin
Puppet::Util::SUIDManager.egid = group
@@ -50,9 +48,7 @@ module Util
if user = Puppet[:user]
user = self.uid(user)
- unless user
- raise Puppet::Error, "No such user #{Puppet[:user]}"
- end
+ raise Puppet::Error, "No such user #{Puppet[:user]}" unless user
unless Puppet::Util::SUIDManager.uid == user
begin
Puppet::Util::SUIDManager.initgroups(user)
@@ -72,9 +68,7 @@ module Util
def self.logmethods(klass, useself = true)
Puppet::Util::Log.eachlevel { |level|
klass.send(:define_method, level, proc { |args|
- if args.is_a?(Array)
- args = args.join(" ")
- end
+ args = args.join(" ") if args.is_a?(Array)
if useself
Puppet::Util::Log.create(
@@ -168,9 +162,7 @@ module Util
object = args.pop
end
- unless level
- raise Puppet::DevError, "Failed to provide level to :benchmark"
- end
+ raise Puppet::DevError, "Failed to provide level to :benchmark" unless level
unless level == :none or object.respond_to? level
raise Puppet::DevError, "Benchmarked object does not respond to #{level}"
@@ -254,12 +246,8 @@ module Util
Puppet.debug "Executing '#{str}'"
end
- if arguments[:uid]
- arguments[:uid] = Puppet::Util::SUIDManager.convert_xid(:uid, arguments[:uid])
- end
- if arguments[:gid]
- arguments[:gid] = Puppet::Util::SUIDManager.convert_xid(:gid, arguments[:gid])
- end
+ arguments[:uid] = Puppet::Util::SUIDManager.convert_xid(:uid, arguments[:uid]) if arguments[:uid]
+ arguments[:gid] = Puppet::Util::SUIDManager.convert_xid(:gid, arguments[:gid]) if arguments[:gid]
@@os ||= Facter.value(:operatingsystem)
output = nil
@@ -274,9 +262,7 @@ module Util
if ! arguments[:squelch]
require "tempfile"
output_file = Tempfile.new("puppet")
- if arguments[:combine]
- error_file=output_file
- end
+ error_file=output_file if arguments[:combine]
end
if Puppet.features.posix?
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb
index cdfc194da..21f99e4c0 100644
--- a/lib/puppet/util/autoload.rb
+++ b/lib/puppet/util/autoload.rb
@@ -50,9 +50,7 @@ class Puppet::Util::Autoload
def initialize(obj, path, options = {})
@path = path.to_s
- if @path !~ /^\w/
- raise ArgumentError, "Autoload paths cannot be fully qualified"
- end
+ raise ArgumentError, "Autoload paths cannot be fully qualified" if @path !~ /^\w/
@object = obj
self.class[obj] = self
@@ -66,9 +64,7 @@ class Puppet::Util::Autoload
end
end
- unless defined?(@wrap)
- @wrap = true
- end
+ @wrap = true unless defined?(@wrap)
end
# Load a single plugin by name. We use 'load' here so we can reload a
diff --git a/lib/puppet/util/autoload/file_cache.rb b/lib/puppet/util/autoload/file_cache.rb
index 881e08637..873dc8fb7 100644
--- a/lib/puppet/util/autoload/file_cache.rb
+++ b/lib/puppet/util/autoload/file_cache.rb
@@ -48,9 +48,7 @@ module Puppet::Util::Autoload::FileCache
def found_file?(path, type = nil)
if data = found_files[path] and ! data_expired?(data[:time])
- if type and ! data[:stat].send(type)
- return false
- end
+ return false if type and ! data[:stat].send(type)
return true
else
return false
diff --git a/lib/puppet/util/cacher.rb b/lib/puppet/util/cacher.rb
index 3a75dc88d..bcd4c1bc1 100644
--- a/lib/puppet/util/cacher.rb
+++ b/lib/puppet/util/cacher.rb
@@ -88,9 +88,7 @@ module Puppet::Util::Cacher
private
def cache_timestamp
- unless defined?(@cache_timestamp)
- @cache_timestamp = Time.now
- end
+ @cache_timestamp = Time.now unless defined?(@cache_timestamp)
@cache_timestamp
end
@@ -102,9 +100,7 @@ module Puppet::Util::Cacher
elsif expired_by_ttl?(name)
value_cache.delete(name)
end
- unless value_cache.include?(name)
- value_cache[name] = send("init_#{name}")
- end
+ value_cache[name] = send("init_#{name}") unless value_cache.include?(name)
value_cache[name]
end
@@ -126,9 +122,7 @@ module Puppet::Util::Cacher
end
def value_cache
- unless defined?(@value_cache) and @value_cache
- @value_cache = {}
- end
+ @value_cache = {} unless defined?(@value_cache) and @value_cache
@value_cache
end
end
diff --git a/lib/puppet/util/classgen.rb b/lib/puppet/util/classgen.rb
index d9022bbdc..d4c693e1e 100644
--- a/lib/puppet/util/classgen.rb
+++ b/lib/puppet/util/classgen.rb
@@ -114,13 +114,9 @@ module Puppet::Util::ClassGen
# Evaluate the passed block if there is one. This should usually
# define all of the work.
- if block
- klass.send(evalmethod, &block)
- end
+ klass.send(evalmethod, &block) if block
- if klass.respond_to? :postinit
- klass.postinit
- end
+ klass.postinit if klass.respond_to? :postinit
# Store the class in hashes or arrays or whatever.
storeclass(klass, name, options)
@@ -148,16 +144,12 @@ module Puppet::Util::ClassGen
# Perform the initializations on the class.
def initclass(klass, options)
- if klass.respond_to? :initvars
- klass.initvars
- end
+ klass.initvars if klass.respond_to? :initvars
if attrs = options[:attributes]
attrs.each do |param, value|
method = param.to_s + "="
- if klass.respond_to? method
- klass.send(method, value)
- end
+ klass.send(method, value) if klass.respond_to? method
end
end
@@ -170,9 +162,7 @@ module Puppet::Util::ClassGen
end
end
- if klass.respond_to? :preinit
- klass.preinit
- end
+ klass.preinit if klass.respond_to? :preinit
end
# Convert our name to a constant.
diff --git a/lib/puppet/util/command_line.rb b/lib/puppet/util/command_line.rb
index fa1b08b70..568d52c47 100644
--- a/lib/puppet/util/command_line.rb
+++ b/lib/puppet/util/command_line.rb
@@ -54,9 +54,7 @@ module Puppet
require_application subcommand_name
Puppet::Application.find(subcommand_name).new(self).run
else
- unless execute_external_subcommand
- abort "Error: Unknown command #{subcommand_name}.\n#{usage_message}"
- end
+ abort "Error: Unknown command #{subcommand_name}.\n#{usage_message}" unless execute_external_subcommand
end
end
diff --git a/lib/puppet/util/docs.rb b/lib/puppet/util/docs.rb
index d73550d9f..beed4bb0b 100644
--- a/lib/puppet/util/docs.rb
+++ b/lib/puppet/util/docs.rb
@@ -84,9 +84,7 @@ module Puppet::Util::Docs
# Stupid markdown
#text = text.gsub("<%=", "&lt;%=")
# For text with no carriage returns, there's nothing to do.
- if text !~ /\n/
- return text
- end
+ return text if text !~ /\n/
indent = nil
# If we can match an indentation, then just remove that same level of
diff --git a/lib/puppet/util/errors.rb b/lib/puppet/util/errors.rb
index d78064227..3aa65d06c 100644
--- a/lib/puppet/util/errors.rb
+++ b/lib/puppet/util/errors.rb
@@ -10,9 +10,7 @@ module Puppet::Util::Errors
error.line ||= self.line if self.respond_to?(:line) and self.line
error.file ||= self.file if self.respond_to?(:file) and self.file
- if other and other.respond_to?(:backtrace)
- error.set_backtrace other.backtrace
- end
+ error.set_backtrace other.backtrace if other and other.respond_to?(:backtrace)
return error
end
diff --git a/lib/puppet/util/feature.rb b/lib/puppet/util/feature.rb
index 40ecfe447..30422ce4c 100644
--- a/lib/puppet/util/feature.rb
+++ b/lib/puppet/util/feature.rb
@@ -13,9 +13,7 @@ class Puppet::Util::Feature
# successfully.
def add(name, options = {})
method = name.to_s + "?"
- if self.class.respond_to?(method)
- raise ArgumentError, "Feature #{name} is already defined"
- end
+ raise ArgumentError, "Feature #{name} is already defined" if self.class.respond_to?(method)
if block_given?
begin
@@ -28,9 +26,7 @@ class Puppet::Util::Feature
end
meta_def(method) do
- unless @results.include?(name)
- @results[name] = test(name, options)
- end
+ @results[name] = test(name, options) unless @results.include?(name)
@results[name]
end
end
@@ -77,9 +73,7 @@ class Puppet::Util::Feature
private
def load_library(lib, name)
- unless lib.is_a?(String)
- raise ArgumentError, "Libraries must be passed as strings not #{lib.class}"
- end
+ raise ArgumentError, "Libraries must be passed as strings not #{lib.class}" unless lib.is_a?(String)
begin
require lib
diff --git a/lib/puppet/util/file_locking.rb b/lib/puppet/util/file_locking.rb
index ab43e2353..cfac5ba16 100644
--- a/lib/puppet/util/file_locking.rb
+++ b/lib/puppet/util/file_locking.rb
@@ -16,9 +16,7 @@ module Puppet::Util::FileLocking
# Create an exclusive lock for writing, and do the writing in a
# tmp file.
def writelock(file, mode = nil)
- unless FileTest.directory?(File.dirname(file))
- raise Puppet::DevError, "Cannot create #{file}; directory #{File.dirname(file)} does not exist"
- end
+ raise Puppet::DevError, "Cannot create #{file}; directory #{File.dirname(file)} does not exist" unless FileTest.directory?(File.dirname(file))
raise ArgumentError, "#{file} is not a file" unless !File.exists?(file) or File.file?(file)
tmpfile = file + ".tmp"
diff --git a/lib/puppet/util/fileparsing.rb b/lib/puppet/util/fileparsing.rb
index 974d908b8..7348b8946 100644
--- a/lib/puppet/util/fileparsing.rb
+++ b/lib/puppet/util/fileparsing.rb
@@ -43,18 +43,14 @@ module Puppet::Util::FileParsing
def fields=(fields)
@fields = fields.collect do |field|
r = symbolize(field)
- if INVALID_FIELDS.include?(r)
- raise ArgumentError.new("Cannot have fields named #{r}")
- end
+ raise ArgumentError.new("Cannot have fields named #{r}") if INVALID_FIELDS.include?(r)
r
end
end
def initialize(type, options = {}, &block)
@type = symbolize(type)
- unless [:record, :text].include?(@type)
- raise ArgumentError, "Invalid record type #{@type}"
- end
+ raise ArgumentError, "Invalid record type #{@type}" unless [:record, :text].include?(@type)
set_options(options)
@@ -64,9 +60,7 @@ module Puppet::Util::FileParsing
self.separator ||= /\s+/
self.joiner ||= " "
self.optional ||= []
- unless defined?(@rollup)
- @rollup = true
- end
+ @rollup = true unless defined?(@rollup)
end
if block_given?
@@ -213,9 +207,7 @@ module Puppet::Util::FileParsing
end
def line_separator
- unless defined?(@line_separator)
- @line_separator = "\n"
- end
+ @line_separator = "\n" unless defined?(@line_separator)
@line_separator
end
@@ -244,18 +236,14 @@ module Puppet::Util::FileParsing
# Handle parsing a single line.
def parse_line(line)
- unless records?
- raise Puppet::DevError, "No record types defined; cannot parse lines"
- end
+ raise Puppet::DevError, "No record types defined; cannot parse lines" unless records?
@record_order.each do |record|
# These are basically either text or record lines.
method = "handle_#{record.type}_line"
if respond_to?(method)
if result = send(method, line, record)
- if record.respond_to?(:post_parse)
- record.send(:post_parse, result)
- end
+ record.send(:post_parse, result) if record.respond_to?(:post_parse)
return result
end
else
@@ -282,9 +270,7 @@ module Puppet::Util::FileParsing
# the regex will be removed.
# * <tt>:separator</tt>: The record separator. Defaults to /\s+/.
def record_line(name, options, &block)
- unless options.include?(:fields)
- raise ArgumentError, "Must include a list of fields"
- end
+ raise ArgumentError, "Must include a list of fields" unless options.include?(:fields)
record = FileRecord.new(:record, options, &block)
record.name = symbolize(name)
@@ -299,9 +285,7 @@ module Puppet::Util::FileParsing
# Define a new type of text record.
def text_line(name, options, &block)
- unless options.include?(:match)
- raise ArgumentError, "You must provide a :match regex for text lines"
- end
+ raise ArgumentError, "You must provide a :match regex for text lines" unless options.include?(:match)
record = FileRecord.new(:text, options, &block)
record.name = symbolize(name)
@@ -313,9 +297,7 @@ module Puppet::Util::FileParsing
def to_file(records)
text = records.collect { |record| to_line(record) }.join(line_separator)
- if trailing_separator
- text += line_separator
- end
+ text += line_separator if trailing_separator
return text
end
@@ -334,9 +316,7 @@ module Puppet::Util::FileParsing
case record.type
when :text; return details[:line]
else
- if record.respond_to?(:to_line)
- return record.to_line(details)
- end
+ return record.to_line(details) if record.respond_to?(:to_line)
line = record.join(details)
@@ -381,9 +361,7 @@ module Puppet::Util::FileParsing
@record_types ||= {}
@record_order ||= []
- if @record_types.include?(record.name)
- raise ArgumentError, "Line type #{record.name} is already defined"
- end
+ raise ArgumentError, "Line type #{record.name} is already defined" if @record_types.include?(record.name)
@record_types[record.name] = record
@record_order << record
diff --git a/lib/puppet/util/filetype.rb b/lib/puppet/util/filetype.rb
index 3df4fdee0..4d7da67eb 100755
--- a/lib/puppet/util/filetype.rb
+++ b/lib/puppet/util/filetype.rb
@@ -44,9 +44,7 @@ class Puppet::Util::FileType
rescue Puppet::Error => detail
raise
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
raise Puppet::Error, "#{self.class} could not read #{@path}: #{detail}"
end
end
@@ -61,9 +59,7 @@ class Puppet::Util::FileType
rescue Puppet::Error => detail
raise
rescue => detail
- if Puppet[:debug]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:debug]
raise Puppet::Error, "#{self.class} could not write #{@path}: #{detail}"
end
end
@@ -76,9 +72,7 @@ class Puppet::Util::FileType
# Pick or create a filebucket to use.
def bucket
- unless defined?(@bucket)
- @bucket = Puppet::Type.type(:filebucket).mkdefaultbucket.bucket
- end
+ @bucket = Puppet::Type.type(:filebucket).mkdefaultbucket.bucket unless defined?(@bucket)
@bucket
end
@@ -105,9 +99,7 @@ class Puppet::Util::FileType
# Remove the file.
def remove
- if File.exist?(@path)
- File.unlink(@path)
- end
+ File.unlink(@path) if File.exist?(@path)
end
# Overwrite the file.
@@ -260,9 +252,7 @@ class Puppet::Util::FileType
def read
begin
output = Puppet::Util.execute(%w{crontab -l}, :uid => @path)
- if output.include?("You are not authorized to use the cron command")
- raise Puppet::Error, "User #{@path} not authorized to use cron"
- end
+ raise Puppet::Error, "User #{@path} not authorized to use cron" if output.include?("You are not authorized to use the cron command")
return output
rescue => detail
raise Puppet::Error, "Could not read crontab for #{@path}: #{detail}"
diff --git a/lib/puppet/util/graph.rb b/lib/puppet/util/graph.rb
index a052bf8f1..5dd55e951 100644
--- a/lib/puppet/util/graph.rb
+++ b/lib/puppet/util/graph.rb
@@ -18,9 +18,7 @@ module Puppet::Util::Graph
unless block_given? and ! yield(child)
graph.add_edge(self, child)
- if child.respond_to?(:to_graph)
- child.to_graph(graph, &block)
- end
+ child.to_graph(graph, &block) if child.respond_to?(:to_graph)
end
end
diff --git a/lib/puppet/util/inifile.rb b/lib/puppet/util/inifile.rb
index 38bc1c574..b90134835 100644
--- a/lib/puppet/util/inifile.rb
+++ b/lib/puppet/util/inifile.rb
@@ -56,9 +56,7 @@ module Puppet::Util::IniConfig
# exists, return nil
def [](key)
entry = find_entry(key)
- if entry.nil?
- return nil
- end
+ return nil if entry.nil?
return entry[1]
end
@@ -69,9 +67,7 @@ module Puppet::Util::IniConfig
@entries.each do |entry|
if entry.is_a?(Array)
key, value = entry
- unless value.nil?
- text << "#{key}=#{value}\n"
- end
+ text << "#{key}=#{value}\n" unless value.nil?
else
text << entry
end
@@ -82,9 +78,7 @@ module Puppet::Util::IniConfig
private
def find_entry(key)
@entries.each do |entry|
- if entry.is_a?(Array) && entry[0] == key
- return entry
- end
+ return entry if entry.is_a?(Array) && entry[0] == key
end
return nil
end
@@ -102,9 +96,7 @@ module Puppet::Util::IniConfig
# already existing sections
def read(file)
text = Puppet::Util::FileType.filetype(:flat).new(file).read
- if text.nil?
- raise "Could not find #{file}"
- end
+ raise "Could not find #{file}" if text.nil?
section = nil # The name of the current section
optname = nil # The name of the last option in section
@@ -172,9 +164,7 @@ module Puppet::Util::IniConfig
def each_section(&block)
@files.each do |file, list|
list.each do |entry|
- if entry.is_a?(Section)
- yield(entry)
- end
+ yield(entry) if entry.is_a?(Section)
end
end
end
@@ -203,9 +193,7 @@ module Puppet::Util::IniConfig
# Add a section to be stored in FILE when store is called
def add_section(name, file)
- if include?(name)
- raise "A section with name #{name} already exists"
- end
+ raise "A section with name #{name} already exists" if include?(name)
result = Section.new(name, file)
@files[file] ||= []
@files[file] << result
diff --git a/lib/puppet/util/inline_docs.rb b/lib/puppet/util/inline_docs.rb
index 405b53945..695b8e8df 100644
--- a/lib/puppet/util/inline_docs.rb
+++ b/lib/puppet/util/inline_docs.rb
@@ -15,9 +15,7 @@ module Puppet::Util::InlineDocs
attr_writer :doc
def doc
- unless defined?(@doc) and @doc
- @doc = ""
- end
+ @doc = "" unless defined?(@doc) and @doc
@doc
end
diff --git a/lib/puppet/util/loadedfile.rb b/lib/puppet/util/loadedfile.rb
index c91fb847f..3dd8151a4 100755
--- a/lib/puppet/util/loadedfile.rb
+++ b/lib/puppet/util/loadedfile.rb
@@ -16,9 +16,7 @@ module Puppet
# be reparsed.
def changed?
# Allow the timeout to be disabled entirely.
- if Puppet[:filetimeout] < 0
- return true
- end
+ return true if Puppet[:filetimeout] < 0
tmp = stamp()
# We use a different internal variable than the stamp method
diff --git a/lib/puppet/util/log.rb b/lib/puppet/util/log.rb
index ac1992526..5dea6d67f 100644
--- a/lib/puppet/util/log.rb
+++ b/lib/puppet/util/log.rb
@@ -47,12 +47,8 @@ class Puppet::Util::Log
# undefs other objects.
def Log.close(destination)
if @destinations.include?(destination)
- if @destinations[destination].respond_to?(:flush)
- @destinations[destination].flush
- end
- if @destinations[destination].respond_to?(:close)
- @destinations[destination].close
- end
+ @destinations[destination].flush if @destinations[destination].respond_to?(:flush)
+ @destinations[destination].close if @destinations[destination].respond_to?(:close)
@destinations.delete(destination)
end
end
@@ -66,21 +62,15 @@ class Puppet::Util::Log
# Flush any log destinations that support such operations.
def Log.flush
@destinations.each { |type, dest|
- if dest.respond_to?(:flush)
- dest.flush
- end
+ dest.flush if dest.respond_to?(:flush)
}
end
# Create a new log message. The primary role of this method is to
# avoid creating log messages below the loglevel.
def Log.create(hash)
- unless hash.include?(:level)
- raise Puppet::DevError, "Logs require a level"
- end
- unless @levels.index(hash[:level])
- raise Puppet::DevError, "Invalid log level #{hash[:level]}"
- end
+ raise Puppet::DevError, "Logs require a level" unless hash.include?(:level)
+ raise Puppet::DevError, "Invalid log level #{hash[:level]}" unless @levels.index(hash[:level])
if @levels.index(hash[:level]) >= @loglevel
return Puppet::Util::Log.new(hash)
else
@@ -104,13 +94,9 @@ class Puppet::Util::Log
# Set the current log level.
def Log.level=(level)
- unless level.is_a?(Symbol)
- level = level.intern
- end
+ level = level.intern unless level.is_a?(Symbol)
- unless @levels.include?(level)
- raise Puppet::DevError, "Invalid loglevel #{level}"
- end
+ raise Puppet::DevError, "Invalid loglevel #{level}" unless @levels.include?(level)
@loglevel = @levels.index(level)
end
@@ -130,9 +116,7 @@ class Puppet::Util::Log
klass.match?(dest)
end
- unless type
- raise Puppet::DevError, "Unknown destination type #{dest}"
- end
+ raise Puppet::DevError, "Unknown destination type #{dest}" unless type
begin
if type.instance_method(:initialize).arity == 1
@@ -143,14 +127,10 @@ class Puppet::Util::Log
flushqueue
@destinations[dest]
rescue => detail
- if Puppet[:debug]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:debug]
# If this was our only destination, then add the console back in.
- if @destinations.empty? and (dest != :console and dest != "console")
- newdestination(:console)
- end
+ newdestination(:console) if @destinations.empty? and (dest != :console and dest != "console")
end
end
@@ -159,9 +139,7 @@ class Puppet::Util::Log
# a potential for a loop here, if the machine somehow gets the destination set as
# itself.
def Log.newmessage(msg)
- if @levels.index(msg.level) < @loglevel
- return
- end
+ return if @levels.index(msg.level) < @loglevel
queuemessage(msg) if @destinations.length == 0
@@ -193,9 +171,7 @@ class Puppet::Util::Log
Puppet.notice "Reopening log files"
types = @destinations.keys
@destinations.each { |type, dest|
- if dest.respond_to?(:close)
- dest.close
- end
+ dest.close if dest.respond_to?(:close)
}
@destinations.clear
# We need to make sure we always end up with some kind of destination
diff --git a/lib/puppet/util/log/destinations.rb b/lib/puppet/util/log/destinations.rb
index 37e6d1ae9..6c94247ea 100644
--- a/lib/puppet/util/log/destinations.rb
+++ b/lib/puppet/util/log/destinations.rb
@@ -4,9 +4,7 @@ Puppet::Util::Log.newdesttype :syslog do
end
def initialize
- if Syslog.opened?
- Syslog.close
- end
+ Syslog.close if Syslog.opened?
name = Puppet[:name]
name = "puppet-#{name}" unless name =~ /puppet/
@@ -49,9 +47,7 @@ Puppet::Util::Log.newdesttype :file do
end
def flush
- if defined?(@file)
- @file.flush
- end
+ @file.flush if defined?(@file)
end
def initialize(path)
@@ -158,14 +154,10 @@ Puppet::Util::Log.newdesttype :host do
def handle(msg)
unless msg.is_a?(String) or msg.remote
- unless defined?(@hostname)
- @hostname = Facter["hostname"].value
- end
+ @hostname = Facter["hostname"].value unless defined?(@hostname)
unless defined?(@domain)
@domain = Facter["domain"].value
- if @domain
- @hostname += ".#{@domain}"
- end
+ @hostname += ".#{@domain}" if @domain
end
if msg.source =~ /^\//
msg.source = @hostname + ":#{msg.source}"
@@ -187,9 +179,7 @@ Puppet::Util::Log.newdesttype :host do
# Add the hostname to the source
@driver.addlog(tmp)
rescue => detail
- if Puppet[:trace]
- puts detail.backtrace
- end
+ puts detail.backtrace if Puppet[:trace]
Puppet.err detail
Puppet::Util::Log.close(self)
end
diff --git a/lib/puppet/util/log_paths.rb b/lib/puppet/util/log_paths.rb
index b5bdc50de..3132238e2 100644
--- a/lib/puppet/util/log_paths.rb
+++ b/lib/puppet/util/log_paths.rb
@@ -5,9 +5,7 @@ module Puppet::Util::LogPaths
# return the full path to us, for logging and rollback
# some classes (e.g., FileTypeRecords) will have to override this
def path
- unless defined?(@path)
- @path = pathbuilder
- end
+ @path = pathbuilder unless defined?(@path)
return "/" + @path.join("/")
end
diff --git a/lib/puppet/util/logging.rb b/lib/puppet/util/logging.rb
index 3af698062..fa50efa0a 100644
--- a/lib/puppet/util/logging.rb
+++ b/lib/puppet/util/logging.rb
@@ -10,9 +10,7 @@ module Puppet::Util::Logging
# Create a method for each log level.
Puppet::Util::Log.eachlevel do |level|
define_method(level) do |args|
- if args.is_a?(Array)
- args = args.join(" ")
- end
+ args = args.join(" ") if args.is_a?(Array)
send_log(level, args)
end
end
diff --git a/lib/puppet/util/methodhelper.rb b/lib/puppet/util/methodhelper.rb
index 771d0e648..f8dc2cedc 100644
--- a/lib/puppet/util/methodhelper.rb
+++ b/lib/puppet/util/methodhelper.rb
@@ -2,9 +2,7 @@
module Puppet::Util::MethodHelper
def requiredopts(*names)
names.each do |name|
- if self.send(name).nil?
- devfail("#{name} is a required option for #{self.class}")
- end
+ devfail("#{name} is a required option for #{self.class}") if self.send(name).nil?
end
end
diff --git a/lib/puppet/util/metric.rb b/lib/puppet/util/metric.rb
index e8de54cf2..6f5b2cf9b 100644
--- a/lib/puppet/util/metric.rb
+++ b/lib/puppet/util/metric.rb
@@ -118,9 +118,7 @@ class Puppet::Util::Metric
Puppet.warning "RRD library is missing; cannot store metrics"
return
end
- unless FileTest.exists?(self.path)
- self.create(time - 5)
- end
+ self.create(time - 5) unless FileTest.exists?(self.path)
@rrd ||= RRDtool.new(self.path)
diff --git a/lib/puppet/util/package.rb b/lib/puppet/util/package.rb
index 874e782ca..24df1c727 100644
--- a/lib/puppet/util/package.rb
+++ b/lib/puppet/util/package.rb
@@ -4,7 +4,7 @@ module Puppet::Util::Package
ax = version_a.scan(vre)
bx = version_b.scan(vre)
- while (ax.length>0 && bx.length>0) do
+ while (ax.length>0 && bx.length>0)
a = ax.shift
b = bx.shift
diff --git a/lib/puppet/util/rdoc/generators/puppet_generator.rb b/lib/puppet/util/rdoc/generators/puppet_generator.rb
index f73b18dce..9d41a71ef 100644
--- a/lib/puppet/util/rdoc/generators/puppet_generator.rb
+++ b/lib/puppet/util/rdoc/generators/puppet_generator.rb
@@ -232,17 +232,13 @@ module Generators
res1 = []
collection['classes'].sort.each do |f|
if f.document_self
- unless f.context.is_module?
- res1 << { "href" => "../"+CGI.escapeHTML(f.path), "name" => CGI.escapeHTML(f.index_name) }
- end
+ res1 << { "href" => "../"+CGI.escapeHTML(f.path), "name" => CGI.escapeHTML(f.index_name) } unless f.context.is_module?
end
end
res2 = []
collection['methods'].sort.each do |f|
- if f.document_self
- res2 << { "href" => "../#{f.path}", "name" => f.index_name.sub(/\(.*\)$/,'') }
- end
+ res2 << { "href" => "../#{f.path}", "name" => f.index_name.sub(/\(.*\)$/,'') } if f.document_self
end
module_name = []
@@ -264,9 +260,7 @@ module Generators
res5 = []
collection['nodes'].sort.each do |f|
- if f.document_self
- res5 << { "href" => "../"+CGI.escapeHTML(f.path), "name" => CGI.escapeHTML(f.name) }
- end
+ res5 << { "href" => "../"+CGI.escapeHTML(f.path), "name" => CGI.escapeHTML(f.name) } if f.document_self
end
values = {
@@ -467,9 +461,7 @@ module Generators
# which is also its url
def http_url(full_name, prefix)
path = full_name.dup
- if path['<<']
- path.gsub!(/<<\s*(\w*)/) { "from-#$1" }
- end
+ path.gsub!(/<<\s*(\w*)/) { "from-#$1" } if path['<<']
File.join(prefix, path.split("::").collect { |p| Digest::MD5.hexdigest(p) }) + ".html"
end
@@ -581,9 +573,7 @@ module Generators
c = @context
c = c.parent while c and !c.diagram
- if c && c.diagram
- @values["diagram"] = diagram_reference(c.diagram)
- end
+ @values["diagram"] = diagram_reference(c.diagram) if c && c.diagram
@values["full_name"] = h_name
@@ -599,9 +589,7 @@ module Generators
end
lookup = "NODE(#{lookup})"
parent_url = AllReferences[lookup] || AllReferences[parent_class]
- if parent_url and parent_url.document_self
- @values["par_url"] = aref_to(parent_url.path)
- end
+ @values["par_url"] = aref_to(parent_url.path) if parent_url and parent_url.document_self
end
files = []
@@ -612,9 +600,7 @@ module Generators
res["full_path"] = full_path
res["full_path_url"] = aref_to(f.viewer.path) if f.document_self
- if @options.webcvs
- res["cvsurl"] = cvs_url( @options.webcvs, full_path )
- end
+ res["cvsurl"] = cvs_url( @options.webcvs, full_path ) if @options.webcvs
files << res
end
@@ -723,9 +709,7 @@ module Generators
# which is also its url
def http_url(full_name, prefix)
path = full_name.dup
- if path['<<']
- path.gsub!(/<<\s*(\w*)/) { "from-#$1" }
- end
+ path.gsub!(/<<\s*(\w*)/) { "from-#$1" } if path['<<']
File.join(prefix, path.split("::")) + ".html"
end
@@ -802,9 +786,7 @@ module Generators
res["full_path"] = full_path
res["full_path_url"] = aref_to(f.viewer.path) if f.document_self
- if @options.webcvs
- res["cvsurl"] = cvs_url( @options.webcvs, full_path )
- end
+ res["cvsurl"] = cvs_url( @options.webcvs, full_path ) if @options.webcvs
files << res
end
@@ -895,9 +877,7 @@ module Generators
def find_symbol(symbol, method=nil)
res = @context.parent.find_symbol(symbol, method)
- if res
- res = res.viewer
- end
+ res = res.viewer if res
res
end
diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb
index 9d14ae6eb..cc767fa05 100644
--- a/lib/puppet/util/rdoc/parser.rb
+++ b/lib/puppet/util/rdoc/parser.rb
@@ -67,9 +67,7 @@ class Parser
names.each do |name|
prev_container = container
container = find_object_named(container, name)
- unless container
- container = prev_container.add_class(PuppetClass, name, nil)
- end
+ container = prev_container.add_class(PuppetClass, name, nil) unless container
end
return [container, final_name]
end
diff --git a/lib/puppet/util/reference.rb b/lib/puppet/util/reference.rb
index c5bfe4722..314f9c136 100644
--- a/lib/puppet/util/reference.rb
+++ b/lib/puppet/util/reference.rb
@@ -147,9 +147,7 @@ class Puppet::Util::Reference
options[:level] ||= 5
#str = "#{name} : "
str = h(name, options[:level])
- if options[:namevar]
- str += "- **namevar**\n\n"
- end
+ str += "- **namevar**\n\n" if options[:namevar]
str += text
#str += text.gsub(/\n/, "\n ")
@@ -170,17 +168,13 @@ class Puppet::Util::Reference
# First the header
text = h(@title, 1)
text += "\n\n**This page is autogenerated; any changes will get overwritten** *(last generated on #{Time.now.to_s})*\n\n"
- if withcontents
- text += ".. contents:: :depth: #{@depth}\n\n"
- end
+ text += ".. contents:: :depth: #{@depth}\n\n" if withcontents
text += @header
text += generate()
- if withcontents
- text += self.class.footer
- end
+ text += self.class.footer if withcontents
return text
end
diff --git a/lib/puppet/util/selinux.rb b/lib/puppet/util/selinux.rb
index fad15d74e..7c6177f81 100644
--- a/lib/puppet/util/selinux.rb
+++ b/lib/puppet/util/selinux.rb
@@ -14,9 +14,7 @@ require 'pathname'
module Puppet::Util::SELinux
def selinux_support?
- unless defined?(Selinux)
- return false
- end
+ return false unless defined?(Selinux)
if Selinux.is_selinux_enabled == 1
return true
end
@@ -26,9 +24,7 @@ module Puppet::Util::SELinux
# Retrieve and return the full context of the file. If we don't have
# SELinux support or if the SELinux call fails then return nil.
def get_selinux_current_context(file)
- unless selinux_support?
- return nil
- end
+ return nil unless selinux_support?
retval = Selinux.lgetfilecon(file)
if retval == -1
return nil
@@ -39,14 +35,10 @@ module Puppet::Util::SELinux
# Retrieve and return the default context of the file. If we don't have
# SELinux support or if the SELinux call fails to file a default then return nil.
def get_selinux_default_context(file)
- unless selinux_support?
- return nil
- end
+ return nil unless selinux_support?
# If the filesystem has no support for SELinux labels, return a default of nil
# instead of what matchpathcon would return
- unless selinux_label_support?(file)
- return nil
- end
+ return nil unless selinux_label_support?(file)
# If the file exists we should pass the mode to matchpathcon for the most specific
# matching. If not, we can pass a mode of 0.
begin
@@ -89,9 +81,7 @@ module Puppet::Util::SELinux
# I believe that the OS should always provide at least a fall-through context
# though on any well-running system.
def set_selinux_context(file, value, component = false)
- unless selinux_support? && selinux_label_support?(file)
- return nil
- end
+ return nil unless selinux_support? && selinux_label_support?(file)
if component
# Must first get existing context to replace a single component
@@ -137,9 +127,7 @@ module Puppet::Util::SELinux
# the file.
def set_selinux_default_context(file)
new_context = get_selinux_default_context(file)
- unless new_context
- return nil
- end
+ return nil unless new_context
cur_context = get_selinux_current_context(file)
if new_context != cur_context
set_selinux_context(file, new_context)
@@ -207,10 +195,8 @@ module Puppet::Util::SELinux
# Remove the last slash and everything after it,
# and repeat with that as the file for the next loop through.
path = realpath(path)
- while not path.empty? do
- if mnts.has_key?(path)
- return mnts[path]
- end
+ while not path.empty?
+ return mnts[path] if mnts.has_key?(path)
path = parent_directory(path)
end
return mnts['/']
@@ -222,9 +208,7 @@ module Puppet::Util::SELinux
# false if not.
def selinux_label_support?(file)
fstype = find_fs(file)
- if fstype.nil?
- return false
- end
+ return false if fstype.nil?
filesystems = ['ext2', 'ext3', 'ext4', 'gfs', 'gfs2', 'xfs', 'jfs']
return filesystems.include?(fstype)
end
diff --git a/lib/puppet/util/settings.rb b/lib/puppet/util/settings.rb
index afec53a8a..b8f4effba 100644
--- a/lib/puppet/util/settings.rb
+++ b/lib/puppet/util/settings.rb
@@ -76,9 +76,7 @@ class Puppet::Util::Settings
# Don't clear the 'used' in this case, since it's a config file reparse,
# and we want to retain this info.
- unless exceptcli
- @used = []
- end
+ @used = [] unless exceptcli
@cache.clear
end
@@ -377,9 +375,7 @@ class Puppet::Util::Settings
# a default or a value, so we can't actually assign it.
def newsetting(hash)
klass = nil
- if hash[:section]
- hash[:section] = hash[:section].to_sym
- end
+ hash[:section] = hash[:section].to_sym if hash[:section]
if type = hash[:type]
unless klass = {:setting => Setting, :file => FileSetting, :boolean => BooleanSetting}[type]
raise ArgumentError, "Invalid setting type '#{type}'"
@@ -457,9 +453,7 @@ class Puppet::Util::Settings
self.each { |name, obj|
section = obj.section || "puppet"
sections[section] ||= []
- unless sectionlist.include?(section)
- sectionlist << section
- end
+ sectionlist << section unless sectionlist.include?(section)
sections[section] << obj
}
@@ -477,7 +471,7 @@ class Puppet::Util::Settings
end
def legacy_to_mode(type, param)
- if not defined?(@app_names) then
+ if not defined?(@app_names)
require 'puppet/util/command_line'
command_line = Puppet::Util::CommandLine.new
@app_names = Puppet::Util::CommandLine::LegacyName.inject({}) do |hash, pair|
@@ -504,12 +498,8 @@ class Puppet::Util::Settings
"Attempt to assign a value to unknown configuration parameter #{param.inspect}"
end
end
- if setting.respond_to?(:munge)
- value = setting.munge(value)
- end
- if setting.respond_to?(:handle) and not options[:dont_trigger_handles]
- setting.handle(value)
- end
+ value = setting.munge(value) if setting.respond_to?(:munge)
+ setting.handle(value) if setting.respond_to?(:handle) and not options[:dont_trigger_handles]
if ReadOnly.include? param and type != :mutable_defaults
raise ArgumentError,
"You're attempting to set configuration parameter $#{param}, which is read-only."
@@ -549,9 +539,7 @@ class Puppet::Util::Settings
name = name.to_sym
hash[:name] = name
hash[:section] = section
- if @config.include?(name)
- raise ArgumentError, "Parameter #{name} is already defined"
- end
+ raise ArgumentError, "Parameter #{name} is already defined" if @config.include?(name)
tryconfig = newsetting(hash)
if short = tryconfig.short
if other = @shortnames[short]
@@ -682,9 +670,7 @@ if @config.include?(:run_mode)
# Look for the value. We have to test the hash for whether
# it exists, because the value might be false.
@sync.synchronize do
- if @values[source].include?(param)
- throw :foundval, @values[source][param]
- end
+ throw :foundval, @values[source][param] if @values[source].include?(param)
end
end
throw :foundval, nil
@@ -749,9 +735,7 @@ if @config.include?(:run_mode)
Puppet::Util::SUIDManager.asuser(*chown) do
mode = obj.mode || 0640
- if args.empty?
- args << "w"
- end
+ args << "w" if args.empty?
args << mode
@@ -768,9 +752,7 @@ if @config.include?(:run_mode)
file = value(get_config_file_default(default).name)
tmpfile = file + ".tmp"
sync = Sync.new
- unless FileTest.directory?(File.dirname(tmpfile))
- raise Puppet::DevError, "Cannot create #{file}; directory #{File.dirname(file)} does not exist"
- end
+ raise Puppet::DevError, "Cannot create #{file}; directory #{File.dirname(file)} does not exist" unless FileTest.directory?(File.dirname(tmpfile))
sync.synchronize(Sync::EX) do
File.open(file, ::File::CREAT|::File::RDWR, 0600) do |rf|
@@ -806,9 +788,7 @@ if @config.include?(:run_mode)
raise ArgumentError, "Unknown default #{default}"
end
- unless obj.is_a? FileSetting
- raise ArgumentError, "Default #{default} is not a file"
- end
+ raise ArgumentError, "Default #{default} is not a file" unless obj.is_a? FileSetting
return obj
end
@@ -824,9 +804,7 @@ if @config.include?(:run_mode)
if user = setting.owner and user != "root" and catalog.resource(:user, user).nil?
resource = Puppet::Resource.new(:user, user, :parameters => {:ensure => :present})
- if self[:group]
- resource[:gid] = self[:group]
- end
+ resource[:gid] = self[:group] if self[:group]
catalog.add_resource resource
end
if group = setting.group and ! %w{root wheel}.include?(group) and catalog.resource(:group, group).nil?
@@ -859,9 +837,7 @@ if @config.include?(:run_mode)
if str =~ /^\s*(\w+)\s*=\s*([\w\d]+)\s*$/
param, value = $1.intern, $2
result[param] = value
- unless [:owner, :mode, :group].include?(param)
- raise ArgumentError, "Invalid file option '#{param}'"
- end
+ raise ArgumentError, "Invalid file option '#{param}'" unless [:owner, :mode, :group].include?(param)
if param == :mode and value !~ /^\d+$/
raise ArgumentError, "File modes must be numbers"
diff --git a/lib/puppet/util/settings/setting.rb b/lib/puppet/util/settings/setting.rb
index 6f8e39209..c3a037102 100644
--- a/lib/puppet/util/settings/setting.rb
+++ b/lib/puppet/util/settings/setting.rb
@@ -37,16 +37,12 @@ class Puppet::Util::Settings::Setting
args.each do |param, value|
method = param.to_s + "="
- unless self.respond_to? method
- raise ArgumentError, "#{self.class} does not accept #{param}"
- end
+ raise ArgumentError, "#{self.class} does not accept #{param}" unless self.respond_to? method
self.send(method, value)
end
- unless self.desc
- raise ArgumentError, "You must provide a description for the #{self.name} config option"
- end
+ raise ArgumentError, "You must provide a description for the #{self.name} config option" unless self.desc
end
def iscreated
@@ -71,9 +67,7 @@ class Puppet::Util::Settings::Setting
# short name for the celement
def short=(value)
- if value.to_s.length != 1
- raise ArgumentError, "Short names can only be one character."
- end
+ raise ArgumentError, "Short names can only be one character." if value.to_s.length != 1
@short = value.to_s
end
@@ -82,9 +76,7 @@ class Puppet::Util::Settings::Setting
str = @desc.gsub(/^/, "# ") + "\n"
# Add in a statement about the default.
- if defined?(@default) and @default
- str += "# The default value is '#{@default}'.\n"
- end
+ str += "# The default value is '#{@default}'.\n" if defined?(@default) and @default
# If the value has not been overridden, then print it out commented
# and unconverted, so it's clear that that's the default and how it
diff --git a/lib/puppet/util/storage.rb b/lib/puppet/util/storage.rb
index 974d56f56..8ca1881ed 100644
--- a/lib/puppet/util/storage.rb
+++ b/lib/puppet/util/storage.rb
@@ -47,9 +47,7 @@ class Puppet::Util::Storage
Puppet.settings.use(:main) unless FileTest.directory?(Puppet[:statedir])
unless File.exists?(Puppet[:statefile])
- unless defined?(@@state) and ! @@state.nil?
- self.init
- end
+ self.init unless defined?(@@state) and ! @@state.nil?
return
end
unless File.file?(Puppet[:statefile])
@@ -87,9 +85,7 @@ class Puppet::Util::Storage
def self.store
Puppet.debug "Storing state"
- unless FileTest.exist?(Puppet[:statefile])
- Puppet.info "Creating state file #{Puppet[:statefile]}"
- end
+ Puppet.info "Creating state file #{Puppet[:statefile]}" unless FileTest.exist?(Puppet[:statefile])
Puppet::Util.benchmark(:debug, "Stored state") do
Puppet::Util::FileLocking.writelock(Puppet[:statefile], 0660) do |file|
diff --git a/lib/puppet/util/subclass_loader.rb b/lib/puppet/util/subclass_loader.rb
index 80a3672c9..505c4b0a5 100644
--- a/lib/puppet/util/subclass_loader.rb
+++ b/lib/puppet/util/subclass_loader.rb
@@ -15,9 +15,7 @@ module Puppet::Util::SubclassLoader
# The hook method that sets up subclass loading. We need the name
# of the method to create and the path in which to look for them.
def handle_subclasses(name, path)
- unless self.is_a?(Class)
- raise ArgumentError, "Must be a class to use SubclassLoader"
- end
+ raise ArgumentError, "Must be a class to use SubclassLoader" unless self.is_a?(Class)
@subclasses = []
@loader = Puppet::Util::Autoload.new(
@@ -41,9 +39,7 @@ module Puppet::Util::SubclassLoader
# Now make the method that returns this subclass. This way we
# normally avoid the method_missing method.
- if c and ! respond_to?(subname)
- define_method(subname) { c }
- end
+ define_method(subname) { c } if c and ! respond_to?(subname)
end
return c
end
@@ -76,9 +72,7 @@ module Puppet::Util::SubclassLoader
# Retrieve or calculate a name.
def name(dummy_argument=:work_arround_for_ruby_GC_bug)
- unless defined?(@name)
- @name = self.to_s.sub(/.+::/, '').intern
- end
+ @name = self.to_s.sub(/.+::/, '').intern unless defined?(@name)
return @name
end
diff --git a/lib/puppet/util/tagging.rb b/lib/puppet/util/tagging.rb
index 51cff9520..1f185e42c 100644
--- a/lib/puppet/util/tagging.rb
+++ b/lib/puppet/util/tagging.rb
@@ -36,9 +36,7 @@ module Puppet::Util::Tagging
return if tags.nil? or tags == ""
- if tags.is_a?(String)
- tags = tags.strip.split(/\s*,\s*/)
- end
+ tags = tags.strip.split(/\s*,\s*/) if tags.is_a?(String)
tags.each do |t|
tag(t)
diff --git a/spec/unit/provider/mount/parsed_spec.rb b/spec/unit/provider/mount/parsed_spec.rb
index 4db167e23..8d1c6ad9e 100755
--- a/spec/unit/provider/mount/parsed_spec.rb
+++ b/spec/unit/provider/mount/parsed_spec.rb
@@ -40,9 +40,7 @@ module ParsedMountTesting
}
@provider_class.fields(:parsed).each do |field|
- unless args.include? field
- args[field] = "fake#{field}#{@pcount}"
- end
+ args[field] = "fake#{field}#{@pcount}" unless args.include? field
end
return args
diff --git a/spec/unit/resource/catalog_spec.rb b/spec/unit/resource/catalog_spec.rb
index 00c17b3e5..8105198df 100755
--- a/spec/unit/resource/catalog_spec.rb
+++ b/spec/unit/resource/catalog_spec.rb
@@ -579,9 +579,7 @@ describe Puppet::Resource::Catalog, "when compiling" do
@catalog.add_resource(resource)
@catalog.resource(:file, resource.title).should equal(resource)
# We can't use .should here, because the resources respond to that method.
- if @catalog.resource(:file, resource.name)
- raise "Aliased non-isomorphic resource"
- end
+ raise "Aliased non-isomorphic resource" if @catalog.resource(:file, resource.name)
end
it "should provide a method to create additional resources that also registers the resource" do
diff --git a/spec/unit/type/group_spec.rb b/spec/unit/type/group_spec.rb
index 0bd7c513d..c563d137b 100755
--- a/spec/unit/type/group_spec.rb
+++ b/spec/unit/type/group_spec.rb
@@ -4,9 +4,7 @@ require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Type.type(:group) do
before do
- unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
- ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin"
- end
+ ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin" unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
@class = Puppet::Type.type(:group)
end
diff --git a/spec/unit/type/user_spec.rb b/spec/unit/type/user_spec.rb
index 5a43c9595..c1953bcb5 100755
--- a/spec/unit/type/user_spec.rb
+++ b/spec/unit/type/user_spec.rb
@@ -6,9 +6,7 @@ user = Puppet::Type.type(:user)
describe user do
before do
- unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
- ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin"
- end
+ ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin" unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
@provider = stub 'provider'
@resource = stub 'resource', :resource => nil, :provider => @provider, :line => nil, :file => nil
end
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index cd8015db7..c42d67397 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -178,9 +178,7 @@ class TestSnippets < Test::Unit::TestCase
%w{a b c d}.each { |letter|
path = "/tmp/create#{letter}test"
assert_file(path)
- if %w{a b}.include?(letter)
- assert_mode_equal(0755, path)
- end
+ assert_mode_equal(0755, path) if %w{a b}.include?(letter)
}
end
diff --git a/test/language/transportable.rb b/test/language/transportable.rb
index 4607c3947..37c67d6f8 100755
--- a/test/language/transportable.rb
+++ b/test/language/transportable.rb
@@ -50,9 +50,7 @@ class TestTransportable < Test::Unit::TestCase
# Make sure our 'delve' command is working
def test_delve
top = mk_transtree do |object, depth, width|
- if width % 2 == 1
- object.file = :funtest
- end
+ object.file = :funtest if width % 2 == 1
end
objects = []
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index 9bcbff9c1..38bb04298 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -113,9 +113,7 @@ module PuppetTest
end
def exampledir(*args)
- unless defined?(@@exampledir)
- @@exampledir = File.join(basedir, "examples")
- end
+ @@exampledir = File.join(basedir, "examples") unless defined?(@@exampledir)
if args.empty?
return @@exampledir
@@ -134,9 +132,7 @@ module PuppetTest
def libsetup
curlibs = ENV["RUBYLIB"].split(":")
$LOAD_PATH.reject do |dir| dir =~ /^\/usr/ end.each do |dir|
- unless curlibs.include?(dir)
- curlibs << dir
- end
+ curlibs << dir unless curlibs.include?(dir)
end
ENV["RUBYLIB"] = curlibs.join(":")
@@ -169,9 +165,7 @@ module PuppetTest
end
def setup
- unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
- ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin"
- end
+ ENV["PATH"] += File::PATH_SEPARATOR + "/usr/sbin" unless ENV["PATH"].split(File::PATH_SEPARATOR).include?("/usr/sbin")
@memoryatstart = Puppet::Util.memory
if defined?(@@testcount)
@@testcount += 1
@@ -198,9 +192,7 @@ module PuppetTest
Puppet[:confdir] = @configpath
Puppet[:vardir] = @configpath
- unless File.exists?(@configpath)
- Dir.mkdir(@configpath)
- end
+ Dir.mkdir(@configpath) unless File.exists?(@configpath)
@@tmpfiles << @configpath << tmpdir()
@@tmppids = []
@@ -212,9 +204,7 @@ module PuppetTest
# If we're running under rake, then disable debugging and such.
#if rake? or ! Puppet[:debug]
#if defined?($puppet_debug) or ! rake?
- if textmate?
- Puppet[:color] = false
- end
+ Puppet[:color] = false if textmate?
Puppet::Util::Log.newdestination(@logs)
if defined? $console
Puppet.info @method_name
@@ -319,9 +309,7 @@ module PuppetTest
@memoryatend = Puppet::Util.memory
diff = @memoryatend - @memoryatstart
- if diff > 1000
- Puppet.info "#{self.class}##{@method_name} memory growth (#{@memoryatstart} to #{@memoryatend}): #{diff}"
- end
+ Puppet.info "#{self.class}##{@method_name} memory growth (#{@memoryatstart} to #{@memoryatend}): #{diff}" if diff > 1000
# reset all of the logs
Puppet::Util::Log.close_all
diff --git a/test/lib/puppettest/certificates.rb b/test/lib/puppettest/certificates.rb
index 4f643b2d5..198ec96c4 100644
--- a/test/lib/puppettest/certificates.rb
+++ b/test/lib/puppettest/certificates.rb
@@ -8,9 +8,7 @@ module PuppetTest::Certificates
def mkPassFile()
keyfile = File.join(@dir, "tmpkeyfile")
@@tmpfiles << keyfile
- unless FileTest.exists?(@dir)
- system("mkdir -p #{@dir}")
- end
+ system("mkdir -p #{@dir}") unless FileTest.exists?(@dir)
File.open(keyfile, "w", 0600) { |f|
f.print "as;dklj23rlkjzdflij23wr"
}
diff --git a/test/lib/puppettest/exetest.rb b/test/lib/puppettest/exetest.rb
index c07615245..78f391ddd 100644
--- a/test/lib/puppettest/exetest.rb
+++ b/test/lib/puppettest/exetest.rb
@@ -18,12 +18,8 @@ module PuppetTest::ExeTest
end
def setbindir
- unless ENV["PATH"].split(":").include?(bindir)
- ENV["PATH"] = [bindir, ENV["PATH"]].join(":")
- end
- unless ENV["PATH"].split(":").include?(sbindir)
- ENV["PATH"] = [sbindir, ENV["PATH"]].join(":")
- end
+ ENV["PATH"] = [bindir, ENV["PATH"]].join(":") unless ENV["PATH"].split(":").include?(bindir)
+ ENV["PATH"] = [sbindir, ENV["PATH"]].join(":") unless ENV["PATH"].split(":").include?(sbindir)
end
def setlibdir
diff --git a/test/lib/puppettest/fakes.rb b/test/lib/puppettest/fakes.rb
index c0e0bd899..2db045ab5 100644
--- a/test/lib/puppettest/fakes.rb
+++ b/test/lib/puppettest/fakes.rb
@@ -35,9 +35,7 @@ module PuppetTest
def []=(param, value)
param = symbolize(param)
- unless @realresource.valid_parameter?(param)
- raise Puppet::DevError, "Invalid attribute #{param} for #{@realresource.name}"
- end
+ raise Puppet::DevError, "Invalid attribute #{param} for #{@realresource.name}" unless @realresource.valid_parameter?(param)
if @realresource.attrtype(param) == :property
@should[param] = value
else
@@ -157,9 +155,7 @@ module PuppetTest
def store(hash)
hash.each do |n, v|
method = n.to_s + "="
- if respond_to? method
- send(method, v)
- end
+ send(method, v) if respond_to? method
end
end
end
diff --git a/test/lib/puppettest/filetesting.rb b/test/lib/puppettest/filetesting.rb
index 3c869f5cf..2ecfce58f 100644
--- a/test/lib/puppettest/filetesting.rb
+++ b/test/lib/puppettest/filetesting.rb
@@ -22,9 +22,7 @@ module PuppetTest::FileTesting
ret = []
num.times { |index|
item = list[rand(list.length)]
- if set.include?(item)
- redo
- end
+ redo if set.include?(item)
ret.push item
}
@@ -32,17 +30,11 @@ module PuppetTest::FileTesting
end
def mkranddirsandfiles(dirs = nil,files = nil,depth = 3)
- if depth < 0
- return
- end
+ return if depth < 0
- unless dirs
- dirs = %w{This Is A Set Of Directories}
- end
+ dirs = %w{This Is A Set Of Directories} unless dirs
- unless files
- files = %w{and this is a set of files}
- end
+ files = %w{and this is a set of files} unless files
tfiles = randlist(files)
tdirs = randlist(dirs)
@@ -128,9 +120,7 @@ module PuppetTest::FileTesting
path = File.join(dir,file)
stat = File.stat(dir)
if checked < 10 and (i % 3) == 2
- unless yield path
- next
- end
+ next unless yield path
checked += 1
end
}
diff --git a/test/lib/puppettest/parsertesting.rb b/test/lib/puppettest/parsertesting.rb
index 2211d17be..a23bd5601 100644
--- a/test/lib/puppettest/parsertesting.rb
+++ b/test/lib/puppettest/parsertesting.rb
@@ -21,9 +21,7 @@ module PuppetTest::ParserTesting
end
def initialize(val = nil)
- if val
- @evaluate = val
- end
+ @evaluate = val if val
end
def reset
@@ -66,9 +64,7 @@ module PuppetTest::ParserTesting
compiler ||= mkcompiler
compiler.topscope.source = (parser.find_hostclass("", "") || parser.newclass(""))
- unless compiler.topscope.source
- raise "Could not find source for scope"
- end
+ raise "Could not find source for scope" unless compiler.topscope.source
# Make the 'main' stuff
compiler.send(:evaluate_main)
compiler.topscope
@@ -97,9 +93,7 @@ module PuppetTest::ParserTesting
end
def resourcedef(type, title, params)
- unless title.is_a?(AST)
- title = stringobj(title)
- end
+ title = stringobj(title) unless title.is_a?(AST)
assert_nothing_raised("Could not create #{type} #{title}") {
return AST::Resource.new(
@@ -221,9 +215,7 @@ module PuppetTest::ParserTesting
def resourceparam(param, value)
# Allow them to pass non-strings in
- if value.is_a?(String)
- value = stringobj(value)
- end
+ value = stringobj(value) if value.is_a?(String)
assert_nothing_raised("Could not create param #{param}") {
return AST::ResourceParam.new(
@@ -249,9 +241,7 @@ module PuppetTest::ParserTesting
end
def varobj(name, value)
- unless value.is_a? AST
- value = stringobj(value)
- end
+ value = stringobj(value) unless value.is_a? AST
assert_nothing_raised("Could not create #{name} code") {
return AST::VarDef.new(
@@ -403,9 +393,7 @@ module PuppetTest::ParserTesting
obj["mode"] = "644"
# Yield, if they want
- if block_given?
- yield(obj, i, j)
- end
+ yield(obj, i, j) if block_given?
resources << obj
end
diff --git a/test/lib/puppettest/railstesting.rb b/test/lib/puppettest/railstesting.rb
index 3af593762..2240c739a 100644
--- a/test/lib/puppettest/railstesting.rb
+++ b/test/lib/puppettest/railstesting.rb
@@ -8,9 +8,7 @@ module PuppetTest::RailsTesting
# If we don't clean up the connection list, then the rails
# lib will still think it's connected.
- if Puppet.features.rails?
- ActiveRecord::Base.clear_active_connections!
- end
+ ActiveRecord::Base.clear_active_connections! if Puppet.features.rails?
end
def railsinit
@@ -18,9 +16,7 @@ module PuppetTest::RailsTesting
end
def railsteardown
- if Puppet[:dbadapter] != "sqlite3"
- Puppet::Rails.teardown
- end
+ Puppet::Rails.teardown if Puppet[:dbadapter] != "sqlite3"
end
def railsresource(type = "file", title = "/tmp/testing", params = {})
diff --git a/test/lib/puppettest/runnable_test.rb b/test/lib/puppettest/runnable_test.rb
index 6fcd9c6dc..ac2fb7b2e 100644
--- a/test/lib/puppettest/runnable_test.rb
+++ b/test/lib/puppettest/runnable_test.rb
@@ -23,9 +23,7 @@ module PuppetTest
# is used directly by Rspec and is not intended for develper use.
#
def runnable?
- if superclass.respond_to?(:runnable?) and not superclass.runnable?
- return false
- end
+ return false if superclass.respond_to?(:runnable?) and not superclass.runnable?
confines.each do |message, is_runnable|
is_runnable = is_runnable.call if is_runnable.respond_to?(:call)
diff --git a/test/lib/puppettest/support/assertions.rb b/test/lib/puppettest/support/assertions.rb
index 528c7b8db..b918e28f6 100644
--- a/test/lib/puppettest/support/assertions.rb
+++ b/test/lib/puppettest/support/assertions.rb
@@ -42,12 +42,8 @@ module PuppetTest
comp = nil
msg = nil
- unless events.is_a? Array
- raise Puppet::DevError, "Incorrect call of assert_events"
- end
- if resources[-1].is_a? String
- msg = resources.pop
- end
+ raise Puppet::DevError, "Incorrect call of assert_events" unless events.is_a? Array
+ msg = resources.pop if resources[-1].is_a? String
config = resources2catalog(*resources)
transaction = Puppet::Transaction.new(config)
diff --git a/test/lib/puppettest/support/helpers.rb b/test/lib/puppettest/support/helpers.rb
index 5b1872dfb..4a3a53095 100644
--- a/test/lib/puppettest/support/helpers.rb
+++ b/test/lib/puppettest/support/helpers.rb
@@ -5,17 +5,13 @@ module PuppetTest
# UID of nobody.
def nonrootuser
Etc.passwd { |user|
- if user.uid != Puppet::Util::SUIDManager.uid and user.uid > 0 and user.uid < 255
- return user
- end
+ return user if user.uid != Puppet::Util::SUIDManager.uid and user.uid > 0 and user.uid < 255
}
end
def nonrootgroup
Etc.group { |group|
- if group.gid != Puppet::Util::SUIDManager.gid and group.gid > 0 and group.gid < 255
- return group
- end
+ return group if group.gid != Puppet::Util::SUIDManager.gid and group.gid > 0 and group.gid < 255
}
end
end
diff --git a/test/lib/puppettest/support/resources.rb b/test/lib/puppettest/support/resources.rb
index 865995507..6b771dda8 100755
--- a/test/lib/puppettest/support/resources.rb
+++ b/test/lib/puppettest/support/resources.rb
@@ -15,9 +15,7 @@ module PuppetTest::Support::Resources
def treenode(config, name, *resources)
comp = tree_container name
resources.each do |resource|
- if resource.is_a?(String)
- resource = tree_resource(resource)
- end
+ resource = tree_resource(resource) if resource.is_a?(String)
config.add_edge(comp, resource)
config.add_resource resource unless config.resource(resource.ref)
end
diff --git a/test/lib/puppettest/support/utils.rb b/test/lib/puppettest/support/utils.rb
index 06ce3ad4a..61ab6e754 100644
--- a/test/lib/puppettest/support/utils.rb
+++ b/test/lib/puppettest/support/utils.rb
@@ -26,9 +26,7 @@ module PuppetTest::Support::Utils
def resources2catalog(*resources)
if resources[0].is_a?(Puppet::Resource::Catalog)
config = resources.shift
- unless resources.empty?
- resources.each { |r| config.add_resource r }
- end
+ resources.each { |r| config.add_resource r } unless resources.empty?
elsif resources[0].is_a?(Puppet::Type.type(:component))
raise ArgumentError, "resource2config() no longer accpts components"
comp = resources.shift
@@ -55,18 +53,14 @@ module PuppetTest::Support::Utils
else
puts id
end
- unless defined?(@me)
- raise "Could not retrieve user name; 'id' did not work"
- end
+ raise "Could not retrieve user name; 'id' did not work" unless defined?(@me)
end
# Define a variable that contains a group I'm in.
def set_mygroup
# retrieve the user name
group = %x{groups}.chomp.split(/ /)[0]
- unless group
- raise "Could not find group to set in @mygroup"
- end
+ raise "Could not find group to set in @mygroup" unless group
@mygroup = group
end
@@ -93,9 +87,7 @@ module PuppetTest::Support::Utils
ary = [PuppetTest.basedir, "test"]
ary += name.split("/")
file = File.join(ary)
- unless FileTest.exists?(file)
- raise Puppet::DevError, "No fakedata file #{file}"
- end
+ raise Puppet::DevError, "No fakedata file #{file}" unless FileTest.exists?(file)
return file
end
diff --git a/test/lib/puppettest/testcase.rb b/test/lib/puppettest/testcase.rb
index 3521589bf..de088a468 100644
--- a/test/lib/puppettest/testcase.rb
+++ b/test/lib/puppettest/testcase.rb
@@ -20,9 +20,7 @@ class PuppetTest::TestCase < Test::Unit::TestCase
elsif self.runnable?
return super
else
- if defined? $console
- puts "Skipping #{name}: #{@messages.join(", ")}"
- end
+ puts "Skipping #{name}: #{@messages.join(", ")}" if defined? $console
suite = Test::Unit::TestSuite.new(name)
return suite
end
diff --git a/test/lib/rake/puppet_test_loader.rb b/test/lib/rake/puppet_test_loader.rb
index be3319ccc..17d29591f 100644
--- a/test/lib/rake/puppet_test_loader.rb
+++ b/test/lib/rake/puppet_test_loader.rb
@@ -10,7 +10,5 @@ args.each { |f| require f unless f =~ /^-/ }
runner = Test::Unit::AutoRunner.new(false)
runner.process_args
-unless runner.run
- exit 14
-end
+exit 14 unless runner.run
diff --git a/test/network/handler/fileserver.rb b/test/network/handler/fileserver.rb
index 3f93a74e0..32951bcce 100755
--- a/test/network/handler/fileserver.rb
+++ b/test/network/handler/fileserver.rb
@@ -12,9 +12,7 @@ class TestFileServer < Test::Unit::TestCase
mount = nil
name = "yaytest"
base = path || tempfile()
- unless FileTest.exists?(base)
- Dir.mkdir(base)
- end
+ Dir.mkdir(base) unless FileTest.exists?(base)
# Create a test file
File.open(File.join(base, "file"), "w") { |f| f.puts "bazoo" }
assert_nothing_raised {
diff --git a/test/other/puppet.rb b/test/other/puppet.rb
index 4acee3ee5..1f81bb781 100755
--- a/test/other/puppet.rb
+++ b/test/other/puppet.rb
@@ -58,9 +58,7 @@ class TestPuppetModule < Test::Unit::TestCase
oldlibs = $LOAD_PATH.dup
cleanup do
$LOAD_PATH.each do |dir|
- unless oldlibs.include?(dir)
- $LOAD_PATH.delete(dir)
- end
+ $LOAD_PATH.delete(dir) unless oldlibs.include?(dir)
end
end
one = tempfile()
diff --git a/test/other/transactions.rb b/test/other/transactions.rb
index e49e96a7f..fa4fa4f61 100755
--- a/test/other/transactions.rb
+++ b/test/other/transactions.rb
@@ -46,9 +46,7 @@ class TestTransactions < Test::Unit::TestCase
$finished << self.name
end
end
- if block
- type.class_eval(&block)
- end
+ type.class_eval(&block) if block
cleanup do
Puppet::Type.rmtype(:generator)
end
@@ -70,9 +68,7 @@ class TestTransactions < Test::Unit::TestCase
end
end
- if block
- type.class_eval(&block)
- end
+ type.class_eval(&block) if block
return type
end
diff --git a/test/puppet/defaults.rb b/test/puppet/defaults.rb
index 1620dfd82..2338e03ee 100755
--- a/test/puppet/defaults.rb
+++ b/test/puppet/defaults.rb
@@ -48,9 +48,7 @@ class TestPuppetDefaults < Test::Unit::TestCase
[@@dirs,@@files].flatten.each { |param|
value = Puppet[param]
- unless value !~ notval
- assert_nothing_raised { raise "#{param} is incorrectly set to #{value}" }
- end
+ assert_nothing_raised { raise "#{param} is incorrectly set to #{value}" } unless value !~ notval
}
end
diff --git a/test/ral/providers/cron/crontab.rb b/test/ral/providers/cron/crontab.rb
index 46678dc7d..3dfac96e6 100755
--- a/test/ral/providers/cron/crontab.rb
+++ b/test/ral/providers/cron/crontab.rb
@@ -23,9 +23,7 @@ class TestCronParsedProvider < Test::Unit::TestCase
# a full cron job. These tests assume individual record types will always be correctly
# parsed, so all they
def sample_crons
- unless defined?(@sample_crons)
- @sample_crons = YAML.load(File.read(File.join(@crondir, "crontab_collections.yaml")))
- end
+ @sample_crons = YAML.load(File.read(File.join(@crondir, "crontab_collections.yaml"))) unless defined?(@sample_crons)
@sample_crons
end
@@ -33,9 +31,7 @@ class TestCronParsedProvider < Test::Unit::TestCase
# mapping between records and lines. We have plenty of redundancy here because
# we use these records to build up our complex, multi-line cron jobs below.
def sample_records
- unless defined?(@sample_records)
- @sample_records = YAML.load(File.read(File.join(@crondir, "crontab_sample_records.yaml")))
- end
+ @sample_records = YAML.load(File.read(File.join(@crondir, "crontab_sample_records.yaml"))) unless defined?(@sample_records)
@sample_records
end
@@ -62,25 +58,19 @@ class TestCronParsedProvider < Test::Unit::TestCase
assert_equal(value, cron.send(param), "#{param} was not equal in #{msg}")
end
%w{command environment minute hour month monthday weekday}.each do |var|
- unless options.include?(var.intern)
- assert_equal(:absent, cron.send(var), "#{var} was not parsed absent in #{msg}")
- end
+ assert_equal(:absent, cron.send(var), "#{var} was not parsed absent in #{msg}") unless options.include?(var.intern)
end
end
# Make sure a cron record matches. This only works for crontab records.
def assert_record_equal(msg, record, options)
- unless options.include?(:record_type)
- raise ArgumentError, "You must pass the required record type"
- end
+ raise ArgumentError, "You must pass the required record type" unless options.include?(:record_type)
assert_instance_of(Hash, record, "not an instance of a hash in #{msg}")
options.each do |param, value|
assert_equal(value, record[param], "#{param} was not equal in #{msg}")
end
FIELDS[record[:record_type]].each do |var|
- unless options.include?(var)
- assert_equal(:absent, record[var], "#{var} was not parsed absent in #{msg}")
- end
+ assert_equal(:absent, record[var], "#{var} was not parsed absent in #{msg}") unless options.include?(var)
end
end
diff --git a/test/ral/providers/group.rb b/test/ral/providers/group.rb
index 067affd68..d6783bf7f 100755
--- a/test/ral/providers/group.rb
+++ b/test/ral/providers/group.rb
@@ -22,9 +22,7 @@ class TestGroupProvider < Test::Unit::TestCase
def teardown
super
@@tmpgroups.each { |group|
- unless missing?(group)
- remove(group)
- end
+ remove(group) unless missing?(group)
}
end
diff --git a/test/ral/providers/package.rb b/test/ral/providers/package.rb
index 600770f13..03b81477d 100755
--- a/test/ral/providers/package.rb
+++ b/test/ral/providers/package.rb
@@ -17,9 +17,7 @@ class TestPackageProvider < Test::Unit::TestCase
def self.load_test_packages
require 'yaml'
file = File.join(PuppetTest.datadir(), "providers", "package", "testpackages.yaml")
- unless FileTest.exists?(file)
- raise "Could not find file #{file}"
- end
+ raise "Could not find file #{file}" unless FileTest.exists?(file)
array = YAML::load(File.read(file)).collect { |hash|
# Stupid ruby 1.8.1. YAML is sometimes broken such that
# symbols end up being strings with the : in them.
@@ -163,9 +161,7 @@ class TestPackageProvider < Test::Unit::TestCase
end
end
else
- if cleancmd
- system(cleancmd)
- end
+ system(cleancmd) if cleancmd
end
end
diff --git a/test/ral/providers/provider.rb b/test/ral/providers/provider.rb
index f716bc1cf..081020638 100755
--- a/test/ral/providers/provider.rb
+++ b/test/ral/providers/provider.rb
@@ -11,9 +11,7 @@ class TestProvider < Test::Unit::TestCase
def echo
echo = Puppet::Util.binary("echo")
- unless echo
- raise "Could not find 'echo' binary; cannot complete test"
- end
+ raise "Could not find 'echo' binary; cannot complete test" unless echo
return echo
end
diff --git a/test/ral/providers/user.rb b/test/ral/providers/user.rb
index 81b3afd3e..e4ec3c125 100755
--- a/test/ral/providers/user.rb
+++ b/test/ral/providers/user.rb
@@ -24,9 +24,7 @@ class TestUserProvider < Test::Unit::TestCase
def teardown
@@tmpusers.each { |user|
- unless missing?(user)
- remove(user)
- end
+ remove(user) unless missing?(user)
}
super
end
@@ -376,9 +374,7 @@ class TestUserProvider < Test::Unit::TestCase
Etc.setgrent
max = 0
while group = Etc.getgrent
- if group.gid > max and group.gid < 5000
- max = group.gid
- end
+ max = group.gid if group.gid > max and group.gid < 5000
end
groups = []
diff --git a/test/ral/providers/user/useradd.rb b/test/ral/providers/user/useradd.rb
index 2e98d7f5d..52d933f89 100755
--- a/test/ral/providers/user/useradd.rb
+++ b/test/ral/providers/user/useradd.rb
@@ -64,9 +64,7 @@ class UserAddProviderTest < PuppetTest::TestCase
end
options = {}
- while params.length > 0
- options[params.shift] = params.shift
- end
+ options[params.shift] = params.shift while params.length > 0
@vals[:groups] = @vals[:groups].join(",")
@@ -118,9 +116,7 @@ class UserAddProviderTest < PuppetTest::TestCase
@user.provider.expects(:execute).with do |params|
assert_equal(params[0], @provider.command(:add), "useradd was not called")
- if %w{Fedora RedHat}.include?(Facter.value(:operatingsystem))
- assert(params.include?("-M"), "Did not add -M on Red Hat")
- end
+ assert(params.include?("-M"), "Did not add -M on Red Hat") if %w{Fedora RedHat}.include?(Facter.value(:operatingsystem))
assert(! params.include?("-m"), "Added -m when managehome was disabled")
true
@@ -171,9 +167,7 @@ class UserAddProviderTest < PuppetTest::TestCase
end
def test_manages_password
- unless @provider.feature?(:manages_passwords)
- return
- end
+ return unless @provider.feature?(:manages_passwords)
@vals[:password] = "somethingorother"
setup_user
diff --git a/test/ral/type/cron.rb b/test/ral/type/cron.rb
index fcee21dd0..6b561c392 100755
--- a/test/ral/type/cron.rb
+++ b/test/ral/type/cron.rb
@@ -197,9 +197,7 @@ class TestCron < Test::Unit::TestCase
cron[param] = value
}
- if value.is_a?(Integer)
- assert_equal([value.to_s], cron.should(param), "Cron value was not set correctly")
- end
+ assert_equal([value.to_s], cron.should(param), "Cron value was not set correctly") if value.is_a?(Integer)
when :invalid
assert_raise(Puppet::Error, "#{value} is incorrectly a valid #{param}") {
cron[param] = value
diff --git a/test/ral/type/exec.rb b/test/ral/type/exec.rb
index 454458ff3..7ddb4650d 100755
--- a/test/ral/type/exec.rb
+++ b/test/ral/type/exec.rb
@@ -391,9 +391,7 @@ class TestExec < Test::Unit::TestCase
assert_events([:executed_command], comp, "usertest")
assert(FileTest.exists?(file), "File does not exist")
- if user
- assert_equal(user.uid, File.stat(file).uid, "File UIDs do not match")
- end
+ assert_equal(user.uid, File.stat(file).uid, "File UIDs do not match") if user
# We can't actually test group ownership, unfortunately, because
# behaviour changes wildlly based on platform.
diff --git a/test/ral/type/filesources.rb b/test/ral/type/filesources.rb
index a928fd7db..7541a7cbe 100755
--- a/test/ral/type/filesources.rb
+++ b/test/ral/type/filesources.rb
@@ -90,9 +90,7 @@ class TestFileSources < Test::Unit::TestCase
todir = File.join(path, "todir")
source = fromdir
- if networked
- source = "puppet://localhost/#{networked}#{fromdir}"
- end
+ source = "puppet://localhost/#{networked}#{fromdir}" if networked
recursive_source_test(source, todir)
return [fromdir,todir, File.join(todir, "one"), File.join(todir, "two")]
diff --git a/test/ral/type/resources.rb b/test/ral/type/resources.rb
index eb53a7edf..50d6839e7 100755
--- a/test/ral/type/resources.rb
+++ b/test/ral/type/resources.rb
@@ -24,9 +24,7 @@ class TestResources < Test::Unit::TestCase
@purgenum += 1
obj = @purgetype.create :name => "purger#{@purgenum}"
$purgemembers[obj[:name]] = obj
- if managed
- obj[:fake] = "testing"
- end
+ obj[:fake] = "testing" if managed
obj
end
@@ -100,9 +98,7 @@ class TestResources < Test::Unit::TestCase
end
}
- if low
- assert(! res.check(@user.create(:name => low)), "low user #{low} passed check")
- end
+ assert(! res.check(@user.create(:name => low)), "low user #{low} passed check") if low
if high
res[:unless_system_user] = 50
assert(res.check(@user.create(:name => high)), "high user #{high} failed check")
diff --git a/test/ral/type/sshkey.rb b/test/ral/type/sshkey.rb
index e362de839..01d72156a 100755
--- a/test/ral/type/sshkey.rb
+++ b/test/ral/type/sshkey.rb
@@ -32,9 +32,7 @@ class TestSSHKey < Test::Unit::TestCase
def teardown
super
- if @provider.respond_to?(:clear)
- @provider.clear
- end
+ @provider.clear if @provider.respond_to?(:clear)
end
def mkkey
diff --git a/test/ral/type/zone.rb b/test/ral/type/zone.rb
index f87774786..c136fbfb1 100755
--- a/test/ral/type/zone.rb
+++ b/test/ral/type/zone.rb
@@ -105,9 +105,7 @@ class TestZone < PuppetTest::TestCase
assert_nothing_raised {
property.class.state_sequence(:absent, :running).each do |st|
[:up, :down].each do |m|
- if st[m]
- methods << st[m]
- end
+ methods << st[m] if st[m]
end
end
}
diff --git a/test/util/fileparsing.rb b/test/util/fileparsing.rb
index fac5f3e83..eaf57cef6 100755
--- a/test/util/fileparsing.rb
+++ b/test/util/fileparsing.rb
@@ -422,9 +422,7 @@ assert_nothing_raised do
ret[:description] = desc unless desc == ""
end
- if line != ""
- ret[:alias] = line.split(/\s+/)
- end
+ ret[:alias] = line.split(/\s+/) if line != ""
return ret
end