b0VIM 7.4VuN\roottkmd-116~root/gem_fabric/lib/cookbook_creator/config_loader.rbutf-8 U3210#"! Utpy$zadyP/ | _ 6 . -  i E  f  ~ } p # Y O N  cWMEDSF;1 x8.Ymc[Z@2*)ub& message << "You have invalid ruby syntax in your config file #{config_file_path}\n\n" message = "" rescue SyntaxError => e raise rescue SignalException Config.from_string(config_content, config_file_path) def read_config(config_content, config_file_path) end Dir.pwd def working_directory end end have_config?(candidate_config) candidate_configs.find do | candidate_config | end candidate_configs << File.join(dot_generator_dir, 'generator.rb') PathHelper.home('.generator') do |dot_generator_dir| # Look for $HOME/.generator/generator.rb end candidate_configs << File.join(generator_config_dir, 'generator.rb') if generator_config_dir # Look for $UPWARD/.generator/generator.rb end candidate_configs << File.join(Dir.pwd, 'generator.rb') if Dir.pwd # Look for $PWD/generator.rb end candidate_configs << File.join(env['COOKBOOK_CREATOR_HOME'], 'generator.rb') if env['COOKBOOK_CREATOR_HOME'] # Look for $COOKBOOK_CREATOR_HOME/generator.rb (allow multiple generator config on same machine) candidate_configs = [] def locate_local_config end end false logger.debug("Config not found at #{path}, trying next option") else true logger.info("Using config at #{path}") if path_exists?(path) def have_config?(path) private end Pathname.new(path).expand_path.exist? def path_exists?(path) # (Private API, public for test purposes) end ENV def env # (Private API, public for test purposes) end read_config(IO.read(config_location), config_location) Config.config_file = config_location # Have to set Config.config_file b/c other config is derived from it. end raise "Specified config file #{config_location} does not exist" if explicit_config_file && !path_exists?(config_location) return false if config_location.nil? # default path. # Ignore it if there's no explicit_config_file and can't find one at a def load end @generator_config_dir end end end break @generator_config_dir = candidate_directory if File.exist?(candidate_directory) && File.directory?(candidate_directory) candidate_directory = File.join(full_path[0..i] + [".generator"]) (full_path.length - 1).downto(0) do |i| full_path = working_directory.split(File::SEPARATOR) @generator_config_dir = false if @generator_config_dir.nil? def generator_config_dir end @config_location ||= (explicit_config_file || locate_local_config) def config_location end config_location.nil? def no_config_found? end @logger = logger || NullLogger.new @config_location = nil @generator_config_dir = nil @explicit_config_file = explicit_config_file def initialize(explicit_config_file, logger=nil) attr_accessor :explicit_config_file # Path to a config file requested by user, (e.g., via command line option). Can be nil class ConfigLoadermodule CookbookCreatorrequire 'pathname'require 'cookbook_creator/pathhelper'require 'cookbook_creator/null_logger'## But in order to fit for our needs it was modified# Initially this code block was developed by Chef community.## Copyright:: Copyright (c) 2016 Tacit Knowledge.# Author:: Anicheev Serghei ()#ad2 $Tj7  ' j M \ R    end end end @logger def logger end "Relevant file content:\n" + lines.join("\n") + "\n" end lines = config_file_lines[Range.new(line - 2, line)] else lines = config_file_lines[0..3] if line == 1 IO.readlines(file).each_with_index {|l, i| config_file_lines << "#{(i + 1).to_s.rjust(3)}: #{l.chomp}"} config_file_lines = [] def highlight_config_error(file, line) end raise ChefConfig::ConfigurationError, message end message << highlight_config_error(config_file_path, line_nr.to_i) line_nr = filtered_trace.first[/#{Regexp.escape(config_file_path)}:([\d]+)/, 1] if !filtered_trace.empty? filtered_trace.each {|bt_line| message << " " << bt_line << "\n" } filtered_trace = e.backtrace.grep(/#{Regexp.escape(config_file_path)}/) message << "#{e.class.name}: #{e.message}\n" message = "You have an error in your config file #{config_file_path}\n\n" rescue Exception => e raise ChefConfig::ConfigurationError, message end message << highlight_config_error(config_file_path, line) line = file_line[/:([\d]+)$/, 1].to_i if file_line = e.message[/#{Regexp.escape(config_file_path)}:[\d]+/] message << "#{e.class.name}: #{e.message}\n"