Sha256: 47662d2d32506c4252fa2c51adcffe7dd73e50e2ce83375a89f05f34bef156aa

Contents?: true

Size: 1.29 KB

Versions: 9

Compression:

Stored size: 1.29 KB

Contents

# encoding: utf-8

module BitBucket
  module Validations
    module Required

      # Validate all keys present in a provided hash against required set,
      # on mismatch raise BitBucket::Error::RequiredParams
      # Note that keys need to be in the same format i.e. symbols or strings,
      # otherwise the comparison will fail.
      #
      def assert_required_keys(required, provided)
        result = required.all? do |key|
          provided.has_deep_key? key
        end
        if !result
          raise BitBucket::Error::RequiredParams.new(provided, required)
        end
        result
      end

      # Validate that required values are not blank
      # the *required are colon separated strings
      # e.g. 'source:branch:name' tests value of params[:source][:branch][:name]
      #
      def assert_required_values_present(params, *required)
        required.each do |encoded_string|
          keys = parse_values(encoded_string)
          value = keys.inject(params) { |params, key| params[key] }
          if value.is_a?(String)
            if value.empty?
              raise BitBucket::Error::BlankValue.new(encoded_string)
            end
          end
        end
      end

      def parse_values(string)
        string.split(':')
      end

    end # Required
  end # Validations
end # BitBucket

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
zz_bitbucket_rest_api-0.1.11 lib/bitbucket_rest_api/validations/required.rb
zz_bitbucket_rest_api-0.1.10 lib/bitbucket_rest_api/validations/required.rb
zz_bitbucket_rest_api-0.1.9 lib/bitbucket_rest_api/validations/required.rb
zz_bitbucket_rest_api-0.1.8 lib/bitbucket_rest_api/validations/required.rb
bitbucket_rest_api2-0.9.5 lib/bitbucket_rest_api/validations/required.rb
bitbucket_rest_api2-0.9.1 lib/bitbucket_rest_api/validations/required.rb
bitbucket_rest_api2-0.2.2 lib/bitbucket_rest_api/validations/required.rb
bitbucket_rest_api2-0.2.1 lib/bitbucket_rest_api/validations/required.rb
bitbucket_rest_api2-0.2.0 lib/bitbucket_rest_api/validations/required.rb