Class: Aws::Templates::Artifact
- Inherits:
-
Object
- Object
- Aws::Templates::Artifact
- Includes:
- Help::Dsl, Utils::Default, Utils::Dependent, Utils::Parametrized
- Defined in:
- lib/aws/templates/artifact.rb
Overview
Basic artifact
“Artifact” in the terminology of the framework is an entity which can represent any parametrizable object type from any problem domain possible. For instance, for CloudFormation, artifacts are resources in a CFN template, the template itself
If your target domain is infrastructure orchestration, artifact is usually a single entity such as S3 volume, ASG, DynamoDB table, etc. However, the notion of artifact is not particularly fixed since the framework can be used for different purposes including documents generation and general templating tasks. Basically, artifact is a single parametrizable entity or a step in input hash transformations.
Artifact classes work together with meta-programming mechanisms in Ruby language enabling artifacts inheritance in the natural way using simple Ruby classes. The feature is useful when you have a group of artifacts which share the same basic parameters but differ in details.
The central part in the framework is played by processed hash. All mechanisms are based on simple ad-hoc merging rules which are described at merge method but basis can be described as following: each superclass initializer accepts children class processed hash as input hash and the hash is processed recursively through class hierarchy. Old values are newer removed by default so the whole process is no more than continuous hash expansion.
class Piece < Artifact
default { { output: [:param] } }
end
class ConcretePiece < Piece
default param: 'Came from child'
end
Piece.new(a: 1, b: 2)..to_hash # => { a: 1, b: 2, output: nil }
ConcretePiece.new(a: 1, b: 2)..to_hash
# => { a: 1, b: 2, output: 'Came from child', param: 'Came from child' }
Also, as one of the peculiarities of the framework, you can override any auto-generated parameter with input hash if they have the same name/path.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
- .features ⇒ Object
-
.featuring(*modules) ⇒ Object
Create new child class with mixins.
- .getter ⇒ Object
- .to_s ⇒ Object
Instance Method Summary collapse
-
#initialize(params) ⇒ Artifact
constructor
Create a new artifact.
-
#lookup_path ⇒ Object
Artifact’s look-up path through all ancestors.
-
#meta ⇒ Object
Meta field.
-
#parent ⇒ Object
Artifact’s parent.
-
#proc ⇒ Object
Artifact’s label.
-
#root ⇒ Object
Artifact’s root.
Methods included from Utils::Inheritable::ClassMethods
#_class_scope_defined?, #_define_class_scope, #class_scope, #included, #instance_scope
Methods included from Utils::Dependent
Methods included from Utils::Inspectable
Methods included from Utils::Guarded
Constructor Details
#initialize(params) ⇒ Artifact
Create a new artifact
Artifact constructor. If you want to override it you might probably want to look into default first. All default values specified in the class definition and all its ancestors are processed and merged with options so it contains fully-processed hash.
The algorithm of the processing is the following:
-
merge defaults hash with passed options; options take precedence
-
merge the hash with default calculations return results; calculations output takes preference
-
pass resulting hash to superclass initializer
-
merge resulting hash with options; options take preference
-
params
- input parameters hash to be used during followinghash transformations and expansions.
156 157 158 |
# File 'lib/aws/templates/artifact.rb', line 156 def initialize(params) @options = Templates::Utils::Options.new(defaults, params) end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
56 57 58 |
# File 'lib/aws/templates/artifact.rb', line 56 def @options end |
Class Method Details
.features ⇒ Object
67 68 69 |
# File 'lib/aws/templates/artifact.rb', line 67 def self.features @features ||= ancestors.take_while { |mod| mod != superclass } end |
.featuring(*modules) ⇒ Object
Create new child class with mixins
The class method is useful when you want to mix-in some behavior adjustments without creating a new named class. For instance when you want to mix-in some defaults into class and instantiate a few instances out of that.
76 77 78 79 80 81 82 |
# File 'lib/aws/templates/artifact.rb', line 76 def self.featuring(*modules) return self if modules.empty? modules.inject(Class.new(self)) do |klass, mod| klass.send(:include, mod) end end |
.getter ⇒ Object
58 59 60 |
# File 'lib/aws/templates/artifact.rb', line 58 def self.getter as_is end |
.to_s ⇒ Object
62 63 64 65 |
# File 'lib/aws/templates/artifact.rb', line 62 def self.to_s return super unless name.nil? "<Subclass of (#{superclass}) with features #{features}>" end |
Instance Method Details
#lookup_path ⇒ Object
Artifact’s look-up path through all ancestors
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/aws/templates/artifact.rb', line 119 def lookup_path acc = [label] ancestor = parent until ancestor.nil? acc << ancestor.label ancestor = ancestor.parent end acc << root acc.reverse! end |
#meta ⇒ Object
Meta field
The field is used to attach arbitrary information to artifacts which is not directly relevant to artifact properties. This attribute can be used for tagginng, for instance.
99 100 101 102 103 104 |
# File 'lib/aws/templates/artifact.rb', line 99 def return @meta if @meta = [:meta] @meta = .nil? ? {} : .to_hash end |
#parent ⇒ Object
Artifact’s parent
Artifacts can be organized into a hierarchy of composition. This field points back to the artifact’s parent.
137 |
# File 'lib/aws/templates/artifact.rb', line 137 parameter :parent, description: 'Artifact parent' |
#proc ⇒ Object
Artifact’s label
All artifacts have labels assigned to them to simplify reverse look-up while linking dependencies. Interpretation of this field is purely application-specific.
90 |
# File 'lib/aws/templates/artifact.rb', line 90 default label: proc { object_id } |
#root ⇒ Object
Artifact’s root
A root is an object which bundles artifacts into common rendering group helping to find disconnected pieces of dependency graph. If two artifacts have different roots they definitelly belong to different graphs.
112 113 114 |
# File 'lib/aws/templates/artifact.rb', line 112 def root [:root] end |