Sha256: 25b57f9806e9b9114b249cb4af4a4a98a8d8ecde5503e6d1fe4bbf2c0cb48143

Contents?: true

Size: 1.24 KB

Versions: 28

Compression:

Stored size: 1.24 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
        @to_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(state = nil)
        require "json"
        to_hash.to_json(state)
      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

28 entries across 28 versions & 1 rubygems

Version Path
github-pages-health-check-1.18.5 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.18.4 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.18.2 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.18.1 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.18.0 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.17.9 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.17.8 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.17.7 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.17.6 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.17.2 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.17.1 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.17.0 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.16.1 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.16.0 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.15.0 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.14.0 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.13.0 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.12.0 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.11.1 lib/github-pages-health-check/checkable.rb
github-pages-health-check-1.11.0 lib/github-pages-health-check/checkable.rb