Sha256: 5318ae67921576b032b4759ef4d87e4195572f7049c311aca6c5a4b14cdc72db

Contents?: true

Size: 683 Bytes

Versions: 6

Compression:

Stored size: 683 Bytes

Contents

module Freno
  class Client
    module Preconditions
      extend self

      PreconditionNotMet = Class.new(ArgumentError)

      class Checker
        attr_reader :errors

        def initialize
          @errors = []
        end

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

        def report
          raise PreconditionNotMet.new(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

6 entries across 6 versions & 1 rubygems

Version Path
freno-client-0.8.1 lib/freno/client/preconditions.rb
freno-client-0.8.0 lib/freno/client/preconditions.rb
freno-client-0.7.0 lib/freno/client/preconditions.rb
freno-client-0.6.0 lib/freno/client/preconditions.rb
freno-client-0.4.0 lib/freno/client/preconditions.rb
freno-client-0.3.0 lib/freno/client/preconditions.rb