File: multiple_namevar.rb

package info (click to toggle)
ruby-puppet-resource-api 1.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,232 kB
  • sloc: ruby: 9,573; sh: 4; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,235 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
require 'puppet/resource_api'

# Implementation for the title_provider type using the Resource API.
class Puppet::Provider::MultipleNamevar::MultipleNamevar
  def initialize
    @current_values ||= [
      { title: 'php-yum', package: 'php', manager: 'yum', ensure: 'present' },
      { title: 'php-gem', package: 'php', manager: 'gem', ensure: 'present' },
      { title: 'mysql-yum', package: 'mysql', manager: 'yum', ensure: 'present' },
      { title: 'mysql-gem', package: 'mysql', manager: 'gem', ensure: 'present' },
      { title: 'foo-bar', package: 'foo', manager: 'bar', ensure: 'present' },
      { title: 'bar-foo', package: 'bar', manager: 'foo', ensure: 'present' },
    ]
  end

  def set(context, changes)
    changes.each do |name, change|
      next unless change[:is] != change[:should]

      match = @current_values.find do |item|
        context.type.namevars.all? do |namevar|
          item[namevar] == change[:should][namevar]
        end
      end
      if match
        match[:ensure] = change[:should][:ensure]
      else
        context.created([name], message: 'Adding new record')
        @current_values << change[:should].dup
      end
    end
  end

  def get(_context)
    @current_values
  end
end