Sha256: ca8970f3be9126558aeac681b523549d3a9f44d7810be416a753a4d22519a6e5

Contents?: true

Size: 684 Bytes

Versions: 1

Compression:

Stored size: 684 Bytes

Contents

# frozen_string_literal: true

module Freno
  class Client
    module Preconditions
      module_function

      PreconditionNotMet = Class.new(ArgumentError)

      class Checker
        attr_reader :errors

        def initialize
          @errors = []
        end

        def present(args = {})
          args.each do |arg, value|
            errors << "#{arg} should be present" unless value
          end
        end

        def report
          raise PreconditionNotMet, errors.join("\n") unless errors.empty?
        end
      end

      def check(&block)
        checker = Checker.new
        checker.instance_eval(&block)
        checker.report
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
freno-client-0.9.0 lib/freno/client/preconditions.rb