/usr/lib/ruby/vendor_ruby/cheffish/merged_config.rb is in ruby-cheffish 4.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | module Cheffish
class MergedConfig
def initialize(*configs)
@configs = configs
@merge_arrays = {}
end
include Enumerable
attr_reader :configs
def merge_arrays(*symbols)
if symbols.size > 0
symbols.each do |symbol|
@merge_arrays[symbol] = true
end
else
@merge_arrays
end
end
def [](name)
if @merge_arrays[name]
configs.select { |c| !c[name].nil? }.collect_concat { |c| c[name] }
else
result_configs = []
configs.each do |config|
value = config[name]
if !value.nil?
if value.respond_to?(:keys)
result_configs << value
elsif result_configs.size > 0
return result_configs[0]
else
return value
end
end
end
if result_configs.size > 1
MergedConfig.new(*result_configs)
elsif result_configs.size == 1
result_configs[0]
else
nil
end
end
end
def method_missing(name, *args)
if args.count > 0
raise NoMethodError, "Unexpected method #{name} for MergedConfig with arguments #{args}"
else
self[name]
end
end
def key?(name)
configs.any? { |config| config.has_key?(name) }
end
alias_method :has_key?, :key?
def keys
configs.map { |c| c.keys }.flatten(1).uniq
end
def values
keys.map { |key| self[key] }
end
def each_pair(&block)
each(&block)
end
def each
keys.each do |key|
if block_given?
yield key, self[key]
end
end
end
def to_hash
result = {}
each_pair do |key, value|
result[key] = value
end
result
end
def to_h
to_hash
end
def to_s
to_hash.to_s
end
end
end
|