Module: Interdependence::Model::ClassMethods

Defined in:
lib/interdependence/model.rb

Overview

Class methods mixed into any class that includes `ActiveModel::Model`

Instance Method Summary collapse

Instance Method Details

#clear_dependencies!Void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

adds an observer that expects #update_validators to be called

Returns:

  • (Void)

See Also:

  • CommonMixin::ClassMethods#clear_dependencies

49
50
51
52
# File 'lib/interdependence/model.rb', line 49

def clear_dependencies!
  super
  dependencies.add_observer(self, :update_validators)
end

#inherited(base) ⇒ undefined

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Clone `validate_calls` on class inherited by class

Returns:

  • (undefined)

17
18
19
20
21
# File 'lib/interdependence/model.rb', line 17

def inherited(base)
  super

  base.validate_calls = validate_calls.clone
end

#update_validatorsVoid

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Update validators attached to the current model

Returns:

  • (Void)

See Also:

  • ActiveModel::Validations::ClassMethods#clear_validators!

31
32
33
34
35
36
37
38
39
40
# File 'lib/interdependence/model.rb', line 31

def update_validators(*)
  clear_validators!
  validate_calls.each do |args, _|
    active_model_validate(*args)
  end

  dependency_chain.each do |validator|
    active_model_validates_with(*validator.to_active_model)
  end
end