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.
181 182 183 184 185 186 187 |
# File 'lib/poise/helpers/subresources/child.rb', line 181 def parent_attribute(name, type: Chef::Resource, optional: false, auto: true) name = :"parent_#{name}" (@parent_attributes ||= {})[name] = type define_method(name) do |val=nil| _parent(name, type, optional, auto, val) end end |
#parent_attributes ⇒ Hash<Symbol, Class>
Return the name of all parent relationships on this class.
193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/poise/helpers/subresources/child.rb', line 193 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
161 162 163 164 165 166 167 168 169 170 |
# File 'lib/poise/helpers/subresources/child.rb', line 161 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
143 144 145 146 147 148 149 150 151 152 |
# File 'lib/poise/helpers/subresources/child.rb', line 143 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
128 129 130 131 132 133 134 |
# File 'lib/poise/helpers/subresources/child.rb', line 128 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 |