Module: BitBucket::Validations::Required
- Included in:
- BitBucket::Validations
- Defined in:
- lib/bitbucket_rest_api/validations/required.rb
Instance Method Summary collapse
-
#assert_required_keys(required, provided) ⇒ Object
Validate all keys present in a provided hash against required set, on mismatch raise BitBucket::Error::RequiredParams Note that keys need to be in the same format i.e.
-
#assert_required_values_present(params, *required) ⇒ Object
Validate that required values are not blank the *required are colon separated strings e.g.
- #parse_values(string) ⇒ Object
Instance Method Details
#assert_required_keys(required, provided) ⇒ Object
Validate all keys present in a provided hash against required set, on mismatch raise BitBucket::Error::RequiredParams Note that keys need to be in the same format i.e. symbols or strings, otherwise the comparison will fail.
10 11 12 13 14 15 16 17 |
# File 'lib/bitbucket_rest_api/validations/required.rb', line 10 def assert_required_keys(required, provided) result = required.all? do |key| provided.has_deep_key? key end raise BitBucket::Error::RequiredParams.new(provided, required) unless result result end |
#assert_required_values_present(params, *required) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/bitbucket_rest_api/validations/required.rb', line 23 def assert_required_values_present(params, *required) required.each do |encoded_string| keys = parse_values(encoded_string) value = keys.inject(params) { |params, key| params[key] } next unless value.is_a?(String) raise BitBucket::Error::BlankValue, encoded_string if value.empty? end end |
#parse_values(string) ⇒ Object
32 33 34 |
# File 'lib/bitbucket_rest_api/validations/required.rb', line 32 def parse_values(string) string.split(':') end |