Sha256: 2ea02d5f27a6cd47aa05d5b3cf58a4a30190b85a8f14c10142a75ee50b244342

Contents?: true

Size: 883 Bytes

Versions: 3

Compression:

Stored size: 883 Bytes

Contents

# encoding: utf-8

require_relative '../error/client_error'

module Github
  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 # Github

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
lingfennan-github_api-0.18.2 lib/github_api/validations/presence.rb
github_api-0.18.2 lib/github_api/validations/presence.rb
github_api-0.18.1 lib/github_api/validations/presence.rb