Module: EasyType::Provider::ClassMethods

Defined in:
lib/easy_type/provider.rb

Overview

nodoc

Instance Method Summary collapse

Instance Method Details

#instancesArray

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

rubocop:disable LineLength

Returns:

  • (Array)

    Mapped Array of resources

Raises:

  • (Puppet::Error)

    When ‘get_raw_resources` is not defined on the type.



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

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.map do |raw_resource|
    map_raw_to_resource(raw_resource)
  end
end

#mk_resource_methodsObject

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.



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/easy_type/provider.rb', line 151

def mk_resource_methods
  attributes = [resource_type.validproperties, resource_type.parameters].flatten
  fail 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

#prefetch(resources) ⇒ Array

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

rubocop:disable IfUnlessModifier

Returns:

  • (Array)

    of Puppet Resources



192
193
194
195
196
197
198
# File 'lib/easy_type/provider.rb', line 192

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