summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2022-04-01 12:24:49 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2022-04-01 12:24:49 -0700
commitc2f6231f5bb3b1cb5d081edf93f43a824c75de89 (patch)
tree2a21edb1e12d59c4bff6382ddc84b62a9df0a8c6
parent4df3e3960920d2eb4e03fa23b6405d7d6945e26b (diff)
downloadchef-c2f6231f5bb3b1cb5d081edf93f43a824c75de89.tar.gz
copyright and some reorganization
the `use` helper for partials can now pull in any partial in the lib/chef/resources directory. for example: ``` use "core::cron/cron_shared" ``` Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/dsl/rest_resource.rb17
-rw-r--r--lib/chef/resource.rb6
-rw-r--r--lib/chef/resource/_rest_resource.rb (renamed from lib/chef/resource/core_partials/rest_resource.rb)17
-rw-r--r--spec/unit/resource/rest_resource_spec.rb (renamed from spec/unit/resource/core_partials/rest_resource_spec.rb)17
4 files changed, 56 insertions, 1 deletions
diff --git a/lib/chef/dsl/rest_resource.rb b/lib/chef/dsl/rest_resource.rb
index 593311361d..96eba24eac 100644
--- a/lib/chef/dsl/rest_resource.rb
+++ b/lib/chef/dsl/rest_resource.rb
@@ -1,3 +1,20 @@
+#
+# Copyright:: Copyright 2008-2016, Chef, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
require "chef/constants" unless defined?(NOT_PASSED)
class Chef
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 8b3084487f..d6c5fe7cdf 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -1499,7 +1499,11 @@ class Chef
#
def self.use(partial)
if partial =~ /^core::(.*)/
- class_eval IO.read(::File.expand_path("resource/core_partials/#{$1}.rb", __dir__))
+ partial = $1
+ dirname = ::File.dirname(partial)
+ basename = ::File.basename(partial, ".rb")
+ basename = basename[1..] if basename.start_with?("_")
+ class_eval IO.read(::File.expand_path("resource/#{dirname}/_#{basename}.rb", __dir__))
else
dirname = ::File.dirname(partial)
basename = ::File.basename(partial, ".rb")
diff --git a/lib/chef/resource/core_partials/rest_resource.rb b/lib/chef/resource/_rest_resource.rb
index 01309f11bc..f14e586eb2 100644
--- a/lib/chef/resource/core_partials/rest_resource.rb
+++ b/lib/chef/resource/_rest_resource.rb
@@ -1,3 +1,20 @@
+#
+# Copyright:: Copyright 2008-2016, Chef, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
require "rest-client" unless defined?(RestClient)
require "jmespath" unless defined?(JMESPath)
require "chef/dsl/rest_resource" unless defined?(Chef::DSL::RestResource)
diff --git a/spec/unit/resource/core_partials/rest_resource_spec.rb b/spec/unit/resource/rest_resource_spec.rb
index 0b84e1c24b..43cb63d8de 100644
--- a/spec/unit/resource/core_partials/rest_resource_spec.rb
+++ b/spec/unit/resource/rest_resource_spec.rb
@@ -1,3 +1,20 @@
+#
+# Copyright:: Copyright 2008-2016, Chef, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
require "spec_helper"
require "train"
require "train-rest"