Class: Puppet::Provider::ElasticYaml
- Inherits:
-
ParsedFile
- Object
- ParsedFile
- Puppet::Provider::ElasticYaml
- Defined in:
- lib/puppet/provider/elastic_yaml.rb
Class Attribute Summary collapse
-
.metadata ⇒ Object
Returns the value of attribute metadata.
Class Method Summary collapse
- .parse(text) ⇒ Object
- .skip_record?(record) ⇒ Boolean
- .to_file(records) ⇒ Object
-
.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.
Class Attribute Details
.metadata ⇒ Object
Returns the value of attribute metadata.
9 10 11 |
# File 'lib/puppet/provider/elastic_yaml.rb', line 9 def @metadata end |
Class Method Details
.parse(text) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puppet/provider/elastic_yaml.rb', line 12 def self.parse text yaml = YAML.load text if yaml yaml.map do |key, | { :name => key, :ensure => :present, @metadata => } end else [] end end |
.skip_record?(record) ⇒ Boolean
44 45 46 |
# File 'lib/puppet/provider/elastic_yaml.rb', line 44 def self.skip_record? record false end |
.to_file(records) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet/provider/elastic_yaml.rb', line 27 def self.to_file records yaml = records.map do |record| # Convert top-level symbols to strings Hash[record.map { |k, v| [k.to_s, v] }] end.inject({}) do |hash, record| # Flatten array of hashes into single hash hash.merge({ record['name'] => record.delete(@metadata.to_s) }) end.extend(Puppet_X::Elastic::SortedHash).to_yaml # Puppet < 4 uses ZAML, which prepends spaces in to_yaml ಠ_ಠ unless Puppet::Util::Package.versioncmp(Puppet.version, '4') >= 0 yaml.gsub!(/^\s{2}/, '') end 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.
51 52 53 |
# File 'lib/puppet/provider/elastic_yaml.rb', line 51 def self.valid_attr?(klass, attr_name) klass.is_a? Class ? klass.parameters.include?(attr_name) : true end |