Module: Poise::Helpers::Subresources::Child::ClassMethods
- Included in:
- Poise::Helpers::Subresources::Child
- Defined in:
- lib/poise/helpers/subresources/child.rb
Overview
Instance Method Summary collapse
-
#parent_attribute(name, type: Chef::Resource, optional: false, auto: true, default: nil)
Create a new kind of parent link.
-
#parent_attributes ⇒ Hash<Symbol, Class>
Return the name of all parent relationships on this class.
- #parent_auto(val = nil) ⇒ Object
- #parent_default(*args) ⇒ Object
- #parent_optional(val = nil) ⇒ Object
- #parent_type(type = nil) ⇒ Object
Instance Method Details
#parent_attribute(name, type: Chef::Resource, optional: false, auto: true, default: nil)
This method returns an undefined value.
Create a new kind of parent link.
240 241 242 243 244 245 246 |
# File 'lib/poise/helpers/subresources/child.rb', line 240 def parent_attribute(name, type: Chef::Resource, optional: false, auto: true, default: nil) name = :"parent_#{name}" (@parent_attributes ||= {})[name] = type define_method(name) do |*args| _parent(name, type, optional, auto, default, *args) end end |
#parent_attributes ⇒ Hash<Symbol, Class>
Return the name of all parent relationships on this class.
252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/poise/helpers/subresources/child.rb', line 252 def parent_attributes {}.tap do |attrs| # Grab superclass's attributes if possible. attrs.update(Poise::Utils.ancestor_send(self, :parent_attributes, default: {})) # Local default parent. attrs[:parent] = parent_type # Extra locally defined parents. attrs.update(@parent_attributes) if @parent_attributes # Remove anything with the type set to true. attrs.reject! {|name, type| type == true } end end |
#parent_auto ⇒ Boolean #parent_auto(val) ⇒ Boolean
200 201 202 203 204 205 206 207 208 209 |
# File 'lib/poise/helpers/subresources/child.rb', line 200 def parent_auto(val=nil) unless val.nil? @parent_auto = val end if @parent_auto.nil? Poise::Utils.ancestor_send(self, :parent_auto, default: true) else @parent_auto end end |
#parent_default ⇒ Object, Chef::DelayedEvaluator #parent_default(val) ⇒ Object, Chef::DelayedEvaluator
220 221 222 223 224 225 226 227 228 229 |
# File 'lib/poise/helpers/subresources/child.rb', line 220 def parent_default(*args) unless args.empty? @parent_default = args.first end if defined?(@parent_default) @parent_default else Poise::Utils.ancestor_send(self, :parent_default) end end |
#parent_optional ⇒ Boolean #parent_optional(val) ⇒ Boolean
182 183 184 185 186 187 188 189 190 191 |
# File 'lib/poise/helpers/subresources/child.rb', line 182 def parent_optional(val=nil) unless val.nil? @parent_optional = val end if @parent_optional.nil? Poise::Utils.ancestor_send(self, :parent_optional, default: false) else @parent_optional end end |
#parent_type ⇒ Class, Symbol #parent_type(type) ⇒ Class, Symbol
164 165 166 167 168 169 170 171 172 173 |
# File 'lib/poise/helpers/subresources/child.rb', line 164 def parent_type(type=nil) if type raise Poise::Error.new("Parent type must be a class, symbol, or true, got #{type.inspect}") unless type.is_a?(Class) || type.is_a?(Symbol) || type == true # Setting to true shouldn't actually do anything if a type was already set. @parent_type = type unless type == true && !@parent_type.nil? end # First ancestor_send looks for a non-true && non-default value, # second one is to check for default vs true if no real value is found. @parent_type || Poise::Utils.ancestor_send(self, :parent_type, ignore: [Chef::Resource, true]) || Poise::Utils.ancestor_send(self, :parent_type, default: Chef::Resource) end |