summaryrefslogtreecommitdiff
path: root/lib/chef/dsl
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-02-13 09:52:10 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2017-02-13 09:52:10 -0800
commit404a9bc88be538769c6c80b3b31f39a6582991d2 (patch)
tree2f8795e5f64153440c22a522d669c235a627f289 /lib/chef/dsl
parentb949a48acc21d4b64869bd7b834708d5232b1f2a (diff)
downloadchef-404a9bc88be538769c6c80b3b31f39a6582991d2.tar.gz
fix specs: RedundantReturn, RedundantSelf, RedundantBegin
department of redundancy department Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib/chef/dsl')
-rw-r--r--lib/chef/dsl/audit.rb4
-rw-r--r--lib/chef/dsl/declare_resource.rb2
-rw-r--r--lib/chef/dsl/platform_introspection.rb60
-rw-r--r--lib/chef/dsl/reboot_pending.rb2
-rw-r--r--lib/chef/dsl/resources.rb14
5 files changed, 39 insertions, 43 deletions
diff --git a/lib/chef/dsl/audit.rb b/lib/chef/dsl/audit.rb
index 98271dc5cb..9ef798df91 100644
--- a/lib/chef/dsl/audit.rb
+++ b/lib/chef/dsl/audit.rb
@@ -38,8 +38,8 @@ class Chef
cookbook_name = self.cookbook_name
metadata = {
cookbook_name: cookbook_name,
- cookbook_version: self.run_context.cookbook_collection[cookbook_name].version,
- recipe_name: self.recipe_name,
+ cookbook_version: run_context.cookbook_collection[cookbook_name].version,
+ recipe_name: recipe_name,
line_number: block.source_location[1],
}
diff --git a/lib/chef/dsl/declare_resource.rb b/lib/chef/dsl/declare_resource.rb
index 5bd1f7fb8e..e48d741c60 100644
--- a/lib/chef/dsl/declare_resource.rb
+++ b/lib/chef/dsl/declare_resource.rb
@@ -287,7 +287,7 @@ class Chef
run_context: run_context,
cookbook_name: cookbook_name,
recipe_name: recipe_name,
- enclosing_provider: self.is_a?(Chef::Provider) ? self : nil
+ enclosing_provider: is_a?(Chef::Provider) ? self : nil
).build(&resource_attrs_block)
end
end
diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb
index f99ab970c5..dc309f9acb 100644
--- a/lib/chef/dsl/platform_introspection.rb
+++ b/lib/chef/dsl/platform_introspection.rb
@@ -68,41 +68,39 @@ class Chef
private
def match_versions(node)
- begin
- platform, version = node[:platform].to_s, node[:platform_version].to_s
- return nil unless @values.key?(platform)
- node_version = Chef::Version::Platform.new(version)
- key_matches = []
- keys = @values[platform].keys
- keys.each do |k|
- begin
- if Chef::VersionConstraint::Platform.new(k).include?(node_version)
- key_matches << k
- end
- rescue Chef::Exceptions::InvalidVersionConstraint => e
- Chef::Log.debug "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform."
- Chef::Log.debug(e)
+ platform, version = node[:platform].to_s, node[:platform_version].to_s
+ return nil unless @values.key?(platform)
+ node_version = Chef::Version::Platform.new(version)
+ key_matches = []
+ keys = @values[platform].keys
+ keys.each do |k|
+ begin
+ if Chef::VersionConstraint::Platform.new(k).include?(node_version)
+ key_matches << k
end
+ rescue Chef::Exceptions::InvalidVersionConstraint => e
+ Chef::Log.debug "Caught InvalidVersionConstraint. This means that a key in value_for_platform cannot be interpreted as a Chef::VersionConstraint::Platform."
+ Chef::Log.debug(e)
end
- return @values[platform][version] if key_matches.include?(version)
- case key_matches.length
- when 0
- return nil
- when 1
- return @values[platform][key_matches.first]
- else
- raise "Multiple matches detected for #{platform} with values #{@values}. The matches are: #{key_matches}"
- end
- rescue Chef::Exceptions::InvalidCookbookVersion => e
- # Lets not break because someone passes a weird string like 'default' :)
- Chef::Log.debug(e)
- Chef::Log.debug "InvalidCookbookVersion exceptions are common and expected here: the generic constraint matcher attempted to match something which is not a constraint. Moving on to next version or constraint"
- return nil
- rescue Chef::Exceptions::InvalidPlatformVersion => e
- Chef::Log.debug "Caught InvalidPlatformVersion, this means that Chef::Version::Platform does not know how to turn #{node_version} into an x.y.z format"
- Chef::Log.debug(e)
+ end
+ return @values[platform][version] if key_matches.include?(version)
+ case key_matches.length
+ when 0
return nil
+ when 1
+ return @values[platform][key_matches.first]
+ else
+ raise "Multiple matches detected for #{platform} with values #{@values}. The matches are: #{key_matches}"
end
+ rescue Chef::Exceptions::InvalidCookbookVersion => e
+ # Lets not break because someone passes a weird string like 'default' :)
+ Chef::Log.debug(e)
+ Chef::Log.debug "InvalidCookbookVersion exceptions are common and expected here: the generic constraint matcher attempted to match something which is not a constraint. Moving on to next version or constraint"
+ return nil
+ rescue Chef::Exceptions::InvalidPlatformVersion => e
+ Chef::Log.debug "Caught InvalidPlatformVersion, this means that Chef::Version::Platform does not know how to turn #{node_version} into an x.y.z format"
+ Chef::Log.debug(e)
+ return nil
end
def set(platforms, value)
diff --git a/lib/chef/dsl/reboot_pending.rb b/lib/chef/dsl/reboot_pending.rb
index e8982d290e..fdd0f5a62b 100644
--- a/lib/chef/dsl/reboot_pending.rb
+++ b/lib/chef/dsl/reboot_pending.rb
@@ -30,7 +30,7 @@ class Chef
# Note that we will silently miss any other platform-specific reboot notices besides Windows+Ubuntu.
def reboot_pending?
# don't break when used as a mixin in contexts without #node (e.g. specs).
- if self.respond_to?(:node, true) && node.run_context.reboot_requested?
+ if respond_to?(:node, true) && node.run_context.reboot_requested?
true
elsif platform?("windows")
# PendingFileRenameOperations contains pairs (REG_MULTI_SZ) of filenames that cannot be updated
diff --git a/lib/chef/dsl/resources.rb b/lib/chef/dsl/resources.rb
index 0d654316d8..1401e3ed53 100644
--- a/lib/chef/dsl/resources.rb
+++ b/lib/chef/dsl/resources.rb
@@ -33,19 +33,17 @@ class Chef
include Chef::DSL::ChefProvisioning
def self.add_resource_dsl(dsl_name)
- begin
- module_eval(<<-EOM, __FILE__, __LINE__ + 1)
+ module_eval(<<-EOM, __FILE__, __LINE__ + 1)
def #{dsl_name}(*args, &block)
Chef.deprecated(:internal_api, "Cannot create resource #{dsl_name} with more than one argument. All arguments except the name (\#{args[0].inspect}) will be ignored. This will cause an error in Chef 13. Arguments: \#{args}") if args.size > 1
declare_resource(#{dsl_name.inspect}, args[0], caller[0], &block)
end
EOM
- rescue SyntaxError
- # Handle the case where dsl_name has spaces, etc.
- define_method(dsl_name.to_sym) do |*args, &block|
- Chef.deprecated(:internal_api, "Cannot create resource #{dsl_name} with more than one argument. All arguments except the name (#{args[0].inspect}) will be ignored. This will cause an error in Chef 13. Arguments: #{args}") if args.size > 1
- declare_resource(dsl_name, args[0], caller[0], &block)
- end
+ rescue SyntaxError
+ # Handle the case where dsl_name has spaces, etc.
+ define_method(dsl_name.to_sym) do |*args, &block|
+ Chef.deprecated(:internal_api, "Cannot create resource #{dsl_name} with more than one argument. All arguments except the name (#{args[0].inspect}) will be ignored. This will cause an error in Chef 13. Arguments: #{args}") if args.size > 1
+ declare_resource(dsl_name, args[0], caller[0], &block)
end
end