Sha256: b8efc3f1f927ee5093571913b6e4218e6e7aefa0874e6be0900a5eed547f0ba9

Contents?: true

Size: 1.44 KB

Versions: 2

Compression:

Stored size: 1.44 KB

Contents

module GitHubPages
  module HealthCheck
    class Error < StandardError
      DOCUMENTATION_BASE = "https://help.github.com"
      DOCUMENTATION_PATH = "/categories/github-pages-basics/"
      LOCAL_ONLY = false # Error is only used when running locally

      attr_reader :repository, :domain

      def initialize(repository: nil, domain: nil)
        super
        @repository = repository
        @domain     = domain
      end

      def self.inherited(base)
        subclasses << base
      end

      def self.subclasses
        @subclasses ||= []
      end

      def message
        "Something's wrong with your GitHub Pages site."
      end

      # Error message, with get more info URL appended
      def message_with_url
        msg = message.gsub(/\s+/, " ").squeeze(" ").strip
        msg << "." unless msg =~ /\.$/ #add trailing period if not there
        "#{msg} #{more_info}"
      end
      alias_method :message_formatted, :message_with_url

      def to_s
        "#{message_with_url} (#{self.class.name.split('::').last})".gsub("\n", " ").squeeze(" ").strip
      end

      private

      def username
        if repository.nil?
          "[YOUR USERNAME]"
        else
          repository.owner
        end
      end

      def more_info
        "For more information, see #{documentation_url}."
      end

      def documentation_url
        URI.join(Error::DOCUMENTATION_BASE, self.class::DOCUMENTATION_PATH).to_s
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
github-pages-health-check-1.3.0 lib/github-pages-health-check/error.rb
github-pages-health-check-1.2.0 lib/github-pages-health-check/error.rb