Module: Github::Validations::Presence
- Included in:
- Github::Validations
- Defined in:
- lib/github_api2/validations/presence.rb
Overview
A mixin to help validate presence of non-empty values
Instance Method Summary collapse
-
#assert_presence_of(*args) ⇒ Object
Ensure that essential arguments are present before request is made.
Instance Method Details
#assert_presence_of(*args) ⇒ Object
Ensure that essential 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
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/github_api2/validations/presence.rb', line 19 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 |