Sha256: 82d929d7b7bf6fc6916404cf374cf3c38c33066091250d64655d2bef212f7b37

Contents?: true

Size: 761 Bytes

Versions: 2

Compression:

Stored size: 761 Bytes

Contents

# frozen_string_literal: true

require "rack/ecg/check"

module Rack
  class ECG
    class CheckFactory
      CheckDefinition = Struct.new(:check_class, :parameters)

      def initialize(definitions, default_checks = [])
        definitions = Array(definitions) | default_checks

        @checks = definitions.map do |check_name, check_parameters|
          CheckDefinition.new(CheckRegistry.lookup(check_name), check_parameters)
        end
      end

      def build_all
        @checks.map do |check_definition|
          build(check_definition.check_class, check_definition.parameters)
        end
      end

      def build(check_class, parameters = nil)
        parameters.nil? ? check_class.new : check_class.new(parameters)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rack-ecg-0.3.0 lib/rack/ecg/check_factory.rb
rack-ecg-0.2.0 lib/rack/ecg/check_factory.rb