Refactor method to reduce ABC Metric size (#6529)

Merge pull request 6529
This commit is contained in:
ashmaroli 2017-11-08 02:09:58 +05:30 committed by jekyllbot
parent efd9864df6
commit 758ee7ed87
1 changed files with 14 additions and 14 deletions

View File

@ -205,27 +205,22 @@ module Jekyll
# forget to add one of the certificates.
private
# rubocop:disable Metrics/AbcSize
def enable_ssl(opts)
return if !opts[:JekyllOptions]["ssl_cert"] && !opts[:JekyllOptions]["ssl_key"]
if !opts[:JekyllOptions]["ssl_cert"] || !opts[:JekyllOptions]["ssl_key"]
# rubocop:disable Style/RedundantException
raise RuntimeError, "--ssl-cert or --ssl-key missing."
end
cert, key, src =
opts[:JekyllOptions].values_at("ssl_cert", "ssl_key", "source")
return if cert.nil? && key.nil?
raise "Missing --ssl_cert or --ssl_key. Both are required." unless cert && key
require "openssl"
require "webrick/https"
source_key = Jekyll.sanitized_path(opts[:JekyllOptions]["source"], \
opts[:JekyllOptions]["ssl_key" ])
source_certificate = Jekyll.sanitized_path(opts[:JekyllOptions]["source"], \
opts[:JekyllOptions]["ssl_cert"])
opts[:SSLCertificate] =
OpenSSL::X509::Certificate.new(File.read(source_certificate))
opts[:SSLPrivateKey ] = OpenSSL::PKey::RSA.new(File.read(source_key))
opts[:SSLCertificate] = OpenSSL::X509::Certificate.new(read_file(src, cert))
opts[:SSLPrivateKey ] = OpenSSL::PKey::RSA.new(read_file(src, key))
opts[:SSLEnable] = true
end
private
def start_callback(detached)
unless detached
proc do
@ -239,6 +234,11 @@ module Jekyll
file = File.expand_path("../mime.types", __dir__)
WEBrick::HTTPUtils.load_mime_types(file)
end
private
def read_file(source_dir, file_path)
File.read(Jekyll.sanitized_path(source_dir, file_path))
end
end
end
end