diff options
author | danielsdeleo <dan@opscode.com> | 2012-10-17 11:44:33 -0700 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2012-10-19 14:15:59 -0700 |
commit | 8b4c0300847cd0ce079a5c997b484579065cd8ac (patch) | |
tree | 88ce2cb0fb48e962592ac7e7daf462636816ac16 /chef/lib | |
parent | 35157bd1a64a29e8cc44853e6cee8ae0ae07a745 (diff) | |
download | chef-8b4c0300847cd0ce079a5c997b484579065cd8ac.tar.gz |
[CHEF-3499] Create DSL namespace, move recipe DSL there.
Diffstat (limited to 'chef/lib')
-rw-r--r-- | chef/lib/chef/dsl/recipe.rb | 82 | ||||
-rw-r--r-- | chef/lib/chef/mixin/recipe_definition_dsl_core.rb | 69 | ||||
-rw-r--r-- | chef/lib/chef/provider.rb | 6 | ||||
-rw-r--r-- | chef/lib/chef/provider/deploy.rb | 3 | ||||
-rw-r--r-- | chef/lib/chef/recipe.rb | 4 |
5 files changed, 97 insertions, 67 deletions
diff --git a/chef/lib/chef/dsl/recipe.rb b/chef/lib/chef/dsl/recipe.rb new file mode 100644 index 0000000000..e1309ac22a --- /dev/null +++ b/chef/lib/chef/dsl/recipe.rb @@ -0,0 +1,82 @@ +#-- +# Author:: Adam Jacob (<adam@opscode.com>) +# Author:: Christopher Walters (<cw@opscode.com>) +# Copyright:: Copyright (c) 2008, 2009 Opscode, 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/resource' +require 'chef/resource_platform_map' +require 'chef/mixin/convert_to_class_name' +require 'chef/mixin/language' + +class Chef + module DSL + + module Recipe + + include Chef::Mixin::ConvertToClassName + include Chef::Mixin::Language + + def method_missing(method_symbol, *args, &block) + # If we have a definition that matches, we want to use that instead. This should + # let you do some really crazy over-riding of "native" types, if you really want + # to. + if run_context.definitions.has_key?(method_symbol) + # This dupes the high level object, but we still need to dup the params + new_def = run_context.definitions[method_symbol].dup + new_def.params = new_def.params.dup + new_def.node = run_context.node + # This sets up the parameter overrides + new_def.instance_eval(&block) if block + new_recipe = Chef::Recipe.new(cookbook_name, @recipe_name, run_context) + new_recipe.params = new_def.params + new_recipe.params[:name] = args[0] + new_recipe.instance_eval(&new_def.recipe) + else + # Otherwise, we're rocking the regular resource call route. + + # Checks the new platform => short_name => resource mapping initially + # then fall back to the older approach (Chef::Resource.const_get) for + # backward compatibility + resource_class = Chef::Resource.resource_for_node(method_symbol, run_context.node) + + super unless resource_class + raise ArgumentError, "You must supply a name when declaring a #{method_symbol} resource" unless args.size > 0 + + # If we have a resource like this one, we want to steal its state + args << run_context + resource = resource_class.new(*args) + resource.load_prior_resource + resource.cookbook_name = cookbook_name + resource.recipe_name = @recipe_name + resource.params = @params + resource.source_line = caller[0] + # Determine whether this resource is being created in the context of an enclosing Provider + resource.enclosing_provider = self.is_a?(Chef::Provider) ? self : nil + # Evaluate resource attribute DSL + resource.instance_eval(&block) if block + + # Run optional resource hook + resource.after_created + + run_context.resource_collection.insert(resource) + resource + end + end + + end + end +end diff --git a/chef/lib/chef/mixin/recipe_definition_dsl_core.rb b/chef/lib/chef/mixin/recipe_definition_dsl_core.rb index cf89600654..ff422d892f 100644 --- a/chef/lib/chef/mixin/recipe_definition_dsl_core.rb +++ b/chef/lib/chef/mixin/recipe_definition_dsl_core.rb @@ -17,70 +17,17 @@ # limitations under the License. # -require 'chef/resource' -require 'chef/resource_platform_map' -require 'chef/mixin/convert_to_class_name' -require 'chef/mixin/language' +### +# NOTE: This file and constant are here only for backwards compatibility. +# New code should use Chef::DSL::Recipe instead. +# +# This constant (module name) will eventually be deprecated and then removed. +### -#-- -# UGH. this is a circular require that will cause an uninitialized constant -# error, but this file really does depend on Chef::Recipe. oh well. -# require 'chef/recipe' +require 'chef/dsl/recipe' class Chef module Mixin - module RecipeDefinitionDSLCore - - include Chef::Mixin::ConvertToClassName - include Chef::Mixin::Language - - def method_missing(method_symbol, *args, &block) - # If we have a definition that matches, we want to use that instead. This should - # let you do some really crazy over-riding of "native" types, if you really want - # to. - if run_context.definitions.has_key?(method_symbol) - # This dupes the high level object, but we still need to dup the params - new_def = run_context.definitions[method_symbol].dup - new_def.params = new_def.params.dup - new_def.node = run_context.node - # This sets up the parameter overrides - new_def.instance_eval(&block) if block - new_recipe = Chef::Recipe.new(cookbook_name, @recipe_name, run_context) - new_recipe.params = new_def.params - new_recipe.params[:name] = args[0] - new_recipe.instance_eval(&new_def.recipe) - else - # Otherwise, we're rocking the regular resource call route. - - # Checks the new platform => short_name => resource mapping initially - # then fall back to the older approach (Chef::Resource.const_get) for - # backward compatibility - resource_class = Chef::Resource.resource_for_node(method_symbol, run_context.node) - - super unless resource_class - raise ArgumentError, "You must supply a name when declaring a #{method_symbol} resource" unless args.size > 0 - - # If we have a resource like this one, we want to steal its state - args << run_context - resource = resource_class.new(*args) - resource.load_prior_resource - resource.cookbook_name = cookbook_name - resource.recipe_name = @recipe_name - resource.params = @params - resource.source_line = caller[0] - # Determine whether this resource is being created in the context of an enclosing Provider - resource.enclosing_provider = self.is_a?(Chef::Provider) ? self : nil - # Evaluate resource attribute DSL - resource.instance_eval(&block) if block - - # Run optional resource hook - resource.after_created - - run_context.resource_collection.insert(resource) - resource - end - end - - end + RecipeDefinitionDSLCore = Chef::DSL::Recipe end end diff --git a/chef/lib/chef/provider.rb b/chef/lib/chef/provider.rb index d392c299c1..b7f8b3dddc 100644 --- a/chef/lib/chef/provider.rb +++ b/chef/lib/chef/provider.rb @@ -19,12 +19,12 @@ require 'chef/mixin/from_file' require 'chef/mixin/convert_to_class_name' -require 'chef/mixin/recipe_definition_dsl_core' +require 'chef/dsl/recipe' require 'chef/mixin/enforce_ownership_and_permissions' require 'chef/mixin/why_run' class Chef class Provider - include Chef::Mixin::RecipeDefinitionDSLCore + include Chef::DSL::Recipe include Chef::Mixin::WhyRun include Chef::Mixin::EnforceOwnershipAndPermissions @@ -192,7 +192,7 @@ class Chef new_provider_class = Class.new self do |cls| - include Chef::Mixin::RecipeDefinitionDSLCore + include Chef::DSL::Recipe def load_current_resource # silence Chef::Exceptions::Override exception diff --git a/chef/lib/chef/provider/deploy.rb b/chef/lib/chef/provider/deploy.rb index 2920917d11..60c626ab08 100644 --- a/chef/lib/chef/provider/deploy.rb +++ b/chef/lib/chef/provider/deploy.rb @@ -20,12 +20,13 @@ require "chef/mixin/command" require "chef/mixin/from_file" require "chef/provider/git" require "chef/provider/subversion" +require 'chef/dsl/recipe' class Chef class Provider class Deploy < Chef::Provider - include Chef::Mixin::RecipeDefinitionDSLCore + include Chef::DSL::Recipe include Chef::Mixin::FromFile include Chef::Mixin::Command diff --git a/chef/lib/chef/recipe.rb b/chef/lib/chef/recipe.rb index 258a56e715..fc38a734c5 100644 --- a/chef/lib/chef/recipe.rb +++ b/chef/lib/chef/recipe.rb @@ -18,7 +18,7 @@ # -require 'chef/mixin/recipe_definition_dsl_core' +require 'chef/dsl/recipe' require 'chef/mixin/from_file' require 'chef/mixin/language' require 'chef/mixin/language_include_recipe' @@ -33,7 +33,7 @@ class Chef include Chef::Mixin::FromFile include Chef::Mixin::Language include Chef::Mixin::LanguageIncludeRecipe - include Chef::Mixin::RecipeDefinitionDSLCore + include Chef::DSL::Recipe include Chef::Mixin::Deprecation attr_accessor :cookbook_name, :recipe_name, :recipe, :params, :run_context |