diff options
| author | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:33 -0700 |
|---|---|---|
| committer | Markus Roberts <Markus@reality.com> | 2010-07-09 18:06:33 -0700 |
| commit | 8d1fbe4586c91682cdda0cb271649e918fd9778b (patch) | |
| tree | 314508ca21830874d9e4ec6e27880fede14193bd /lib/puppet/transaction | |
| parent | 889158ad57e33df083613d6f7d136b2e11aaa16a (diff) | |
| download | puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.tar.gz puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.tar.xz puppet-8d1fbe4586c91682cdda0cb271649e918fd9778b.zip | |
Code smell: Avoid explicit returns
Replaced 583 occurances of
(DEF)
(LINES)
return (.*)
end
with
3 Examples:
The code:
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) }
filters[f] << spec
break
end
end
return filters
end
becomes:
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) }
filters[f] << spec
break
end
end
filters
end
The code:
def retrieve
return_value = super
return_value = return_value[0] if return_value && return_value.is_a?(Array)
return return_value
end
becomes:
def retrieve
return_value = super
return_value = return_value[0] if return_value && return_value.is_a?(Array)
return_value
end
The code:
def fake_fstab
os = Facter['operatingsystem']
if os == "Solaris"
name = "solaris.fstab"
elsif os == "FreeBSD"
name = "freebsd.fstab"
else
# Catchall for other fstabs
name = "linux.fstab"
end
oldpath = @provider_class.default_target
return fakefile(File::join("data/types/mount", name))
end
becomes:
def fake_fstab
os = Facter['operatingsystem']
if os == "Solaris"
name = "solaris.fstab"
elsif os == "FreeBSD"
name = "freebsd.fstab"
else
# Catchall for other fstabs
name = "linux.fstab"
end
oldpath = @provider_class.default_target
fakefile(File::join("data/types/mount", name))
end
Diffstat (limited to 'lib/puppet/transaction')
| -rw-r--r-- | lib/puppet/transaction/change.rb | 8 | ||||
| -rw-r--r-- | lib/puppet/transaction/report.rb | 6 | ||||
| -rw-r--r-- | lib/puppet/transaction/resource_harness.rb | 4 |
3 files changed, 9 insertions, 9 deletions
diff --git a/lib/puppet/transaction/change.rb b/lib/puppet/transaction/change.rb index 18f11c016..0f2ed5788 100644 --- a/lib/puppet/transaction/change.rb +++ b/lib/puppet/transaction/change.rb @@ -50,7 +50,7 @@ class Puppet::Transaction::Change # Is our property noop? This is used for generating special events. def noop? - return @property.noop + @property.noop end # The resource that generated this change. This is used for handling events, @@ -63,7 +63,7 @@ class Puppet::Transaction::Change end def to_s - return "change #{@property.change_to_s(@is, @should)}" + "change #{@property.change_to_s(@is, @should)}" end private @@ -74,7 +74,7 @@ class Puppet::Transaction::Change result.message = "audit change: previously recorded value #{property.should_to_s(should)} has been changed to #{property.is_to_s(is)}" result.status = "audit" result.send_log - return result + result end def noop_event @@ -82,6 +82,6 @@ class Puppet::Transaction::Change result.message = "is #{property.is_to_s(is)}, should be #{property.should_to_s(should)} (noop)" result.status = "noop" result.send_log - return result + result end end diff --git a/lib/puppet/transaction/report.rb b/lib/puppet/transaction/report.rb index f9dfab3a3..021c0200a 100644 --- a/lib/puppet/transaction/report.rb +++ b/lib/puppet/transaction/report.rb @@ -20,7 +20,7 @@ class Puppet::Transaction::Report def <<(msg) @logs << msg - return self + self end def add_times(name, value) @@ -83,7 +83,7 @@ class Puppet::Transaction::Report ret += " %15s %s\n" % [label + ":", value] end end - return ret + ret end # Based on the contents of this report's metrics, compute a single number @@ -93,7 +93,7 @@ class Puppet::Transaction::Report status = 0 status |= 2 if @metrics["changes"][:total] > 0 status |= 4 if @metrics["resources"][:failed] > 0 - return status + status end private diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb index 36bb6029d..5f90df5b9 100644 --- a/lib/puppet/transaction/resource_harness.rb +++ b/lib/puppet/transaction/resource_harness.rb @@ -13,7 +13,7 @@ class Puppet::Transaction::ResourceHarness deplabel = deps.collect { |r| r.ref }.join(",") plurality = deps.length > 1 ? "":"s" resource.warning "#{deplabel} still depend#{plurality} on me -- not purging" - return false + false end def apply_changes(status, changes) @@ -117,7 +117,7 @@ class Puppet::Transaction::ResourceHarness # have been synced a long time ago (e.g., a file only gets updated # once a month on the server and its schedule is daily; the last sync time # will have been a month ago, so we'd end up checking every run). - return schedule.match?(cached(resource, :checked).to_i) + schedule.match?(cached(resource, :checked).to_i) end def schedule(resource) |
