class GraphqlConnector::ServiceClassable::ReturnFieldsValidator
Valdations for return fields set within the context of a service class
Public Class Methods
validate(return_fields)
click to toggle source
# File lib/graphql_connector/service_classable/return_fields_validator.rb, line 9 def validate(return_fields) unless return_fields.is_a?(Array) raise ReturnFieldsErrors, 'Please ensure that returns is followed '\ 'by an array. E.g. returns: [:id]' end return_fields.each { |entry| recursive_validation(entry) } end
Private Class Methods
hash_validation(hash)
click to toggle source
# File lib/graphql_connector/service_classable/return_fields_validator.rb, line 34 def hash_validation(hash) hash.each do |key, value| recursive_validation(key) recursive_validation(value) end end
recursive_validation(entry)
click to toggle source
# File lib/graphql_connector/service_classable/return_fields_validator.rb, line 20 def recursive_validation(entry) case entry when Hash hash_validation(entry) when Array entry.each { |item| recursive_validation(item) } else return if [String, Symbol].member?(entry.class) raise ReturnFieldsErrors, "The #{entry} is neither a String nor a"\ 'Symbol!' end end