summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2016-05-18 11:13:57 +0100
committerThom May <thom@may.lt>2016-05-18 11:13:57 +0100
commitcfab6de01fd596a03b60ce9c9dd59e4b7cb5aa48 (patch)
treeb31977af615d0ac32cb74682222f7b723cbdb37e
parent2f19f54b60a5c05fea0ec75ce20af25940f545d9 (diff)
parent53d796a95c7d33a4c3cd7b1285b53bb9b095d160 (diff)
downloadchef-cfab6de01fd596a03b60ce9c9dd59e4b7cb5aa48.tar.gz
Merge pull request #4942 from chef/lcg/universal-dsl
create 'universal' DSL
-rw-r--r--lib/chef/dsl/core.rb30
-rw-r--r--lib/chef/dsl/recipe.rb24
-rw-r--r--lib/chef/dsl/universal.rb50
-rw-r--r--lib/chef/node.rb4
-rw-r--r--lib/chef/provider/lwrp_base.rb1
-rw-r--r--lib/chef/resource.rb9
6 files changed, 88 insertions, 30 deletions
diff --git a/lib/chef/dsl/core.rb b/lib/chef/dsl/core.rb
index c2dbea7628..11507857cf 100644
--- a/lib/chef/dsl/core.rb
+++ b/lib/chef/dsl/core.rb
@@ -18,27 +18,35 @@
#
require "chef/dsl/declare_resource"
+require "chef/dsl/universal"
require "chef/mixin/notifying_block"
-require "chef/mixin/powershell_out"
-require "chef/mixin/shell_out"
+require "chef/mixin/lazy_module_include"
class Chef
module DSL
- # This is the "Core DSL" with various bits of Sugar that are mixed into core providers as well
- # as user LWRPs. This module deliberately does not mixin the Resources or Defintions DSL bits
- # so that cookbooks are not injeting random things into the namespace of core providers.
+ # Part of a family of DSL mixins.
#
- # - If you are writing cookbooks: you have come to the wrong place, please inject things into
- # Chef::DSL::Recipe instead.
+ # Chef::DSL::Recipe mixes into Recipes and LWRP Providers.
+ # - this does not target core chef resources and providers.
+ # - this is restricted to recipe/resource/provider context where a resource collection exists.
+ # - cookbook authors should typically include modules into here.
#
- # - If you are writing core chef: you have come to the right place, please drop your DSL modules
- # into here.
+ # Chef::DSL::Core mixes into Recipes, LWRP Providers and Core Providers
+ # - this adds cores providers on top of the Recipe DSL.
+ # - this is restricted to recipe/resource/provider context where a resource collection exists.
+ # - core chef authors should typically include modules into here.
+ #
+ # Chef::DSL::Universal mixes into Recipes, LWRP Resources+Providers, Core Resources+Providers, and Attributes files.
+ # - this adds resources and attributes files.
+ # - do not add helpers which manipulate the resource collection.
+ # - this is for general-purpose stuff that is useful nearly everywhere.
+ # - it also pollutes the namespace of nearly every context, watch out.
#
module Core
+ include Chef::DSL::Universal
include Chef::DSL::DeclareResource
include Chef::Mixin::NotifyingBlock
- include Chef::Mixin::PowershellOut
- include Chef::Mixin::ShellOut
+ extend Chef::Mixin::LazyModuleInclude
end
end
end
diff --git a/lib/chef/dsl/recipe.rb b/lib/chef/dsl/recipe.rb
index c8b1aed74d..1bb8f130af 100644
--- a/lib/chef/dsl/recipe.rb
+++ b/lib/chef/dsl/recipe.rb
@@ -21,7 +21,6 @@ require "chef/exceptions"
require "chef/dsl/resources"
require "chef/dsl/definitions"
require "chef/dsl/data_query"
-require "chef/dsl/platform_introspection"
require "chef/dsl/include_recipe"
require "chef/dsl/registry_helper"
require "chef/dsl/reboot_pending"
@@ -33,20 +32,27 @@ require "chef/mixin/lazy_module_include"
class Chef
module DSL
- # This is the "Recipe DSL" which is all the sugar, plus all the resources and definitions
- # which are mixed into user LWRPs/Resources/Providers.
+ # Part of a family of DSL mixins.
#
- # - If you are writing cookbooks: you have come to the right place, please inject things
- # into here if you want to make them available to all recipe and non-core provider code.
+ # Chef::DSL::Recipe mixes into Recipes and LWRP Providers.
+ # - this does not target core chef resources and providers.
+ # - this is restricted to recipe/resource/provider context where a resource collection exists.
+ # - cookbook authors should typically include modules into here.
#
- # - If you are writing core chef: you have likely come to the wrong place, please consider
- # dropping your DSL modules into Chef::DSL::Core instead so that we can use them in core
- # providers (unless they are *only* intended for recipe code).
+ # Chef::DSL::Core mixes into Recipes, LWRP Providers and Core Providers
+ # - this adds cores providers on top of the Recipe DSL.
+ # - this is restricted to recipe/resource/provider context where a resource collection exists.
+ # - core chef authors should typically include modules into here.
+ #
+ # Chef::DSL::Universal mixes into Recipes, LWRP Resources+Providers, Core Resources+Providers, and Attributes files.
+ # - this adds resources and attributes files.
+ # - do not add helpers which manipulate the resource collection.
+ # - this is for general-purpose stuff that is useful nearly everywhere.
+ # - it also pollutes the namespace of nearly every context, watch out.
#
module Recipe
include Chef::DSL::Core
include Chef::DSL::DataQuery
- include Chef::DSL::PlatformIntrospection
include Chef::DSL::IncludeRecipe
include Chef::DSL::RegistryHelper
include Chef::DSL::RebootPending
diff --git a/lib/chef/dsl/universal.rb b/lib/chef/dsl/universal.rb
new file mode 100644
index 0000000000..810792f542
--- /dev/null
+++ b/lib/chef/dsl/universal.rb
@@ -0,0 +1,50 @@
+#--
+# Author:: Adam Jacob (<adam@chef.io>)
+# Author:: Christopher Walters (<cw@chef.io>)
+# Copyright:: Copyright 2008-2016, 2009-2015 Chef Software, 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/dsl/platform_introspection"
+require "chef/mixin/powershell_out"
+require "chef/mixin/shell_out"
+
+class Chef
+ module DSL
+ # Part of a family of DSL mixins.
+ #
+ # Chef::DSL::Recipe mixes into Recipes and LWRP Providers.
+ # - this does not target core chef resources and providers.
+ # - this is restricted to recipe/resource/provider context where a resource collection exists.
+ # - cookbook authors should typically include modules into here.
+ #
+ # Chef::DSL::Core mixes into Recipes, LWRP Providers and Core Providers
+ # - this adds cores providers on top of the Recipe DSL.
+ # - this is restricted to recipe/resource/provider context where a resource collection exists.
+ # - core chef authors should typically include modules into here.
+ #
+ # Chef::DSL::Universal mixes into Recipes, LWRP Resources+Providers, Core Resources+Providers, and Attributes files.
+ # - this adds resources and attributes files.
+ # - do not add helpers which manipulate the resource collection.
+ # - this is for general-purpose stuff that is useful nearly everywhere.
+ # - it also pollutes the namespace of nearly every context, watch out.
+ #
+ module Universal
+ include Chef::DSL::PlatformIntrospection
+ include Chef::Mixin::PowershellOut
+ include Chef::Mixin::ShellOut
+ end
+ end
+end
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 294358f405..8d77becbf0 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -25,7 +25,7 @@ require "chef/mixin/params_validate"
require "chef/mixin/from_file"
require "chef/mixin/deep_merge"
require "chef/dsl/include_attribute"
-require "chef/dsl/platform_introspection"
+require "chef/dsl/universal"
require "chef/environment"
require "chef/server_api"
require "chef/run_list"
@@ -58,7 +58,7 @@ class Chef
include Chef::Mixin::FromFile
include Chef::DSL::IncludeAttribute
- include Chef::DSL::PlatformIntrospection
+ include Chef::DSL::Universal
include Chef::Mixin::ParamsValidate
diff --git a/lib/chef/provider/lwrp_base.rb b/lib/chef/provider/lwrp_base.rb
index f5ba30ba15..cbf25f1e4f 100644
--- a/lib/chef/provider/lwrp_base.rb
+++ b/lib/chef/provider/lwrp_base.rb
@@ -34,7 +34,6 @@ class Chef
# These were previously provided by Chef::Mixin::RecipeDefinitionDSLCore.
# They are not included by its replacement, Chef::DSL::Recipe, but
# they may be used in existing LWRPs.
- include Chef::DSL::PlatformIntrospection
include Chef::DSL::DataQuery
# Allow include_recipe from within LWRP provider code
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 21b2308688..2633187690 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -19,7 +19,6 @@
#
require "chef/exceptions"
-require "chef/dsl/platform_introspection"
require "chef/dsl/data_query"
require "chef/dsl/registry_helper"
require "chef/dsl/reboot_pending"
@@ -42,8 +41,7 @@ require "set"
require "chef/mixin/deprecation"
require "chef/mixin/properties"
require "chef/mixin/provides"
-require "chef/mixin/shell_out"
-require "chef/mixin/powershell_out"
+require "chef/dsl/universal"
class Chef
class Resource
@@ -53,14 +51,11 @@ class Chef
#
include Chef::DSL::DataQuery
- include Chef::DSL::PlatformIntrospection
include Chef::DSL::RegistryHelper
include Chef::DSL::RebootPending
extend Chef::Mixin::Provides
- # This lets user code do things like `not_if { shell_out!("command") }`
- include Chef::Mixin::ShellOut
- include Chef::Mixin::PowershellOut
+ include Chef::DSL::Universal
# Bring in `property` and `property_type`
include Chef::Mixin::Properties