class AchFlattenMeta::FlattenMeta
Public Class Methods
new( os_version, node_environment, confhash)
click to toggle source
First create a simple and flattened hash with k => { value, prio }
This can be iterated over using each method provided
# File lib/ach_flattenmeta/flattenmeta.rb, line 8 def initialize( os_version, node_environment, confhash) @flatconf = Hash.new() @os_version = os_version @node_environment = node_environment @confhash = confhash end
Public Instance Methods
each() { |k, v| ... }
click to toggle source
# File lib/ach_flattenmeta/flattenmeta.rb, line 15 def each filter() @flatconf.each { |k,v | yield k, v['value'] if v['active'] } end
Private Instance Methods
filter()
click to toggle source
# File lib/ach_flattenmeta/flattenmeta.rb, line 21 def filter() @confhash.each do | location, data| # Do some basic sanity checks on the config hash passed raise ArgumentError, 'environments is not an Array' unless data['metadata']['environments'].kind_of?(Array) raise ArgumentError, 'platforms is not an Array' unless data['metadata']['platforms'].kind_of?(Array) raise ArgumentError, 'priority is not an Integer' unless data['metadata']['priority'].is_a? Integer raise ArgumentError, 'active is not a Boolean' unless data['metadata']['active'].is_a? TrueClass or data['metadata']['active'].is_a? FalseClass if(data['metadata']['environments'] & [@node_environment, 'all']).any? && (data['metadata']['platforms'] & [@os_version, 'all']).any? prio = data['metadata']['priority'] active = data['metadata']['active'] data.each do | k, v | next if k == 'metadata' if @flatconf.key?(k) @flatconf[k] = { 'value' => v, 'priority' => prio, 'active' => active } if @flatconf[k]['priority'] > prio else @flatconf[k] = { 'value' => v, 'priority' => prio, 'active' => active } end # if 'metadata' end #data.each end # if any? end # @confhas.each end