CartoDB/cartodb20

View on GitHub
lib/carto/oauth_provider/scopes/scopes_validator.rb

Summary

Maintainability
A
0 mins
Test Coverage
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