Module: Pathway::Plugins::DryValidation::ClassMethods

Defined in:
lib/pathway/plugins/dry_validation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#form_classObject

Returns the value of attribute form_class.



7
8
9
# File 'lib/pathway/plugins/dry_validation.rb', line 7

def form_class
  @form_class
end

Instance Method Details

#build_form(opts = {}) ⇒ Object



25
26
27
# File 'lib/pathway/plugins/dry_validation.rb', line 25

def build_form(opts = {})
  @builded_form || form_class.new(opts)
end

#form(base = nil, **opts, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/pathway/plugins/dry_validation.rb', line 9

def form(base = nil, **opts, &block)
  if block_given?
    base ||= _base_form
    self.form_class = Dry::Validation.Form(_form_class(base), _form_opts(opts), &block)
  elsif base
    self.form_class = _form_class(base)
  else
    raise ArgumentError, 'Either a form class or a block must be provided'
  end
end

#inherited(subclass) ⇒ Object



29
30
31
32
# File 'lib/pathway/plugins/dry_validation.rb', line 29

def inherited(subclass)
  super
  subclass.form_class = form_class
end