Class: Puppet::Parser::Resource
- Includes:
- YamlTrimmer, Resource::TypeCollectionHelper, Util, Util::Errors, Util::Logging, Util::MethodHelper, Util::Tagging
- Defined in:
- lib/vendor/puppet/parser/resource.rb
Overview
The primary difference between this class and its parent is that this class has rules on who can set parameters
Defined Under Namespace
Classes: Param
Constant Summary
Constants included from YamlTrimmer
Constants included from Util
Util::AbsolutePathPosix, Util::AbsolutePathWindows
Constants inherited from Resource
Resource::ATTRIBUTES, Resource::Reference
Constants included from Indirector
Instance Attribute Summary collapse
-
#catalog ⇒ Object
Returns the value of attribute catalog.
-
#collector_id ⇒ Object
Returns the value of attribute collector_id.
-
#evaluated ⇒ Object
Returns the value of attribute evaluated.
-
#exported ⇒ Object
Returns the value of attribute exported.
-
#file ⇒ Object
Returns the value of attribute file.
-
#line ⇒ Object
Returns the value of attribute line.
-
#override ⇒ Object
Returns the value of attribute override.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#scope ⇒ Object
Returns the value of attribute scope.
-
#source ⇒ Object
Returns the value of attribute source.
-
#translated ⇒ Object
Returns the value of attribute translated.
-
#virtual ⇒ Object
Returns the value of attribute virtual.
Attributes inherited from Resource
#strict, #title, #type, #validate_parameters
Class Method Summary collapse
-
.relationship_parameter?(name) ⇒ Boolean
Determine whether the provided parameter name is a relationship parameter.
Instance Method Summary collapse
- #[](param) ⇒ Object
- #[]=(param, value) ⇒ Object
-
#add_edge_to_stage ⇒ Object
Process the stage metaparameter for a class.
- #eachparam ⇒ Object
- #environment ⇒ Object
-
#evaluate ⇒ Object
Retrieve the associated definition and evaluate it.
- #evaluated? ⇒ Boolean
-
#finish ⇒ Object
Do any finishing work on this object, called before evaluation or before storage/translation.
-
#finished? ⇒ Boolean
Has this resource already been finished?.
-
#initialize(*args) ⇒ Resource
constructor
A new instance of Resource.
-
#isomorphic? ⇒ Boolean
Is this resource modeling an isomorphic resource type?.
-
#merge(resource) ⇒ Object
Merge an override resource in.
-
#metaparam_compatibility_mode? ⇒ Boolean
Unless we’re running >= 0.25, we’re in compat mode.
- #name ⇒ Object
- #override? ⇒ Boolean
-
#path ⇒ Object
A temporary occasion, until I get paths in the scopes figured out.
-
#set_parameter(param, value = nil) ⇒ Object
Define a parameter in our resource.
- #to_hash ⇒ Object
-
#to_ral ⇒ Object
Convert this resource to a RAL resource.
-
#to_resource ⇒ Object
Create a Puppet::Resource instance from this parser resource.
-
#to_trans ⇒ Object
Translate our object to a transportable object.
-
#translated? ⇒ Boolean
Set up some boolean test methods.
Methods included from YamlTrimmer
Methods included from Util::Tagging
Methods included from Util::Logging
#clear_deprecation_warnings, #deprecation_warning, #send_log
Methods included from Util::Errors
#adderrorcontext, #devfail, #error_context, #exceptwrap, #fail
Methods included from Util::MethodHelper
#requiredopts, #set_options, #symbolize_options
Methods included from Util
absolute_path?, activerecord_version, benchmark, binread, chuser, classproxy, #execfail, #execpipe, execute, execute_posix, execute_windows, logmethods, memory, path_to_uri, proxy, replace_file, safe_posix_fork, symbolize, symbolizehash, symbolizehash!, synchronize_on, thinmark, #threadlock, uri_to_path, wait_for_output, which, withumask
Methods included from Util::POSIX
#get_posix_field, #gid, #idfield, #methodbyid, #methodbyname, #search_posix_field, #uid
Methods included from Resource::TypeCollectionHelper
Methods inherited from Resource
#==, #builtin?, #builtin_type?, #each, #environment=, from_pson, #include?, #inspect, #key_attributes, #prune_parameters, #ref, #resolve, #resource_type, #to_manifest, #to_pson, #to_pson_data_hash, #to_ref, #to_s, #to_trans_ref, #to_transobject, #uniqueness_key, #valid_parameter?, #validate_parameter, value_to_pson_data, #yaml_property_munge
Methods included from Util::Pson
Methods included from Indirector
Constructor Details
#initialize(*args) ⇒ Resource
Returns a new instance of Resource.
121 122 123 124 125 126 |
# File 'lib/vendor/puppet/parser/resource.rb', line 121 def initialize(*args) raise ArgumentError, "Resources require a scope" unless args.last[:scope] super @source ||= scope.source end |
Instance Attribute Details
#catalog ⇒ Object
Returns the value of attribute catalog.
22 23 24 |
# File 'lib/vendor/puppet/parser/resource.rb', line 22 def catalog @catalog end |
#collector_id ⇒ Object
Returns the value of attribute collector_id.
21 22 23 |
# File 'lib/vendor/puppet/parser/resource.rb', line 21 def collector_id @collector_id end |
#evaluated ⇒ Object
Returns the value of attribute evaluated.
22 23 24 |
# File 'lib/vendor/puppet/parser/resource.rb', line 22 def evaluated @evaluated end |
#exported ⇒ Object
Returns the value of attribute exported.
25 26 27 |
# File 'lib/vendor/puppet/parser/resource.rb', line 25 def exported @exported end |
#file ⇒ Object
Returns the value of attribute file.
23 24 25 |
# File 'lib/vendor/puppet/parser/resource.rb', line 23 def file @file end |
#line ⇒ Object
Returns the value of attribute line.
23 24 25 |
# File 'lib/vendor/puppet/parser/resource.rb', line 23 def line @line end |
#override ⇒ Object
Returns the value of attribute override.
22 23 24 |
# File 'lib/vendor/puppet/parser/resource.rb', line 22 def override @override end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
25 26 27 |
# File 'lib/vendor/puppet/parser/resource.rb', line 25 def parameters @parameters end |
#scope ⇒ Object
Returns the value of attribute scope.
21 22 23 |
# File 'lib/vendor/puppet/parser/resource.rb', line 21 def scope @scope end |
#source ⇒ Object
Returns the value of attribute source.
21 22 23 |
# File 'lib/vendor/puppet/parser/resource.rb', line 21 def source @source end |
#translated ⇒ Object
Returns the value of attribute translated.
22 23 24 |
# File 'lib/vendor/puppet/parser/resource.rb', line 22 def translated @translated end |
#virtual ⇒ Object
Returns the value of attribute virtual.
22 23 24 |
# File 'lib/vendor/puppet/parser/resource.rb', line 22 def virtual @virtual end |
Class Method Details
.relationship_parameter?(name) ⇒ Boolean
Determine whether the provided parameter name is a relationship parameter.
28 29 30 31 |
# File 'lib/vendor/puppet/parser/resource.rb', line 28 def self.relationship_parameter?(name) @relationship_names ||= Puppet::Type.relationship_params.collect { |p| p.name } @relationship_names.include?(name) end |
Instance Method Details
#[](param) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/vendor/puppet/parser/resource.rb', line 38 def [](param) param = param.intern if param == :title return self.title end if @parameters.has_key?(param) @parameters[param].value else nil end end |
#[]=(param, value) ⇒ Object
50 51 52 |
# File 'lib/vendor/puppet/parser/resource.rb', line 50 def []=(param, value) set_parameter(param, value) end |
#add_edge_to_stage ⇒ Object
Process the stage metaparameter for a class. A containment edge is drawn from the class to the stage. The stage for containment defaults to main, if none is specified.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/vendor/puppet/parser/resource.rb', line 67 def add_edge_to_stage return unless self.type.to_s.downcase == "class" unless stage = catalog.resource(:stage, self[:stage] || (scope && scope.resource && scope.resource[:stage]) || :main) raise ArgumentError, "Could not find stage #{self[:stage] || :main} specified by #{self}" end self[:stage] ||= stage.title unless stage.title == :main catalog.add_edge(stage, self) end |
#eachparam ⇒ Object
54 55 56 57 58 |
# File 'lib/vendor/puppet/parser/resource.rb', line 54 def eachparam @parameters.each do |name, param| yield param end end |
#environment ⇒ Object
60 61 62 |
# File 'lib/vendor/puppet/parser/resource.rb', line 60 def environment scope.environment end |
#evaluate ⇒ Object
Retrieve the associated definition and evaluate it.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/vendor/puppet/parser/resource.rb', line 79 def evaluate return if evaluated? @evaluated = true if klass = resource_type and ! builtin_type? finish evaluated_code = klass.evaluate_code(self) return evaluated_code elsif builtin? devfail "Cannot evaluate a builtin type (#{type})" else self.fail "Cannot find definition #{type}" end end |
#evaluated? ⇒ Boolean
36 |
# File 'lib/vendor/puppet/parser/resource.rb', line 36 def evaluated?; !!@evaluated; end |
#finish ⇒ Object
Do any finishing work on this object, called before evaluation or before storage/translation.
107 108 109 110 111 112 113 114 |
# File 'lib/vendor/puppet/parser/resource.rb', line 107 def finish return if finished? @finished = true add_defaults validate end |
#finished? ⇒ Boolean
Has this resource already been finished?
117 118 119 |
# File 'lib/vendor/puppet/parser/resource.rb', line 117 def finished? @finished end |
#isomorphic? ⇒ Boolean
Is this resource modeling an isomorphic resource type?
129 130 131 132 133 134 135 |
# File 'lib/vendor/puppet/parser/resource.rb', line 129 def isomorphic? if builtin_type? return resource_type.isomorphic? else return true end end |
#merge(resource) ⇒ Object
Merge an override resource in. This will throw exceptions if any overrides aren’t allowed.
139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/vendor/puppet/parser/resource.rb', line 139 def merge(resource) # Test the resource scope, to make sure the resource is even allowed # to override. unless self.source.object_id == resource.source.object_id || resource.source.child_of?(self.source) raise Puppet::ParseError.new("Only subclasses can override parameters", resource.line, resource.file) end # Some of these might fail, but they'll fail in the way we want. resource.parameters.each do |name, param| override_parameter(param) end end |
#metaparam_compatibility_mode? ⇒ Boolean
Unless we’re running >= 0.25, we’re in compat mode.
152 153 154 |
# File 'lib/vendor/puppet/parser/resource.rb', line 152 def ! (catalog and ver = (catalog.client_version||'0.0.0').split(".") and (ver[0] > "0" or ver[1].to_i >= 25)) end |
#name ⇒ Object
156 157 158 |
# File 'lib/vendor/puppet/parser/resource.rb', line 156 def name self[:name] || self.title end |
#override? ⇒ Boolean
35 |
# File 'lib/vendor/puppet/parser/resource.rb', line 35 def override?; !!@override; end |
#path ⇒ Object
A temporary occasion, until I get paths in the scopes figured out.
161 162 163 |
# File 'lib/vendor/puppet/parser/resource.rb', line 161 def path to_s end |
#set_parameter(param, value = nil) ⇒ Object
Define a parameter in our resource. if we ever receive a parameter named ‘tag’, set the resource tags with its value.
168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/vendor/puppet/parser/resource.rb', line 168 def set_parameter(param, value = nil) if ! value.nil? param = Puppet::Parser::Resource::Param.new( :name => param, :value => value, :source => self.source ) elsif ! param.is_a?(Puppet::Parser::Resource::Param) raise ArgumentError, "Must pass a parameter or all necessary values" end tag(*param.value) if param.name == :tag # And store it in our parameter hash. @parameters[param.name] = param end |
#to_hash ⇒ Object
183 184 185 186 187 188 189 190 |
# File 'lib/vendor/puppet/parser/resource.rb', line 183 def to_hash @parameters.inject({}) do |hash, ary| param = ary[1] # Skip "undef" values. hash[param.name] = param.value if param.value != :undef hash end end |
#to_ral ⇒ Object
Convert this resource to a RAL resource. We hackishly go via the transportable stuff.
240 241 242 |
# File 'lib/vendor/puppet/parser/resource.rb', line 240 def to_ral to_resource.to_ral end |
#to_resource ⇒ Object
Create a Puppet::Resource instance from this parser resource. We plan, at some point, on not needing to do this conversion, but it’s sufficient for now.
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/vendor/puppet/parser/resource.rb', line 196 def to_resource result = Puppet::Resource.new(type, title) to_hash.each do |p, v| if v.is_a?(Puppet::Resource) v = Puppet::Resource.new(v.type, v.title) elsif v.is_a?(Array) # flatten resource references arrays v = v.flatten if v.flatten.find { |av| av.is_a?(Puppet::Resource) } v = v.collect do |av| av = Puppet::Resource.new(av.type, av.title) if av.is_a?(Puppet::Resource) av end end # If the value is an array with only one value, then # convert it to a single value. This is largely so that # the database interaction doesn't have to worry about # whether it returns an array or a string. result[p] = if v.is_a?(Array) and v.length == 1 v[0] else v end end result.file = self.file result.line = self.line result.exported = self.exported result.virtual = self.virtual result.tag(*self.) result end |
#to_trans ⇒ Object
Translate our object to a transportable object.
232 233 234 235 236 |
# File 'lib/vendor/puppet/parser/resource.rb', line 232 def to_trans return nil if virtual? to_resource.to_trans end |
#translated? ⇒ Boolean
Set up some boolean test methods
34 |
# File 'lib/vendor/puppet/parser/resource.rb', line 34 def translated?; !!@translated; end |