summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2022-03-31 21:38:09 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2022-03-31 21:38:09 -0700
commitae4777206577025e13116f2e94b273833cb5dfed (patch)
treea13465f0cb801de6c6b273111bd07d5f6fec82c5
parent1147c39a4b6cbb36b8293ee02ceb122e89217408 (diff)
downloadchef-ae4777206577025e13116f2e94b273833cb5dfed.tar.gz
simplify DSL code
Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/dsl/rest_resource.rb78
-rw-r--r--lib/chef/resource/core_partials/rest_resource.rb2
-rw-r--r--spec/unit/resource/core_partials/rest_resource_spec.rb2
3 files changed, 35 insertions, 47 deletions
diff --git a/lib/chef/dsl/rest_resource.rb b/lib/chef/dsl/rest_resource.rb
index d324d85ed4..055904e1c2 100644
--- a/lib/chef/dsl/rest_resource.rb
+++ b/lib/chef/dsl/rest_resource.rb
@@ -1,63 +1,51 @@
class Chef
module DSL
module RestResource
- module ClassMethods
- def rest_property_map(rest_property_map = "NOT_PASSED")
- if rest_property_map != "NOT_PASSED"
- rest_property_map = rest_property_map.to_h { |k| [k.to_sym, k] } if rest_property_map.is_a? Array
+ def rest_property_map(rest_property_map = "NOT_PASSED")
+ if rest_property_map != "NOT_PASSED"
+ rest_property_map = rest_property_map.to_h { |k| [k.to_sym, k] } if rest_property_map.is_a? Array
- @rest_property_map = rest_property_map
- end
- @rest_property_map
- end
-
- # URL to collection
- def rest_api_collection(rest_api_collection = "NOT_PASSED")
- @rest_api_collection = rest_api_collection if rest_api_collection != "NOT_PASSED"
- @rest_api_collection
+ @rest_property_map = rest_property_map
end
+ @rest_property_map
+ end
- # RFC6570-Templated URL to document
- def rest_api_document(rest_api_document = "NOT_PASSED", first_element_only: false)
- if rest_api_document != "NOT_PASSED"
- @rest_api_document = rest_api_document
- @rest_api_document_first_element_only = first_element_only
- end
- @rest_api_document
- end
+ # URL to collection
+ def rest_api_collection(rest_api_collection = "NOT_PASSED")
+ @rest_api_collection = rest_api_collection if rest_api_collection != "NOT_PASSED"
+ @rest_api_collection
+ end
- # Explicit REST document identity mapping
- def rest_identity_map(rest_identity_map = "NOT_PASSED")
- @rest_identity_map = rest_identity_map if rest_identity_map != "NOT_PASSED"
- @rest_identity_map
+ # RFC6570-Templated URL to document
+ def rest_api_document(rest_api_document = "NOT_PASSED", first_element_only: false)
+ if rest_api_document != "NOT_PASSED"
+ @rest_api_document = rest_api_document
+ @rest_api_document_first_element_only = first_element_only
end
+ @rest_api_document
+ end
- # Mark up properties for POST only, not PATCH/PUT
- def rest_post_only_properties(rest_post_only_properties = "NOT_PASSED")
- if rest_post_only_properties != "NOT_PASSED"
- @rest_post_only_properties = Array(rest_post_only_properties).map(&:to_sym)
- end
- @rest_post_only_properties || []
- end
+ # Explicit REST document identity mapping
+ def rest_identity_map(rest_identity_map = "NOT_PASSED")
+ @rest_identity_map = rest_identity_map if rest_identity_map != "NOT_PASSED"
+ @rest_identity_map
+ end
- def rest_api_document_first_element_only(rest_api_document_first_element_only = "NOT_PASSED")
- if rest_api_document_first_element_only != "NOT_PASSED"
- @rest_api_document_first_element_only = rest_api_document_first_element_only
- end
- @rest_api_document_first_element_only
+ # Mark up properties for POST only, not PATCH/PUT
+ def rest_post_only_properties(rest_post_only_properties = "NOT_PASSED")
+ if rest_post_only_properties != "NOT_PASSED"
+ @rest_post_only_properties = Array(rest_post_only_properties).map(&:to_sym)
end
+ @rest_post_only_properties || []
+ end
- # "What if this was built into Chef Infra Core?" demo only
- def resource_type(resource_type = "NOT_PASSED"); end
-
- def included(other)
- other.extend ClassMethods
+ def rest_api_document_first_element_only(rest_api_document_first_element_only = "NOT_PASSED")
+ if rest_api_document_first_element_only != "NOT_PASSED"
+ @rest_api_document_first_element_only = rest_api_document_first_element_only
end
+ @rest_api_document_first_element_only
end
- def self.included(other)
- other.extend ClassMethods
- end
end
end
end
diff --git a/lib/chef/resource/core_partials/rest_resource.rb b/lib/chef/resource/core_partials/rest_resource.rb
index e64d589f5a..01309f11bc 100644
--- a/lib/chef/resource/core_partials/rest_resource.rb
+++ b/lib/chef/resource/core_partials/rest_resource.rb
@@ -2,7 +2,7 @@ require "rest-client" unless defined?(RestClient)
require "jmespath" unless defined?(JMESPath)
require "chef/dsl/rest_resource" unless defined?(Chef::DSL::RestResource)
-include Chef::DSL::RestResource
+extend Chef::DSL::RestResource
action_class do
def load_current_resource
diff --git a/spec/unit/resource/core_partials/rest_resource_spec.rb b/spec/unit/resource/core_partials/rest_resource_spec.rb
index 0a6a36c21d..0b84e1c24b 100644
--- a/spec/unit/resource/core_partials/rest_resource_spec.rb
+++ b/spec/unit/resource/core_partials/rest_resource_spec.rb
@@ -89,7 +89,7 @@ describe "rest_resource using query-based addressing" do
end
it "should mixin RestResourceDSL" do
- expect(resource.class.included_modules).to include(Chef::DSL::RestResource)
+ expect(resource.class.ancestors).to include(Chef::DSL::RestResource)
end
describe "#rest_postprocess" do