Method: Chef::Mixin::Properties::ClassMethods#property
- Defined in:
- lib/chef/mixin/properties.rb
#property(name, type = NOT_PASSED, **options) ⇒ Object Also known as: attribute
Create a property on this resource class.
If a superclass has this property, or if this property has already been defined by this resource, this will override the previous value.
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/chef/mixin/properties.rb', line 100 def property(name, type = NOT_PASSED, **) name = name.to_sym = .inject({}) { |memo, (key, value)| memo[key.to_sym] = value; memo } [:instance_variable_name] = :"@#{name}" unless .key?(:instance_variable_name) [:name] = name [:declared_in] = self if type == NOT_PASSED # If a type is not passed, the property derives from the # superclass property (if any) if properties.key?(name) property = properties[name].derive(**) else property = property_type(**) end # If a Property is specified, derive a new one from that. elsif type.is_a?(Property) || (type.is_a?(Class) && type <= Property) property = type.derive(**) # If a primitive type was passed, combine it with "is" else if [:is] [:is] = ([ type ] + [ [:is] ]).flatten(1) else [:is] = type end property = property_type(**) end local_properties = properties(false) local_properties[name] = property property.emit_dsl end |