diff options
author | Ezra Zygmuntowicz <ez@engineyard.com> | 2008-10-08 14:19:52 -0700 |
---|---|---|
committer | Ezra Zygmuntowicz <ez@engineyard.com> | 2008-10-08 14:19:52 -0700 |
commit | c5d33c1298834ce40b8fbf344f281045771b5371 (patch) | |
tree | 1f0d4c7eab1eb379b544282a7ce48052acf719a5 /lib/chef/recipe.rb | |
parent | 3d14601aea23dee3899d097324875274da419d84 (diff) | |
download | chef-c5d33c1298834ce40b8fbf344f281045771b5371.tar.gz |
big refactor of the repo layout. move to a chef gem and a chef-server gem all with proper deps
Diffstat (limited to 'lib/chef/recipe.rb')
-rw-r--r-- | lib/chef/recipe.rb | 127 |
1 files changed, 0 insertions, 127 deletions
diff --git a/lib/chef/recipe.rb b/lib/chef/recipe.rb deleted file mode 100644 index e2e20640f7..0000000000 --- a/lib/chef/recipe.rb +++ /dev/null @@ -1,127 +0,0 @@ -# -# Author:: Adam Jacob (<adam@hjksolutions.com>) -# Copyright:: Copyright (c) 2008 HJK Solutions, LLC -# 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 File.join(File.dirname(__FILE__), "mixin", "from_file") - -class Chef - class Recipe - - include Chef::Mixin::FromFile - - attr_accessor :cookbook_name, :recipe_name, :recipe, :node, :collection, - :definitions, :params, :cookbook_loader - - def initialize(cookbook_name, recipe_name, node, collection=nil, definitions=nil, cookbook_loader=nil) - @cookbook_name = cookbook_name - @recipe_name = recipe_name - @node = node - - if collection - @collection = collection - else - @collection = Chef::ResourceCollection.new() - end - - if definitions - @definitions = definitions - else - @definitions = Hash.new - end - - if cookbook_loader - @cookbook_loader = cookbook_loader - else - @cookbook_loader = Chef::CookbookLoader.new() - end - - @params = Hash.new - end - - def require_recipe(*args) - args.flatten.each do |recipe| - rmatch = recipe.match(/(.+?)::(.+)/) - if rmatch - cookbook = @cookbook_loader[rmatch[1]] - cookbook.load_recipe(rmatch[2], @node, @collection, @definitions, @cookbook_loader) - else - cookbook = @cookbook_loader[recipe] - cookbook.load_recipe("default", @node, @collection, @definitions, @cookbook_loader) - end - end - end - - def resources(*args) - @collection.resources(*args) - end - - def search(type, query, &block) - Chef::Log.debug("Searching #{type} index with #{query}") - r = Chef::REST.new(Chef::Config[:search_url]) - results = r.get_rest("search/#{type}?q=#{query}") - Chef::Log.debug("Searching #{type} index with #{query} returned #{results.length} entries") - results.each do |sr| - block.call(sr) - end - end - - def method_missing(method_symbol, *args, &block) - resource = nil - # 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 @definitions.has_key?(method_symbol) - new_def = @definitions[method_symbol].dup - new_def.instance_eval(&block) if block - new_recipe = Chef::Recipe.new(@cookbook_name, @recipe_name, @node, @collection, @definitions, @cookbook_loader) - new_recipe.params = new_def.params - new_recipe.params[:name] = args[0] - new_recipe.instance_eval(&new_def.recipe) - else - method_name = method_symbol.to_s - # Otherwise, we're rocking the regular resource call route. - rname = nil - mn = method_name.match(/^(.+)_(.+)$/) - if mn - rname = "Chef::Resource::#{mn[1].capitalize}#{mn[2].capitalize}" - else - short_match = method_name.match(/^(.+)$/) - if short_match - rname = "Chef::Resource::#{short_match[1].capitalize}" - end - end - begin - args << @collection - args << @node - resource = eval(rname).new(*args) - resource.cookbook_name = @cookbook_name - resource.recipe_name = @recipe_name - resource.params = @params - resource.instance_eval(&block) if block - rescue Exception => e - if e.kind_of?(NameError) && e.to_s =~ /Chef::Resource/ - raise NameError, "Cannot find #{rname} for #{method_name}\nOriginal: #{e.to_s}" - else - raise e - end - end - @collection << resource - resource - end - end - end -end
\ No newline at end of file |