Module: EasyType::Provider::ClassMethods

Defined in:
lib/easy_type/provider.rb

Instance Method Summary (collapse)

Instance Method Details

- (Array) instances

Retrieve the raw_resource information by calling the`get_raw_resources` method on the Type. Map every element of this Array to a Puppet resource. and return this mapped Array

Returns:

  • (Array) —

    Mapped Array of resources

Raises:

  • (Puppet::Error) —

    When `get_raw_resources` is not defined on the type.



160
161
162
163
164
165
166
# File 'lib/easy_type/provider.rb', line 160

def instances
  fail("information: to_get_raw_resources not defined on type #{resource_type.name}") unless defined?(resource_type.get_raw_resources)
  raw_resources = resource_type.get_raw_resources
  raw_resources.collect do |raw_resource|
    map_raw_to_resource(raw_resource)
  end
end

- (Object) mk_resource_methods

define a getter and a setter method for evert specified parameter and property in the type. Define the setter so it modifies the property_hash and the property_flush based on what the other provider methods expect.

Raises:

  • (Puppet::Error)


136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/easy_type/provider.rb', line 136

def mk_resource_methods
  attributes = [resource_type.validproperties, resource_type.parameters].flatten
  raise Puppet::Error, 'no parameters or properties defined. Probably an error' if attributes == [:provider]
  attributes.each do |attr|
    attr = attr.intern
    next if attr == :name
    define_method(attr) do
      @property_hash[attr] || :absent
    end

    define_method(attr.to_s + "=") do |value|
      @property_flush[attr] = value
    end
  end
end

- (Array) prefetch(resources)

Prefetch all information of the specified resource. Because we already have everything in the inatnces array, we just have to set the provider

Returns:

  • (Array) —

    of Puppet Resources



175
176
177
178
179
180
181
182
# File 'lib/easy_type/provider.rb', line 175

def prefetch(resources)
  objects = instances
  resources.keys.each do |name|
    if provider = objects.find{ |object| object.name == name } 
      resources[name].provider = provider
    end
  end
end