class Govuk::Diff::Pages::WraithConfigGenerator
Public Class Methods
new()
click to toggle source
# File lib/govuk/diff/pages/wraith_config_generator.rb, line 8 def initialize @config = AppConfig.new unless File.exist?(Govuk::Diff::Pages.govuk_pages_file) raise "Cannot find file #{Govuk::Diff::Pages.govuk_pages_file}: run 'rake update_page_list' to generate." end @govuk_pages = YAML.load_file(Govuk::Diff::Pages.govuk_pages_file) @url_checker = UrlChecker.new(@config) puts "Generating wraith.yaml" if verbose? validate_hard_coded_pages end
Public Instance Methods
run()
click to toggle source
# File lib/govuk/diff/pages/wraith_config_generator.rb, line 19 def run @wraith_config = @config.wraith.to_h @wraith_config['paths'] = generate_path_list @wraith_config['domains'] = @config.domains.to_h @wraith_config['browser'] = { 'phantomjs' => 'phantomjs' } @wraith_config['phantomjs_options'] = "--ssl-protocol=tlsv1 --ignore-ssl-errors=true" end
save()
click to toggle source
# File lib/govuk/diff/pages/wraith_config_generator.rb, line 27 def save File.open(Govuk::Diff::Pages.wraith_config_file, 'w') do |fp| fp.puts YAML.dump(@wraith_config) end end
verbose?()
click to toggle source
# File lib/govuk/diff/pages/wraith_config_generator.rb, line 33 def verbose? @config.verbose end
Private Instance Methods
generate_path_list()
click to toggle source
# File lib/govuk/diff/pages/wraith_config_generator.rb, line 52 def generate_path_list paths = generate_paths_from_govuk_pages_file paths.merge(@config.hard_coded_pages.to_h) end
generate_paths_from_govuk_pages_file()
click to toggle source
# File lib/govuk/diff/pages/wraith_config_generator.rb, line 57 def generate_paths_from_govuk_pages_file paths = {} @govuk_pages.each do |path| next unless @url_checker.valid?(path) normalized_path = @url_checker.normalize(path) paths[keyify_path(normalized_path)] = normalized_path end paths end
keyify_path(path)
click to toggle source
# File lib/govuk/diff/pages/wraith_config_generator.rb, line 71 def keyify_path(path) key = path.sub(/^\//, '').tr("/", "_") # YAML DUMP doesn't work with very long keys key = SecureRandom.uuid if key.size > 100 key end
normalize_path(path)
click to toggle source
# File lib/govuk/diff/pages/wraith_config_generator.rb, line 67 def normalize_path(path) path.sub(/^#{@config.domains.production}/, '') end
print_errors_and_exit(errors)
click to toggle source
# File lib/govuk/diff/pages/wraith_config_generator.rb, line 48 def print_errors_and_exit(errors) raise ArgumentError.new %[Invalid config:\n #{errors.join("\n ")}] end
validate_hard_coded_pages()
click to toggle source
# File lib/govuk/diff/pages/wraith_config_generator.rb, line 39 def validate_hard_coded_pages errors = [] @config.hard_coded_pages.to_h.each do |_key, url| next if @url_checker.valid?(url) errors << "ERROR: Invalid url specified in hard coded pages: '#{url}'" end print_errors_and_exit(errors) unless errors.empty? end