Sha256: 519d94e2d2b81a582ab7bf62a066e89614f9ae69640bf0e0be81951527262a5a

Contents?: true

Size: 821 Bytes

Versions: 1

Compression:

Stored size: 821 Bytes

Contents

module Middleman
  module LiveReload
    class Wss
      def initialize(certificate, private_key)
        @certificate = certificate
        @private_key = private_key
        validate!
      end

      def valid?
        @certificate && @private_key
      end

      def to_options
        return {} unless valid?
        {
          secure: true,
          tls_options: {
            private_key_file: @private_key,
            cert_chain_file: @certificate
          }
        }
      end

      def scheme
        valid? ? "wss" : "ws"
      end

      private

      def present?
        @certificate || @private_key
      end

      def validate!
        if present? && !valid?
          raise ArgumentError.new, "You must provide both :wss_certificate and :wss_private_key"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
middleman-livereload-3.4.7 lib/middleman-livereload/wss.rb