Module: Puppet_X::Elastic
- Defined in:
- lib/puppet_x/elastic/hash.rb,
lib/puppet_x/elastic/deep_to_i.rb,
lib/puppet_x/elastic/deep_implode.rb,
lib/puppet_x/elastic/es_versioning.rb,
lib/puppet_x/elastic/plugin_parsing.rb
Overview
Elastic helpers
Defined Under Namespace
Modules: SortedHash Classes: EsVersioning
Class Method Summary collapse
-
.deep_implode(hash) ⇒ Object
Recursively implode a hash into dot-delimited structure of Hash keys/values.
-
.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.
-
.implode(new_hash, hash, path = []) ⇒ Object
Recursively descend into hash values, flattening the key structure into dot-delimited keyed Hash.
- .plugin_name(raw_name) ⇒ Object
-
.plugin_split(original_string, position) ⇒ Object
Attempt to guess at the plugin’s final directory name.
Class Method Details
.deep_implode(hash) ⇒ Object
Recursively implode a hash into dot-delimited structure of Hash keys/values.
5 6 7 8 9 |
# File 'lib/puppet_x/elastic/deep_implode.rb', line 5 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
Recursively descend into hash values, flattening the key structure into dot-delimited keyed Hash.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/puppet_x/elastic/deep_implode.rb', line 13 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(raw_name) ⇒ Object
3 4 5 |
# File 'lib/puppet_x/elastic/plugin_parsing.rb', line 3 def self.plugin_name(raw_name) plugin_split(raw_name, 1) end |
.plugin_split(original_string, position) ⇒ Object
Attempt to guess at the plugin’s final directory name
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/puppet_x/elastic/plugin_parsing.rb', line 8 def self.plugin_split(original_string, position) # Try both colon (maven) and slash-delimited (github/elastic.co) names %w[/ :].each do |delimiter| parts = original_string.split(delimiter) # If the string successfully split, assume we found the right format return parts[position].gsub(/(elasticsearch-|es-)/, '') unless parts[position].nil? end # Fallback to the originally passed plugin name original_string end |