Class: Interdependence::DependencyResolver::Base

Inherits:
Object
  • Object
show all
Includes:
Adamantium
Defined in:
lib/interdependence/dependency_resolver/base.rb

Overview

Base class that consolidates common functionality for dependency resolvers

Direct Known Subclasses

Model, Validator

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.dependency_class=(value) ⇒ Class (writeonly)

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.

Dependency class this resolver should use

Returns:

  • (Class)

    specified dependency class



41
# File 'lib/interdependence/dependency_resolver/base.rb', line 41

class_attribute :dependency_class, instance_writer: false

Instance Method Details

#dependenciesObservableDependencySetGraph

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.

ObservableDependencySetGraph resolved dependencies

Returns:



49
50
51
52
53
54
55
# File 'lib/interdependence/dependency_resolver/base.rb', line 49

def dependencies
  dependency_graph_mapper.each do |(parent, children), graph|
    new_parent, new_children = resolve_pair(parent, children)

    graph[new_parent].replace(new_children)
  end
end

#dependency_graph_mapperEnumerator

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.

Iterator for resolving dependencies

Returns:

  • (Enumerator)
    description


106
107
108
109
110
111
# File 'lib/interdependence/dependency_resolver/base.rb', line 106

def dependency_graph_mapper
  new_dependency
    .dependencies
    .each
    .with_object(ObservableDependencySetGraph.new)
end

#fieldSymbol

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.

Field name

Returns:

  • (Symbol)

    field name



15
# File 'lib/interdependence/dependency_resolver/base.rb', line 15

attribute :field, Symbol, strict: true

#new_dependencydependency_class

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.

New dependency initialized with attributes of self

Returns:

  • (dependency_class)

    new dependency



63
64
65
# File 'lib/interdependence/dependency_resolver/base.rb', line 63

def new_dependency
  dependency_class.new(self)
end

#optionsHash

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.

Options for validator

Returns:

  • (Hash)

    options hash



31
# File 'lib/interdependence/dependency_resolver/base.rb', line 31

attribute :options, Hash, strict: true

#resolve_dependency(dependency) ⇒ dependency_class

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.

Resolve a dependency if it is resolvable

Parameters:

  • dependency (dependency_class)

    dependency to resolve

Returns:

  • (dependency_class)

    resolved dependency or input



76
77
78
79
80
81
82
# File 'lib/interdependence/dependency_resolver/base.rb', line 76

def resolve_dependency(dependency)
  if resolvable?(dependency)
    resolve_with(dependency)
  else
    dependency
  end
end

#resolve_pair(parent, children) ⇒ Object

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.

Resolve a parent-children pair

Parameters:

  • parent (dependency_class)

    dependency owner

  • children (Array<dependency_class>)

    dependencies of parent

Returns:

  • resolved parent-children pair



93
94
95
96
97
98
# File 'lib/interdependence/dependency_resolver/base.rb', line 93

def resolve_pair(parent, children)
  parent = resolve_dependency(parent)
  children = children.map { |child| resolve_dependency(child) }

  [parent, children]
end

#validator_classClass

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.

Descendant of ActiveModel::Model

Returns:

  • (Class)

    class that includes activemodel



23
# File 'lib/interdependence/dependency_resolver/base.rb', line 23

attribute :validator_class, Class, coercer: Types::ValidatorClassCoercer, strict: true