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)
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_optional(val = nil) ⇒ Object
- #parent_type(type = nil) ⇒ Object
Instance Method Details
#parent_attribute(name, type: Chef::Resource, optional: false, auto: true)
This method returns an undefined value.
Create a new kind of parent link.
187 188 189 190 191 192 193 |
# File 'lib/poise/helpers/subresources/child.rb', line 187 def parent_attribute(name, type: Chef::Resource, optional: false, auto: true) name = :"parent_#{name}" (@parent_attributes ||= {})[name] = type define_method(name) do |*args| _parent(name, type, optional, auto, *args) end end |
#parent_attributes ⇒ Hash<Symbol, Class>
Return the name of all parent relationships on this class.
199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/poise/helpers/subresources/child.rb', line 199 def parent_attributes {}.tap do |attrs| # Grab superclass's attributes if possible. attrs.update(superclass.parent_attributes) if superclass.respond_to?(:parent_attributes) # 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
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/poise/helpers/subresources/child.rb', line 167 def parent_auto(val=nil) unless val.nil? @parent_auto = val end if @parent_auto.nil? superclass.respond_to?(:parent_auto) ? superclass.parent_auto : true else @parent_auto end end |
#parent_optional ⇒ Boolean #parent_optional(val) ⇒ Boolean
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/poise/helpers/subresources/child.rb', line 149 def parent_optional(val=nil) unless val.nil? @parent_optional = val end if @parent_optional.nil? superclass.respond_to?(:parent_optional) ? superclass.parent_optional : false else @parent_optional end end |
#parent_type ⇒ Class, Symbol #parent_type(type) ⇒ Class, Symbol
134 135 136 137 138 139 140 |
# File 'lib/poise/helpers/subresources/child.rb', line 134 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 @parent_type = type end @parent_type || (superclass.respond_to?(:parent_type) ? superclass.parent_type : Chef::Resource) end |