Module: Nimbu::Request::Validations::Presence

Included in:
Nimbu::Request::Validations
Defined in:
lib/nimbu-api/request/validations/presence.rb

Overview

A mixin to help validate presence of non-empty values

Instance Method Summary collapse

Instance Method Details

#assert_presence_of(*args) ⇒ Object

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


18
19
20
21
22
23
24
25
26
27
# File 'lib/nimbu-api/request/validations/presence.rb', line 18

def assert_presence_of(*args)
  hash = args.last.is_a?(::Hash) ? args.pop : {}

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

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