class Cookiefilter::Validator
Public Class Methods
validate_array(err, list)
click to toggle source
# File lib/cookiefilter/validator.rb, line 19 def validate_array(err, list) raise err, 'safelist method does not return Array' if list.class != Array end
validate_description(err, index, obj)
click to toggle source
# File lib/cookiefilter/validator.rb, line 37 def validate_description(err, index, obj) description = obj[:description] if description.class != String return raise err, "safelist child with index #{index}: ':description' \ must be of class String, got #{description.class}" end end
validate_hash(err, index, obj)
click to toggle source
# File lib/cookiefilter/validator.rb, line 23 def validate_hash(err, index, obj) if obj.class != Hash raise err, "safelist child with index #{index}: Is not an Hash Object" end end
validate_key(err, index, obj)
click to toggle source
# File lib/cookiefilter/validator.rb, line 45 def validate_key(err, index, obj) key = obj[:key] if key.class != Regexp return raise err, "safelist child with index #{index}: ':key' \ must be of class Regexp, got #{key.class}" end end
validate_keys(err, index, obj)
click to toggle source
# File lib/cookiefilter/validator.rb, line 29 def validate_keys(err, index, obj) %w(description key value sacred).each do |key| unless obj.has_key?(key.to_sym) raise err, "safelist child with index #{index}: Missing key :#{key}" end end end
validate_sacred(err, index, obj)
click to toggle source
# File lib/cookiefilter/validator.rb, line 61 def validate_sacred(err, index, obj) sacred = obj[:sacred] if obj[:sacred].class != TrueClass && obj[:sacred].class != FalseClass return raise err, "safelist child with index #{index}: ':sacred' \ must be of class TrueClass or FalseClass, got #{sacred.class}" end end
validate_safelist(safelist)
click to toggle source
# File lib/cookiefilter/validator.rb, line 3 def validate_safelist(safelist) err = Cookiefilter::MalformedSafelistError Cookiefilter::Validator.validate_array(err, safelist) safelist.each_index do |index| obj = safelist[index] Cookiefilter::Validator.validate_hash(err, index, obj) Cookiefilter::Validator.validate_keys(err, index, obj) Cookiefilter::Validator.validate_description(err, index, obj) Cookiefilter::Validator.validate_key(err, index, obj) Cookiefilter::Validator.validate_value(err, index, obj) Cookiefilter::Validator.validate_sacred(err, index, obj) end true end
validate_value(err, index, obj)
click to toggle source
# File lib/cookiefilter/validator.rb, line 53 def validate_value(err, index, obj) value = obj[:value] if value.class != Regexp && value.class != NilClass return raise err, "safelist child with index #{index}: ':value' \ must be of class Regexp or NilClass, got #{value.class}" end end