Sha256: 3994cead901c2e0b6cb5100af29ddc23d37cc7c096e24a94695bace6585720ae
Contents?: true
Size: 765 Bytes
Versions: 2
Compression:
Stored size: 765 Bytes
Contents
require 'facter' require 'jgrep' module FacterDB def self.get_os_facts(facter_version='*', filter=[]) if filter.is_a?(Array) filter_str = filter.map { |f| f.map { |k,v | "#{k}=#{v}" }.join(' and ') }.join(' or ') elsif filter.is_a?(Hash) filter_str = filter.map { |k,v | "#{k}=#{v}" }.join(' and ') elsif filter.is_a?(String) filter_str = filter else raise 'filter must be either an Array a Hash or a String' end facts_dir = File.expand_path(File.join(File.dirname(__FILE__), '../facts')) jsons = Dir.glob("#{facts_dir}/#{facter_version}/*.facts").map { |f| File.read(f) } json = "[#{jsons.join(',')}]\n" JGrep.jgrep(json, filter_str).map { |hash| Hash[hash.map{ |k, v| [k.to_sym, v] }] } end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
facterdb-0.2.2 | lib/facterdb.rb |
facterdb-0.2.1 | lib/facterdb.rb |