Method: Attributor::Hash#validate

Defined in:
lib/attributor/types/hash.rb

#validate(context = Attributor::DEFAULT_ROOT_CONTEXT) ⇒ Object



634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
# File 'lib/attributor/types/hash.rb', line 634

def validate(context = Attributor::DEFAULT_ROOT_CONTEXT)
  @validating = true
  context = [context] if context.is_a? ::String

  if self.class.keys.any?
    extra_keys = @contents.keys - self.class.keys.keys
    if extra_keys.any? && !self.class.options[:allow_extra]
      return extra_keys.collect do |k|
        "#{Attributor.humanize_context(context)} can not have key: #{k.inspect}"
      end
    end
    self.validate_keys(context)
  else
    self.validate_generic(context)
  end
ensure
  @validating = false      
end