Class: Chef::Resource::LWRPBase
- Inherits:
-
Resource
- Object
- Resource
- Chef::Resource::LWRPBase
- Extended by:
- Mixin::ConvertToClassName, Mixin::FromFile
- Defined in:
- lib/chef/resource/lwrp_base.rb
Overview
Chef::Resource::LWRPBase
Base class for LWRP resources. Adds DSL sugar on top of Chef::Resource, so attributes, default action, etc. can be defined with pleasing syntax.
Class Attribute Summary collapse
-
.run_context ⇒ Object
Set the run context on the class.
Attributes included from Mixin::FromFile
Class Method Summary collapse
-
.actions(*action_names) ⇒ Object
Adds
action_namesto the list of valid actions for this resource. - .build_from_file(cookbook_name, filename, run_context) ⇒ Object
- .node ⇒ Object
- .valid_actions(*args) ⇒ Object deprecated Deprecated.
Methods included from Mixin::FromFile
Methods included from Mixin::ConvertToClassName
convert_to_class_name, convert_to_snake_case, filename_to_qualified_string, normalize_snake_case_name, snake_case_basename
Class Attribute Details
.run_context ⇒ Object
Set the run context on the class. Used to provide access to the node during class definition.
96 97 98 |
# File 'lib/chef/resource/lwrp_base.rb', line 96 def run_context @run_context end |
Class Method Details
.actions(*action_names) ⇒ Object
Adds action_names to the list of valid actions for this resource.
Does not include superclass's action list when appending.
78 79 80 81 82 83 84 85 |
# File 'lib/chef/resource/lwrp_base.rb', line 78 def actions(*action_names) action_names = action_names.flatten if !action_names.empty? && !@allowed_actions self.allowed_actions = ([ :nothing ] + action_names).uniq else allowed_actions(*action_names) end end |
.build_from_file(cookbook_name, filename, run_context) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/chef/resource/lwrp_base.rb', line 45 def build_from_file(cookbook_name, filename, run_context) if LWRPBase.loaded_lwrps[filename] Chef::Log.trace("Custom resource #{filename} from cookbook #{cookbook_name} has already been loaded! Skipping the reload.") return loaded_lwrps[filename] end resource_name = filename_to_qualified_string(cookbook_name, filename) resource_class = Class.new(self) resource_class.run_context = run_context resource_class.class_from_file(filename) # Make a useful string for the class (rather than <Class:312894723894>) resource_class.instance_eval do define_singleton_method(:to_s) do "Custom resource #{resource_name} from cookbook #{cookbook_name}" end define_singleton_method(:inspect) { to_s } end Chef::Log.trace("Loaded contents of #{filename} into resource #{resource_name} (#{resource_class})") # wire up the default resource name after the class is parsed only if we haven't declared one. # (this ordering is important for MapCollision deprecation warnings) resource_class.provides resource_name.to_sym unless Chef::ResourceResolver.includes_handler?(resource_name.to_sym, self) LWRPBase.loaded_lwrps[filename] = resource_class resource_class end |
.node ⇒ Object
98 99 100 |
# File 'lib/chef/resource/lwrp_base.rb', line 98 def node run_context ? run_context.node : nil end |