Sha256: d87f57649cc880bda36cf066b27abab5c9c616641c9e7054b1009c6ba0fe85eb
Contents?: true
Size: 737 Bytes
Versions: 1
Compression:
Stored size: 737 Bytes
Contents
module ForemanAnsible class FactSparser class << self def sparse(hash, options = {} ) hash.map do |k, v| prefix = options.fetch(:prefix, []) + [k] next sparse(v, options.merge(:prefix => prefix)) if v.is_a? Hash { prefix.join(options.fetch(:separator, FactName::SEPARATOR)) => v } end.reduce(:merge) || Hash.new end def unsparse(hash, options={}) ret = Hash.new sparse(hash).each do |k, v| current = ret key = k.to_s.split(options.fetch(:separator, FactName::SEPARATOR)) current = (current[key.shift] ||= Hash.new) until key.size <= 1 current[key.first] = v end ret end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
foreman_ansible-0.2.1 | app/services/foreman_ansible/fact_sparser.rb |