Class: DTK::State::Component::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/state/component/attribute.rb,
lib/state/component/providers/influxdb.rb,
lib/state/component/providers/kube_crd.rb

Direct Known Subclasses

Influxdb, KubeCrd

Defined Under Namespace

Classes: Influxdb, KubeCrd

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attribute_content, parent) ⇒ Attribute

Returns a new instance of Attribute.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 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

Instance Attribute Details

#dynamicObject (readonly)

Returns the value of attribute dynamic.



7
8
9
# File 'lib/state/component/attribute.rb', line 7

def dynamic
  @dynamic
end

#encryptedObject (readonly)

Returns the value of attribute encrypted.



7
8
9
# File 'lib/state/component/attribute.rb', line 7

def encrypted
  @encrypted
end

#functionObject (readonly)

Returns the value of attribute function.



7
8
9
# File 'lib/state/component/attribute.rb', line 7

def function
  @function
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/state/component/attribute.rb', line 7

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/state/component/attribute.rb', line 7

def parent
  @parent
end

#requiredObject (readonly)

Returns the value of attribute required.



7
8
9
# File 'lib/state/component/attribute.rb', line 7

def required
  @required
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/state/component/attribute.rb', line 7

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/state/component/attribute.rb', line 7

def value
  @value
end

Class Method Details

.create_from_kube_array(kube_attributes) ⇒ Object



71
72
73
74
75
# 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) ⇒ Object



65
66
67
68
69
# 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 = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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

Instance Method Details

#to_hashObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# 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