Sha256: f46d4ef1f0eafc184e545a387e5a53f57f7aa55a0fb3ad457b5a8129188fc459

Contents?: true

Size: 940 Bytes

Versions: 2

Compression:

Stored size: 940 Bytes

Contents

require_relative 'model/config'
require_relative 'model/client'

module DogWatch
  ##
  # Manage the execution of the Dogfile
  ##
  class DogFile
    # @param [String] dogfile
    # @param [String|Object] api_key
    # @param [String|Object] app_key
    # @param [Integer] timeout
    def configure(dogfile, api_key, app_key, timeout)
      @dogfile = dogfile
      @config = DogWatch::Model::Config.new(api_key, app_key, timeout)
    end

    # @param [Proc] block
    def create(&block)
      monitor = instance_eval(IO.read(@dogfile), @dogfile, 1)

      if monitor.is_a?(DogWatch::Monitor)
        monitor.config = @config
        monitor.client

        monitor.get
        monitor.responses.each { |r| block.call(r) }
      else
        klass = Class.new do
          def to_thor
            [:none, 'File does not contain any monitors.', :yellow]
          end
        end

        block.call(klass.new)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dogwatch-1.2.0 lib/dogwatch/dogfile.rb
dogwatch-1.1.1 lib/dogwatch/dogfile.rb