Module: Chef::DSL::Recipe
- Includes:
- DeclareResource, Definitions, Resources, Mixin::PowershellOut, Mixin::ShellOut
- Included in:
- FullDSL, Provider::Deploy, Provider::LWRPBase
- Defined in:
- lib/chef/dsl/recipe.rb
Overview
Chef::DSL::Recipe
Provides the primary recipe DSL functionality for defining Chef resource objects via method calls.
Defined Under Namespace
Modules: FullDSL
Constant Summary
Constants included from Mixin::ShellOut
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Method Summary collapse
- #describe_self_for_error ⇒ Object
- #exec(args) ⇒ Object
- #have_resource_class_for?(snake_case_name) ⇒ Boolean
-
#method_missing(method_symbol, *args, &block) ⇒ Object
DEPRECATED: method_missing must live for backcompat purposes until Chef 13.
- #resource_class_for(snake_case_name) ⇒ Object
Methods included from DeclareResource
#build_resource, #declare_resource
Methods included from Definitions
add_definition, #evaluate_resource_definition, #has_resource_definition?
Methods included from Resources
add_resource_dsl, remove_resource_dsl
Methods included from ChefProvisioning
Methods included from Cheffish
Methods included from Mixin::PowershellOut
#powershell_out, #powershell_out!
Methods included from Mixin::WindowsArchitectureHelper
#assert_valid_windows_architecture!, #disable_wow64_file_redirection, #forced_32bit_override_required?, #is_i386_process_on_x86_64_windows?, #node_supports_windows_architecture?, #node_windows_architecture, #restore_wow64_file_redirection, #valid_windows_architecture?, #with_os_architecture, #wow64_architecture_override_required?, #wow64_directory
Methods included from Mixin::ShellOut
#run_command_compatible_options, #shell_out, #shell_out!, #shell_out_with_systems_locale, #shell_out_with_systems_locale!
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_symbol, *args, &block) ⇒ Object
DEPRECATED: method_missing must live for backcompat purposes until Chef 13.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/chef/dsl/recipe.rb', line 68 def method_missing(method_symbol, *args, &block) # # If there is already DSL for this, someone must have called # method_missing manually. Not a fan. Not. A. Fan. # if respond_to?(method_symbol) Chef.log_deprecation("Calling method_missing(#{method_symbol.inspect}) directly is deprecated in Chef 12 and will be removed in Chef 13. Use public_send() or send() instead.") return send(method_symbol, *args, &block) end # # If a definition exists, then Chef::DSL::Definitions.add_definition was # never called. DEPRECATED. # if run_context.definitions.has_key?(method_symbol.to_sym) Chef.log_deprecation("Definition #{method_symbol} (#{run_context.definitions[method_symbol.to_sym]}) was added to the run_context without calling Chef::DSL::Definitions.add_definition(#{method_symbol.to_sym.inspect}). This will become required in Chef 13.") Chef::DSL::Definitions.add_definition(method_symbol) return send(method_symbol, *args, &block) end # # See if the resource exists anyway. If the user had set # Chef::Resource::Blah = <resource>, a deprecation warning will be # emitted and the DSL method 'blah' will be added to the DSL. # resource_class = Chef::ResourceResolver.resolve(method_symbol, node: run_context ? run_context.node : nil) if resource_class Chef::DSL::Resources.add_resource_dsl(method_symbol) return send(method_symbol, *args, &block) end begin super rescue NoMethodError raise NoMethodError, "No resource or method named `#{method_symbol}' for #{describe_self_for_error}" rescue NameError raise NameError, "No resource, method, or local variable named `#{method_symbol}' for #{describe_self_for_error}" end end |
Instance Method Details
#describe_self_for_error ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/chef/dsl/recipe.rb', line 52 def describe_self_for_error if respond_to?(:name) %Q{`#{self.class} "#{name}"'} elsif respond_to?(:recipe_name) %Q{`#{self.class} "#{recipe_name}"'} else to_s end end |
#exec(args) ⇒ Object
62 63 64 |
# File 'lib/chef/dsl/recipe.rb', line 62 def exec(args) raise Chef::Exceptions::ResourceNotFound, "exec was called, but you probably meant to use an execute resource. If not, please call Kernel#exec explicitly. The exec block called was \"#{args}\"" end |
#have_resource_class_for?(snake_case_name) ⇒ Boolean
46 47 48 49 50 |
# File 'lib/chef/dsl/recipe.rb', line 46 def have_resource_class_for?(snake_case_name) not resource_class_for(snake_case_name).nil? rescue NameError false end |
#resource_class_for(snake_case_name) ⇒ Object
42 43 44 |
# File 'lib/chef/dsl/recipe.rb', line 42 def resource_class_for(snake_case_name) Chef::Resource.resource_for_node(snake_case_name, run_context.node) end |