Module: Interdependence::CommonMixin::ClassMethods

Defined in:
lib/interdependence/common_mixin.rb

Overview

Common class methods for Model and Validator

Instance Method Summary collapse

Instance Method Details

#add_interdependent_validator(field, validator, options) ⇒ 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.

Add validator and merge its dependencies

Parameters:

  • field (Symbol)
    name of field to validate
  • validator (Class)
    descendant of ActiveModel::Validator
  • options (Hash, TrueClass)
    ActiveModel::Validator options

Returns:

  • (undefined)


64
65
66
67
68
69
70
71
# File 'lib/interdependence/common_mixin.rb', line 64

def add_interdependent_validator(field, validator, options)
  self::Validator.new(
    owner: self,
    field: field,
    validator_class: validator,
    options: options
  ).save
end

#clear_dependencies!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.

Resets dependencies to a new ObservableDependencySetGraph

Returns:

  • (undefined)


79
80
81
# File 'lib/interdependence/common_mixin.rb', line 79

def clear_dependencies!
  self.dependencies = ObservableDependencySetGraph.new
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.

Handle dependencies on inheritance

resets depenencies on base and then merges in a clone of the parent dependencies

Returns:

  • (undefined)


47
48
49
50
51
52
# File 'lib/interdependence/common_mixin.rb', line 47

def inherited(base)
  super

  base.clear_dependencies!
  base.dependencies.merge!(dependencies.clone)
end