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:
-
Dependency
can be used whereever original object is expected -
Dependecy can be applied case-by-case basis whereas singleton is attached to the object itself
Attributes
Public Class Methods
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
Non-equality
# File lib/aws/templates/utils/dependency.rb, line 36 def !=(other) !eql?(other) end
Alias for eql?
# File lib/aws/templates/utils/dependency.rb, line 31 def ==(other) eql?(other) end
mark the object as dependency
# File lib/aws/templates/utils/dependency.rb, line 51 def as_a_dependency self end
BasicObject is so basic that this part is missing too
# File lib/aws/templates/utils/dependency.rb, line 41 def class Dependency end
It's a dependency
# File lib/aws/templates/utils/dependency.rb, line 46 def dependency? true end
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
Redirect every method call to the proxied object if the object supports it
# 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
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
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
Set dependency to the target
# File lib/aws/templates/utils/dependency.rb, line 107 def to_self to(object) end
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