Sha256: c20836df6f7f316c07b34d69acdb22a3f8a8bfb1b93bbba2db028e493b629ef4

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module GitHubPages
  module HealthCheck
    class Checkable
      # Array of symbolized methods to be included in the output hash
      HASH_METHODS = [].freeze

      def check!
        raise "Not implemented"
      end
      alias valid! check!

      # Runs all checks, returns true if valid, otherwise false
      def valid?
        check!
        true
      rescue GitHubPages::HealthCheck::Error
        false
      end

      # Returns the reason the check failed, if any
      def reason
        check!
        nil
      rescue GitHubPages::HealthCheck::Error => e
        e
      end

      def to_hash
        @hash ||= begin
          hash = {}
          self.class::HASH_METHODS.each do |method|
            hash[method] = public_send(method)
          end
          hash
        end
      end
      alias [] to_hash
      alias to_h to_hash

      def to_json
        require "json"
        to_hash.to_json
      end

      def to_s
        printer.simple_string
      end

      def to_s_pretty
        printer.pretty_print
      end
      alias pretty_print to_s_pretty

      private

      def printer
        @printer ||= GitHubPages::HealthCheck::Printer.new(self)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
github-pages-health-check-1.3.6 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.4.0 lib/github-pages-health-check/checkable.rb