Sha256: da2a3fcc8dfdbfb7950c8a092f56ded4b6a38eed56c49c4efcd806ad2b19d735

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module StatusCat

  class Status

    # Returns an array of instances of StatusCat::Checkers::Base subclasses
    def self.all
      StatusCat::Config.instance.enabled.map { |name| factory( name ) }
    end

    # By default, returns all checkers
    # If given a list of checker names, returns an array of those checkers
    # If given a single checker name, just returns that checker
    def self.check( which = :all )
      return all if which == :all
      return factory( which ) unless which.is_a?( Array )
      return which.map { |name| factory( name ) }
    end

    # Emails ::failed list if it is not empty
    def self.cron
      checkers = self.failed
      StatusCat::StatusMailer.failure( checkers ).deliver_now unless checkers.empty?
    end

    # Constructs a checker instance given it's name
    def self.factory( name )
      ( 'StatusCat::Checkers::' + name.to_s.classify ).constantize.new
    end

    # Returns an array of failed instances of ::all
    def self.failed
      self.all.map { |checker| checker.status.nil? ? nil : checker }.compact
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
status_cat-0.1.1 lib/status_cat/status.rb