Module: Reform::Validation::ClassMethods

Defined in:
lib/reform/validation.rb

Instance Method Summary collapse

Instance Method Details

#deprecate_validation_positional_args(name, options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/reform/validation.rb', line 20

def deprecate_validation_positional_args(name, options)
  if name.is_a?(Symbol)
    warn "[Reform] Form::validation API is now: validation(name: :default, if:nil, schema:Schema). Please use keyword arguments instead of positional arguments."
    return {name: name}.merge(options)
  end

  return {name: :default}.merge(options) if name.nil?

  {name: :default}.merge(name)
end

#validation(name = nil, options = {}, &block) ⇒ Object

DSL.



10
11
12
13
14
15
16
17
18
# File 'lib/reform/validation.rb', line 10

def validation(name = nil, options = {}, &block)
  options = deprecate_validation_positional_args(name, options)
  name    = options[:name] # TODO: remove in favor of kw args in 3.0.

  heritage.record(:validation, options, &block)
  group = validation_groups.add(name, options)

  group.instance_exec(&block)
end

#validation_group_classObject



31
32
33
34
# File 'lib/reform/validation.rb', line 31

def validation_group_class
  raise NoValidationLibraryError, "no validation library loaded. Please include a " +
                                  "validation library such as Reform::Form::Dry"
end

#validation_groupsObject



5
6
7
# File 'lib/reform/validation.rb', line 5

def validation_groups
  @groups ||= Groups.new(validation_group_class)
end