Sha256: 030727047d347ec58177d31cd912ee60b28832da9f4f9bda76a6b833b9d591bf

Contents?: true

Size: 799 Bytes

Versions: 11

Compression:

Stored size: 799 Bytes

Contents

module Gameball
  module Utils
    extend self

    def validate(hash, required, optional) # Method used to validate body parameters by checking optional fields and required fields
      errors = []
      # Loop on required fields and throw error if field is not in ruby hash
      required.each do |val|
        raise Gameball::GameballError.new("Required key: #{val.to_sym.inspect}") unless hash.has_key?(val.to_sym)
      end
      allowed = optional + required
      # Loop on each field in ruby hash and check if it is allowed
      hash.each_key do |val|
        unless allowed.include?(val.to_s)
          raise Gameball::GameballError.new("Unknown key: #{val.to_sym.inspect}. Valid keys are: #{allowed.map(&:inspect).join(", ")}")
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
gameball-3.1.5 lib/gameball/utils/validation.rb
gameball-3.1.4 lib/gameball/utils/validation.rb
gameball-2.1.4 lib/gameball/utils/validation.rb
gameball-2.1.3 lib/gameball/utils/validation.rb
gameball-2.1.1 lib/gameball/utils/validation.rb
gameball-2.0.1 lib/gameball/utils/validation.rb
gameball-2.0.0 lib/gameball/utils/validation.rb
gameball-1.0.1 lib/gameball/utils/validation.rb
gameball-1.0.0 lib/gameball/utils/validation.rb
alphaSDK-0.2.8 lib/gameball/utils/validation.rb
alphaSDK-0.2.7 lib/gameball/utils/validation.rb