Class: Puppet::Provider::ElasticYaml

Inherits:
ElasticParsedFile
  • Object
show all
Defined in:
lib/puppet/provider/elastic_yaml.rb

Overview

Provider for yaml-based Elasticsearch configuration files.

Direct Known Subclasses

ElasticUserRoles

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.metadataObject

Returns the value of attribute metadata.



12
13
14
# File 'lib/puppet/provider/elastic_yaml.rb', line 12

def 
  @metadata
end

Class Method Details

.parse(text) ⇒ Object

Transform a given string into a Hash-based representation of the provider.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/puppet/provider/elastic_yaml.rb', line 17

def self.parse(text)
  yaml = YAML.safe_load text
  if yaml
    yaml.map do |key, |
      {
        :name => key,
        :ensure => :present,
        @metadata => 
      }
    end
  else
    []
  end
end

.skip_record?(_record) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/puppet/provider/elastic_yaml.rb', line 51

def self.skip_record?(_record)
  false
end

.to_file(records) ⇒ Object

Transform a given list of provider records into yaml-based representation.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/puppet/provider/elastic_yaml.rb', line 34

def self.to_file(records)
  yaml = records.map do |record|
    # Convert top-level symbols to strings
    record.transform_keys(&:to_s)
  end
  yaml = yaml.reduce({}) do |hash, record|
    # Flatten array of hashes into single hash
    hash.merge(record['name'] => record.delete(@metadata.to_s))
  end
  yaml = yaml.extend(Puppet_X::Elastic::SortedHash).to_yaml.split("\n")

  yaml.shift if yaml.first =~ %r{---}
  yaml = yaml.join("\n")

  yaml << "\n"
end

.valid_attr?(klass, attr_name) ⇒ Boolean

This is ugly, but it’s overridden in ParsedFile with abstract functionality we don’t need for our simple provider class. This has been observed to break in Puppet version 3/4 switches.

Returns:

  • (Boolean)


58
59
60
# File 'lib/puppet/provider/elastic_yaml.rb', line 58

def self.valid_attr?(klass, attr_name)
  klass.is_a? Class ? klass.parameters.include?(attr_name) : true
end