Module: Reform::Contract::Validate::NestedValid

Defined in:
lib/reform/contract/validate.rb

Instance Method Summary collapse

Instance Method Details

#to_hashObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/reform/contract/validate.rb', line 3

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