class Aws::Templates::Utils::Dependency

Dependency marker proxy

Used internally in the framework to mark an object as potential dependency. There are other alternatives for doing the same like singleton class and reference object. There are a few advantages of the approach taken:

Attributes

dependencies[R]
not_a_dependency[R]
object[R]

Public Class Methods

new(source_object) click to toggle source

Initialize the proxy

# File lib/aws/templates/utils/dependency.rb, line 113
def initialize(source_object)
  @object = source_object.object

  @dependencies = if source_object.dependency?
    source_object.dependencies.dup
  else
    ::Set.new
  end
end

Public Instance Methods

!=(other) click to toggle source

Non-equality

# File lib/aws/templates/utils/dependency.rb, line 36
def !=(other)
  !eql?(other)
end
==(other) click to toggle source

Alias for eql?

# File lib/aws/templates/utils/dependency.rb, line 31
def ==(other)
  eql?(other)
end
as_a_dependency() click to toggle source

mark the object as dependency

# File lib/aws/templates/utils/dependency.rb, line 51
def as_a_dependency
  self
end
class() click to toggle source

BasicObject is so basic that this part is missing too

# File lib/aws/templates/utils/dependency.rb, line 41
def class
  Dependency
end
dependency?() click to toggle source

It's a dependency

# File lib/aws/templates/utils/dependency.rb, line 46
def dependency?
  true
end
eql?(other) click to toggle source

Equality

Two Dependency objects are equal if it's the same object or if they are pointing to the same target.

# File lib/aws/templates/utils/dependency.rb, line 25
def eql?(other)
  equal?(other) || ((self.class == other.class) && (object == other.object))
end
method_missing(name, *args, &block) click to toggle source

Redirect every method call to the proxied object if the object supports it

Calls superclass method
# File lib/aws/templates/utils/dependency.rb, line 62
def method_missing(name, *args, &block)
  object.respond_to?(name) ? object.send(name, *args, &block) : super
end
respond_to_missing?(name, include_private = false) click to toggle source

It supports every method proxied object supports

# File lib/aws/templates/utils/dependency.rb, line 68
def respond_to_missing?(name, include_private = false)
  object.respond_to?(name, include_private)
end
to(target) click to toggle source

Add dependency

Add a link to the target to the current Dependency object

# File lib/aws/templates/utils/dependency.rb, line 76
def to(target)
  if target.dependency?
    dependencies.merge(target.dependencies)
  else
    dependencies << target
  end

  self
end
to_self() click to toggle source

Set dependency to the target

# File lib/aws/templates/utils/dependency.rb, line 107
def to_self
  to(object)
end
with(source = nil, &source_calculation_block) click to toggle source

Link the value to the source

Links source or result of calculation of the block to the target object of the dependency. The mecahanism is a middle ground between extreme case of indefinite recursive dependency propagation and no propagation at all

some_artifact.as_a_dependency.with { some_attribute }
# => Dependency(@object = <some_attribute value>, <link to some_artifact>)
# File lib/aws/templates/utils/dependency.rb, line 95
def with(source = nil, &source_calculation_block)
  value = if source_calculation_block.nil?
    source
  else
    object.instance_exec(value, &source_calculation_block)
  end

  value.as_a_dependency.to(self)
end