Class: Reform::Form::ActiveModel::ModelValidations::ValidationCopier

Inherits:
Object
  • Object
show all
Defined in:
lib/reform/form/active_model/model_validations.rb

Overview

TODO: extract Composition behaviour. reduce code in Mapping.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(form_class, mapping, model, model_name = nil) ⇒ ValidationCopier

Returns a new instance of ValidationCopier.



18
19
20
21
22
23
# File 'lib/reform/form/active_model/model_validations.rb', line 18

def initialize(form_class, mapping, model, model_name=nil)
  @form_class = form_class
  @mapping = mapping
  @model = model
  @model_name = model_name
end

Class Method Details

.copy(form_class, mapping, models) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/reform/form/active_model/model_validations.rb', line 8

def self.copy(form_class, mapping, models)
  if models.is_a?(Hash)
    models.each do |model_name, model|
      new(form_class, mapping, model, model_name).copy
    end
  else
    new(form_class, mapping, models).copy
  end
end

Instance Method Details

#copyObject



25
26
27
# File 'lib/reform/form/active_model/model_validations.rb', line 25

def copy
  @model.validators.each(&method(:add_validator))
end