Sha256: 9824a735c8deea5a3ffec8730c708b4fd9e60952ddabec2c8b7af23dd3bb3686

Contents?: true

Size: 841 Bytes

Versions: 45

Compression:

Stored size: 841 Bytes

Contents

# encoding: utf-8

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

45 entries across 45 versions & 1 rubygems

Version Path
github_api-0.17.0 lib/github_api/validations/presence.rb
github_api-0.16.0 lib/github_api/validations/presence.rb
github_api-0.15.0 lib/github_api/validations/presence.rb
github_api-0.14.5 lib/github_api/validations/presence.rb
github_api-0.14.4 lib/github_api/validations/presence.rb
github_api-0.14.3 lib/github_api/validations/presence.rb
github_api-0.14.2 lib/github_api/validations/presence.rb
github_api-0.14.1 lib/github_api/validations/presence.rb
github_api-0.14.0 lib/github_api/validations/presence.rb
github_api-0.13.1 lib/github_api/validations/presence.rb
github_api-0.13.0 lib/github_api/validations/presence.rb
github_api-0.12.4 lib/github_api/validations/presence.rb
github_api-0.12.3 lib/github_api/validations/presence.rb
github_api-0.12.2 lib/github_api/validations/presence.rb
github_api-0.12.1 lib/github_api/validations/presence.rb
github_api-0.12.0 lib/github_api/validations/presence.rb
github_api-0.11.3 lib/github_api/validations/presence.rb
github_api-0.11.2 lib/github_api/validations/presence.rb
github_api-0.11.1 lib/github_api/validations/presence.rb
github_api-0.11.0 lib/github_api/validations/presence.rb