cartodb-4.29/lib/carto/oauth_provider/scopes/scopes_validator.rb

15 lines
475 B
Ruby
Raw Normal View History

2020-06-15 10:58:47 +08:00
module Carto
module OauthProvider
module Scopes
class ScopesValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return record.errors[attribute] = ['has to be an array'] unless value&.is_a?(Array)
invalid_scopes = Scopes.invalid_scopes(value)
record.errors[attribute] << "contains unsupported scopes: #{invalid_scopes.join(', ')}" if invalid_scopes.any?
end
end
end
end
end