class Puppet::Provider::AixObject::MappedObject
Class
representing a MappedObject
, which can either be an AIX attribute or a Puppet
property. This class lets us write something like:
attribute = mappings[:aix_attribute][:uid] attribute.name attribute.convert_property_value(uid) property = mappings[:puppet_property][:id] property.name property.convert_attribute_value(id)
NOTE: This is an internal class specific to AixObject
. It is not meant to be used anywhere else. That's why we do not have any validation code in here.
NOTE: See the comments in the class-level mappings method to understand what we mean by pure and impure conversion functions.
NOTE: The 'mapping' code, including this class, could possibly be moved to a separate module so that it can be re-used in some of our other providers. See PUP-9082.
Attributes
Public Class Methods
# File lib/puppet/provider/aix_object.rb 30 def initialize(name, conversion_fn, conversion_fn_code) 31 @name = name 32 @conversion_fn = conversion_fn 33 @conversion_fn_code = conversion_fn_code 34 35 return unless pure_conversion_fn? 36 37 # Our conversion function is pure, so we can go ahead 38 # and define it. This way, we can use this MappedObject 39 # at the class-level as well as at the instance-level. 40 define_singleton_method(@conversion_fn) do |value| 41 @conversion_fn_code.call(value) 42 end 43 end
Public Instance Methods
# File lib/puppet/provider/aix_object.rb 45 def pure_conversion_fn? 46 @conversion_fn_code.arity == 1 47 end
Sets our MappedObject's provider. This only makes sense if it has an impure conversion function. We will call this in the instance-level mappings method after the provider instance has been created to define our conversion function. Note that a MappedObject
with an impure conversion function cannot be used at the class level.
# File lib/puppet/provider/aix_object.rb 55 def set_provider(provider) 56 define_singleton_method(@conversion_fn) do |value| 57 @conversion_fn_code.call(provider, value) 58 end 59 end