Sha256: c17a6c1843712e5e17f8450c3242fa8d544086804c5c3a77421482f2f461f712

Contents?: true

Size: 847 Bytes

Versions: 5

Compression:

Stored size: 847 Bytes

Contents

# encoding: utf-8

module BitBucket
  module Validations
    # A mixin to help validate presence of non-empty values
    module Presence

      # Ensure that esential arguments are present before request is made.
      #
      # == Parameters
      #  Hash/Array of arguments to be checked against nil and empty string
      #
      # == Example
      #  assert_presence_of user: '...', repo: '...'
      #  assert_presence_of user, repo
      #
      def assert_presence_of(*args)
        hash = args.last.is_a?(::Hash) ? args.pop : {}

        errors = hash.select { |key, val| val.to_s.empty? }
        raise Github::Error::Validations.new(errors) unless errors.empty?

        args.each do |arg|
          raise ArgumentError, "parameter cannot be nil" if arg.nil?
        end
      end

    end # Presence
  end # Validations
end # BitBucket

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
codenamev_bitbucket_api-0.4.1 lib/bitbucket_rest_api/validations/presence.rb
codenamev_bitbucket_api-0.4.0 lib/bitbucket_rest_api/validations/presence.rb
reenhanced_bitbucket_api-0.3.2 lib/bitbucket_rest_api/validations/presence.rb
reenhanced_bitbucket_api-0.3.1 lib/bitbucket_rest_api/validations/presence.rb
reenhanced_bitbucket_api-0.3.0 lib/bitbucket_rest_api/validations/presence.rb