forked from piotrmurach/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.rb
More file actions
24 lines (20 loc) · 736 Bytes
/
Copy pathformat.rb
File metadata and controls
24 lines (20 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# encoding: utf-8
module Github
module Validations
module Format
# Ensures that value for a given key is of the correct form whether
# matching regular expression or set of predefined values.
#
def assert_valid_values(permitted, params)
params.each do |k, v|
next unless permitted.keys.include?(k)
if permitted[k].is_a?(Array) && !permitted[k].include?(params[k])
raise Github::Error::UnknownValue.new(k,v, permitted[k].join(', '))
elsif permitted[k].is_a?(Regexp) && !(permitted[k] =~ params[k])
raise Github::Error::UnknownValue.new(k,v, permitted[k])
end
end
end
end # Format
end # Validations
end # Github