Class: DTK::State::Component
- Inherits:
-
Object
- Object
- DTK::State::Component
- Defined in:
- lib/state/component.rb,
lib/state/component/attribute.rb
Defined Under Namespace
Classes: Attribute
Instance Attribute Summary collapse
-
#component_def ⇒ Object
readonly
Returns the value of attribute component_def.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
-
.get(crd_assembly_namespace, crd_assembly_name, component_name, opts = {}) ⇒ Object
opts can have keys task_id.
-
.get_attributes(crd_assembly_namespace, crd_assembly_name, component_name, opts = {}) ⇒ Object
opts can have keys task_id format: hash kubernetes - return attributes in raw format from kubeclient.
Instance Method Summary collapse
- #attribute_values ⇒ Object
- #attributes(opts = {}) ⇒ Object
-
#initialize(name, component_content, parent, opts = {}) ⇒ Component
constructor
A new instance of Component.
Constructor Details
#initialize(name, component_content, parent, opts = {}) ⇒ Component
Returns a new instance of Component.
7 8 9 10 11 12 13 14 |
# File 'lib/state/component.rb', line 7 def initialize(name, component_content, parent, opts = {}) @name = name # @parent = parent @component_defs = parent.references.component_def @component_def = get_component_def(opts) @attribute_objs = Attribute.create_from_kube_hash(component_content[:attributes] || {})# convert_to_attribute_objects(component_content[:attributes]) end |
Instance Attribute Details
#component_def ⇒ Object (readonly)
Returns the value of attribute component_def.
5 6 7 |
# File 'lib/state/component.rb', line 5 def component_def @component_def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/state/component.rb', line 5 def name @name end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
5 6 7 |
# File 'lib/state/component.rb', line 5 def parent @parent end |
Class Method Details
.get(crd_assembly_namespace, crd_assembly_name, component_name, opts = {}) ⇒ Object
opts can have keys
task_id
18 19 20 21 22 23 |
# File 'lib/state/component.rb', line 18 def self.get(crd_assembly_namespace, crd_assembly_name, component_name, opts = {}) crd_assembly = CrdAssembly.get(crd_assembly_namespace, crd_assembly_name, opts) if matching_component = Component.find_matching_component(crd_assembly, component_name) Component.new(component_name, Component.get_component_content(matching_component, component_name), crd_assembly, opts) end end |
.get_attributes(crd_assembly_namespace, crd_assembly_name, component_name, opts = {}) ⇒ Object
opts can have keys task_id format:
hash
kubernetes - return attributes in raw format from kubeclient
30 31 32 33 |
# File 'lib/state/component.rb', line 30 def self.get_attributes(crd_assembly_namespace, crd_assembly_name, component_name, opts = {}) component = get(crd_assembly_namespace, crd_assembly_name, component_name, opts) component.attributes(opts) end |
Instance Method Details
#attribute_values ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/state/component.rb', line 47 def attribute_values attribute_with_values = [] @content[:attributes].each do |name, content| attribute_with_values << { name => content[:value] } end attribute_with_values end |
#attributes(opts = {}) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/state/component.rb', line 35 def attributes(opts = {}) format = opts[:format] return @attribute_objs unless format if format.to_s == 'hash' @attribute_objs.map{ |attr| attr.to_hash } else fail Error.new "Unsupported format '#{format}'" end end |