class EasyParams::Base
Public Class Methods
name()
click to toggle source
# File lib/easy_params/base.rb, line 7 def self.name 'EasyParams::Base' end
Public Instance Methods
validate_nested()
click to toggle source
# File lib/easy_params/base.rb, line 19 def validate_nested run_nested_validations = proc do |attr_name, value, array_index, error_key_prefix| case value when Array value.each.with_index do |element, i| run_nested_validations[attr_name, element, i, error_key_prefix] end when self.class.struct if value.invalid? error_key_components = [error_key_prefix, attr_name, array_index] attr_error_key_prefix = error_key_components.compact.join('/') value.errors.each do |error_key, error_message| errors.add("#{attr_error_key_prefix}/#{error_key}", error_message) end end value.attributes.each do |nested_attr_name, nested_value| run_nested_validations[nested_attr_name, nested_value, nil, attr_error_key_prefix] end else # NOOP end end attributes.each(&run_nested_validations) end