Module: Puppet_X::Elastic

Defined in:
lib/puppet_x/elastic/hash.rb,
lib/puppet_x/elastic/deep_to_i.rb,
lib/puppet_x/elastic/plugin_name.rb,
lib/puppet_x/elastic/deep_implode.rb,
lib/puppet_x/elastic/es_versioning.rb

Defined Under Namespace

Modules: SortedHash Classes: EsVersioning

Class Method Summary collapse

Class Method Details

.deep_implode(hash) ⇒ Object



3
4
5
6
7
# File 'lib/puppet_x/elastic/deep_implode.rb', line 3

def self.deep_implode(hash)
  ret = Hash.new
  implode ret, hash
  ret
end

.deep_to_i(obj) ⇒ Object

This ugly hack is required due to the fact Puppet passes in the puppet-native hash with stringified numerics, which causes the decoded JSON from the Elasticsearch API to be seen as out-of-sync when the parsed template hash is compared against the puppet hash.



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/puppet_x/elastic/deep_to_i.rb', line 7

def self.deep_to_i obj
  if obj.is_a? String and obj =~ /^[0-9]+$/
    obj.to_i
  elsif obj.is_a? Array
    obj.map { |element| deep_to_i(element) }
  elsif obj.is_a? Hash
    obj.merge(obj) { |key, val| deep_to_i(val) }
  else
    obj
  end
end

.implode(new_hash, hash, path = []) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/puppet_x/elastic/deep_implode.rb', line 9

def self.implode(new_hash, hash, path=[])
  hash.sort_by{|k,v| k.length}.reverse.each do |key, value|
    new_path = path + [key]
    case value
    when Hash
      implode(new_hash, value, new_path)
    else
      new_key = new_path.join('.')
      if value.is_a? Array \
          and new_hash.has_key? new_key \
          and new_hash[new_key].is_a? Array
          new_hash[new_key] += value
      else
        new_hash[new_key] ||= value
      end
    end
  end
end

.plugin_name(original_string) ⇒ Object

Attempt to guess at the plugin’s final directory name



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/puppet_x/elastic/plugin_name.rb', line 4

def self.plugin_name(original_string)
  vendor, plugin, _version = original_string.split('/')

  if plugin.nil?
    # Not delineated by slashes; single plugin name in the style of
    # commercial plugins post-2.x
    vendor
  else # strip off potential es prefixes and return the plugin name
    plugin.gsub(/(elasticsearch-|es-)/, '')
  end
end