class DTK::State::Component::Attribute
Attributes
dynamic[R]
encrypted[R]
function[R]
name[R]
parent[R]
required[R]
type[R]
value[R]
Public Class Methods
create_from_kube_array(kube_attributes)
click to toggle source
# File lib/state/component/attribute.rb, line 71 def self.create_from_kube_array(kube_attributes) kube_attributes.map do |attribute_content| Attribute.new(attribute_content[:name], attribute_content, nil) end end
create_from_kube_hash(kube_attributes)
click to toggle source
# File lib/state/component/attribute.rb, line 65 def self.create_from_kube_hash(kube_attributes) kube_attributes.to_hash.map do |attribute_name, attribute_content| Attribute.new(attribute_name, attribute_content, nil) end end
get(namespace, assembly_name, component_name, attribute_name, opts = {})
click to toggle source
# File lib/state/component/attribute.rb, line 34 def self.get(namespace, assembly_name, component_name, attribute_name, opts = {}) # getting attribute here because we can reuse it if it's stored in crd # when we decide to not store attribute value as part of assembly crd we can overwrite this assembly = Component.get(namespace, assembly_name, component_name, opts) attribute_content = assembly.attributes.find{ |attribute| attribute.name == attribute_name } fail Error.new("Unable to find attribute '#{attribute_name}' in provided assembly") if attribute_content.nil? || attribute_content.empty? attribute = self.new(attribute_name, attribute_content, assembly) provider_class = provider_class_name(attribute, opts) # return already fetched attribute value if provider is KubeCrd return attribute if provider_class == 'KubeCrd' # for KubeCrd this will do the same work we did in provider_class_name method to find temporal param self.class.const_get(provider_class).get(component_name, attribute_name, opts) end
new(name, attribute_content, parent)
click to toggle source
# File lib/state/component/attribute.rb, line 9 def initialize(name, attribute_content, parent) @name = name # @attribute_content = attribute_content # @parent = parent # TODO for backward compatibility with remote executors all attribute content is considered as value # we should change this to use proper parts of attribute as specified below @value = attribute_content # workaround for cases where we have attribute set as attribut_name: value # if attribute_content.is_a?(String) # attribute_content = { # value: attribute_content # } # end # @type = attribute_content[:type] # @function = attribute_content[:function] # @value = attribute_content[:value] # @temporal = attribute_content[:temporal] # @required = attribute_content[:required] || false # @dynamic = attribute_content[:dynamic] || false # @encrypted = attribute_content[:encrypted] || false end
Public Instance Methods
to_hash()
click to toggle source
# File lib/state/component/attribute.rb, line 51 def to_hash { @name => { # type: @type, # function: @function, value: @value, # temporal: @temporal, # required: @required, # dynamic: @dynamic, # encrypted: @encrypted } } end
Private Instance Methods
provider_class_name(attribute, opts = {})
click to toggle source
# File lib/state/component/attribute.rb, line 79 def provider_class_name(attribute, opts = {}) if attribute.temporal 'Influxdb' else 'KubeCrd' end end