Module: Interdependence::Validator::ClassMethods

Defined in:
lib/interdependence/validator.rb

Overview

Class methods mixed into ActiveModel::Validator

Instance Method Summary collapse

Instance Method Details

#as_dependencyDependency::Validator

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.

Current validator wrapped in the Dependency::Validator class

Returns:



38
39
40
# File 'lib/interdependence/validator.rb', line 38

def as_dependency
  @as_dependency ||= Dependency::Validator.new(validator_class: self)
end

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

Registers self as a dependency owner on dependencies

Returns:

  • (Void)


61
62
63
64
# File 'lib/interdependence/validator.rb', line 61

def clear_dependencies!
  super
  dependencies.register(as_dependency)
end

#inherit_dependencies(old_owner) ⇒ 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.

Delete another key and inherit its dependencies

Parameters:

Returns:

  • (undefined)


29
30
31
# File 'lib/interdependence/validator.rb', line 29

def inherit_dependencies(old_owner)
  dependencies[as_dependency] = dependencies.delete(old_owner)
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.

Transfer parent dependencies to child upon inheritance

Parameters:

  • base (Class)
    parent class

Returns:

  • (undefined)


15
16
17
18
19
# File 'lib/interdependence/validator.rb', line 15

def inherited(base)
  super

  base.inherit_dependencies(as_dependency)
end

#sync_dependenciesVoid

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.

Merges dependencies of validators the current class depends on

Returns:

  • (Void)


48
49
50
51
52
53
# File 'lib/interdependence/validator.rb', line 48

def sync_dependencies(*)
  dependencies.keys.each do |key|
    validator = key.validator_class
    dependencies[key] = validator.dependencies[validator.as_dependency]
  end
end