3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/tamplier/validator.rb', line 3
def ensure(root, environment = nil)
Iterator.new.call(root) do |sample_file, config_file|
raise ConfigurationException.new("Configuration file #{config_file} does not exist, but sample file #{sample_file} does.") unless config_file.exist?
if environmental_file?(sample_file)
raise ConfigurationException.new("There is no #{environment} environment in the #{config_file} file.") unless YAML.load(config_file.read)[environment].present?
end
sample_config = YAML.load(sample_file.read)
real_config = YAML.load(config_file.read)
diff = environmental_file?(sample_file) ?
flat_keys(sample_config['development']) - flat_keys(real_config[environment]) :
flat_keys(sample_config) - flat_keys(real_config)
raise ConfigurationException.new("Several keys #{diff.inspect} from #{sample_file} are not in #{config_file} file.") unless diff.empty?
end
end
|