Module: DiffChecker
- Defined in:
- lib/housing_misc/diff_checker.rb
Overview
DiffChecker module is used to compare diff among application.yml application.yml.sample and default.rb.
Class Method Summary collapse
Class Method Details
.check_diff(deployment_file_path, sample_file_path, default_rb_file) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/housing_misc/diff_checker.rb', line 10 def self.check_diff(deployment_file_path, sample_file_path, default_rb_file) content = YAML.safe_load(File.read(deployment_file_path)) content_sample = YAML.safe_load(File.read(sample_file_path)) raise "#{sample_file_path} cant be empty" if (content_sample.nil? || content_sample.empty?) missing_keys = content.nil? ? content_sample.keys : content_sample.keys - content.keys unless missing_keys.empty? raise "Some keys are missing in application.yml, but present in application.yml.sample. missing_keys : #{missing_keys}" end default_content_type1 = File.readlines(default_rb_file) .map{ |line| line.match(/Figaro.env.[a-z0-9\_\-]+/).to_s.split('.')[2]}.reject{|line| line.nil?} default_content_type2 = File.readlines(default_rb_file) .map{ |line| line.match(/Figaro.env[^\.\s]+/).to_s.match(/[\"\'][a-z]*[^\]]+/) .to_s.gsub!(/\A"|"\Z/, '')}.reject{|line| line.nil?} default_file_keys = default_content_type1 + default_content_type2 missing_keys = content.nil? ? default_file_keys : default_file_keys - content.keys unless missing_keys.empty? raise "Some keys are missing in application.yml, but present in default.rb. missing_keys : #{missing_keys}" end end |