Sha256: dde72d911d8be80fda7e82047cdbdb826de47c632b2f6f8b47abb6869fb3a802
Contents?: true
Size: 1.27 KB
Versions: 3
Compression:
Stored size: 1.27 KB
Contents
module Reform::Contract::Validate module NestedValid def to_hash(*) nested_forms do |attr| # attr.delete(:prepare) # attr.delete(:extend) attr.merge!( :serialize => lambda { |object, args| # FIXME: merge with Validate::Writer options = args.user_options.dup options[:prefix] = options[:prefix].dup # TODO: implement Options#dup. options[:prefix] << args.binding.name # FIXME: should be #as. # puts "======= user_options: #{args.user_options.inspect}" object.validate!(options) # recursively call valid? }, ) end super end end def validate options = {:errors => errs = Reform::Contract::Errors.new(self), :prefix => []} validate!(options) self.errors = errs # if the AM valid? API wouldn't use a "global" variable this would be better. errors.valid? end def validate!(options) # puts "validate! in #{self.class.name}: #{true.inspect}" prefix = options[:prefix] # call valid? recursively and collect nested errors. mapper.new(self).extend(NestedValid).to_hash(options) valid? # this validates on <Fields> using AM::Validations, currently. options[:errors].merge!(self.errors, prefix) end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
reform-1.0.2 | lib/reform/contract/validate.rb |
reform-1.0.1 | lib/reform/contract/validate.rb |
reform-1.0.0 | lib/reform/contract/validate.rb |