summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-03-30 12:24:56 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2017-03-30 12:24:56 -0700
commitde209e6ee12939f641ec0ed002c2d3506abaafe7 (patch)
tree0a6b37f0519a71444250c5ffd84d3df89649228d /lib
parent5584126a725ab72c24ea610328f56a905986295b (diff)
downloadchef-de209e6ee12939f641ec0ed002c2d3506abaafe7.tar.gz
make nameless properties opt-in
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/dsl/resources.rb8
-rw-r--r--lib/chef/resource.rb2
-rw-r--r--lib/chef/resource/apt_update.rb4
-rw-r--r--lib/chef/resource_builder.rb2
-rw-r--r--lib/chef/resource_collection/resource_set.rb4
5 files changed, 10 insertions, 10 deletions
diff --git a/lib/chef/dsl/resources.rb b/lib/chef/dsl/resources.rb
index 4baec22f2e..638e626ae2 100644
--- a/lib/chef/dsl/resources.rb
+++ b/lib/chef/dsl/resources.rb
@@ -34,10 +34,10 @@ class Chef
def self.add_resource_dsl(dsl_name)
module_eval(<<-EOM, __FILE__, __LINE__ + 1)
- def #{dsl_name}(arg = "", &block)
- declare_resource(#{dsl_name.inspect}, arg, created_at: caller[0], &block)
- end
- EOM
+ def #{dsl_name}(args = nil, &block)
+ declare_resource(#{dsl_name.inspect}, args, created_at: caller[0], &block)
+ end
+ EOM
end
def self.remove_resource_dsl(dsl_name)
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 2aee8536a4..9dc01a8d3a 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -84,7 +84,7 @@ class Chef
# @param name [Object] The name to set, typically a String or Array
# @return [String] The name of this Resource.
#
- property :name, String, coerce: proc { |v| v.is_a?(Array) ? v.join(", ") : v.to_s }, desired_state: false
+ property :name, String, coerce: proc { |v| v.is_a?(Array) ? v.join(", ") : v.to_s }, desired_state: false, required: true
#
# The node the current Chef run is using.
diff --git a/lib/chef/resource/apt_update.rb b/lib/chef/resource/apt_update.rb
index 1a25ec2ef5..67ca7fbfea 100644
--- a/lib/chef/resource/apt_update.rb
+++ b/lib/chef/resource/apt_update.rb
@@ -1,6 +1,6 @@
#
# Author:: Thom May (<thom@chef.io>)
-# Copyright:: Copyright (c) 2016 Chef Software, Inc.
+# Copyright:: Copyright (c) 2016-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +24,8 @@ class Chef
resource_name :apt_update
provides :apt_update
+ # allow bare apt_update with no name
+ property :name, String, default: ""
property :frequency, Integer, default: 86_400
default_action :periodic
diff --git a/lib/chef/resource_builder.rb b/lib/chef/resource_builder.rb
index 275f795362..43a2495cba 100644
--- a/lib/chef/resource_builder.rb
+++ b/lib/chef/resource_builder.rb
@@ -43,8 +43,6 @@ class Chef
end
def build(&block)
- raise ArgumentError, "You must supply a name when declaring a #{type} resource" if name.nil?
-
@resource = resource_class.new(name, run_context)
if resource.resource_name.nil?
raise Chef::Exceptions::InvalidResourceSpecification, "#{resource}.resource_name is `nil`! Did you forget to put `provides :blah` or `resource_name :blah` in your resource class?"
diff --git a/lib/chef/resource_collection/resource_set.rb b/lib/chef/resource_collection/resource_set.rb
index 66ccc1ccb3..111d23dc09 100644
--- a/lib/chef/resource_collection/resource_set.rb
+++ b/lib/chef/resource_collection/resource_set.rb
@@ -46,7 +46,7 @@ class Chef
def insert_as(resource, resource_type = nil, instance_name = nil)
is_chef_resource!(resource)
resource_type ||= resource.resource_name
- instance_name ||= resource.name || ""
+ instance_name ||= resource.name
key = create_key(resource_type, instance_name)
@resources_by_key[key] = resource
end
@@ -145,7 +145,7 @@ class Chef
private
- def create_key(resource_type, instance_name = "")
+ def create_key(resource_type, instance_name)
"#{resource_type}[#{instance_name}]"
end