Class: Datadog::Core::Remote::Configuration::Content

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/remote/configuration/content.rb

Overview

Content stores the information associated with a specific Configuration::Path

Defined Under Namespace

Modules: ApplyState

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path:, data:) ⇒ Content

Returns a new instance of Content.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/datadog/core/remote/configuration/content.rb', line 24

def initialize(path:, data:)
  if data.nil?
    # +data+ is passed to Digest calculation and also is
    # unconditionally taken length of by +length+ method.
    # As such, the class is not written to expect +data+ to be nil.
    # Detect bad incoming values here to provide earlier diagnostics
    # when developing tests, for example.
    raise ArgumentError, 'data must not be nil'
  end
  unless String === data
    raise ArgumentError, "Invalid type for data: #{data.class}: expected String"
  end

  @path = path
  @data = data
  @apply_state = ApplyState::UNACKNOWLEDGED
  @apply_error = nil
  @hashes = {}
  @version = 0
end

Instance Attribute Details

#apply_errorObject (readonly)

Returns the value of attribute apply_error.



21
22
23
# File 'lib/datadog/core/remote/configuration/content.rb', line 21

def apply_error
  @apply_error
end

#apply_stateObject (readonly)

Returns the value of attribute apply_state.



21
22
23
# File 'lib/datadog/core/remote/configuration/content.rb', line 21

def apply_state
  @apply_state
end

#dataObject (readonly)

Returns the value of attribute data.



21
22
23
# File 'lib/datadog/core/remote/configuration/content.rb', line 21

def data
  @data
end

#hashesObject (readonly)

Returns the value of attribute hashes.



21
22
23
# File 'lib/datadog/core/remote/configuration/content.rb', line 21

def hashes
  @hashes
end

#pathObject (readonly)

Returns the value of attribute path.



21
22
23
# File 'lib/datadog/core/remote/configuration/content.rb', line 21

def path
  @path
end

#versionObject

Returns the value of attribute version.



22
23
24
# File 'lib/datadog/core/remote/configuration/content.rb', line 22

def version
  @version
end

Class Method Details

.parse(hash) ⇒ Object



13
14
15
16
17
18
# File 'lib/datadog/core/remote/configuration/content.rb', line 13

def parse(hash)
  path = Path.parse(hash[:path])
  data = hash[:content]

  new(path: path, data: data)
end

Instance Method Details

#appliedObject

Sets this configuration as successfully applied.



54
55
56
57
# File 'lib/datadog/core/remote/configuration/content.rb', line 54

def applied
  @apply_state = ApplyState::ACKNOWLEDGED
  @apply_error = nil
end

#errored(error_message) ⇒ Object

Sets this configuration as not successfully applied, with a message describing the error.



61
62
63
64
# File 'lib/datadog/core/remote/configuration/content.rb', line 61

def errored(error_message)
  @apply_state = ApplyState::ERROR
  @apply_error = error_message
end

#hexdigest(type) ⇒ Object



45
46
47
# File 'lib/datadog/core/remote/configuration/content.rb', line 45

def hexdigest(type)
  @hashes[type] || compute_and_store_hash(type)
end

#lengthObject



49
50
51
# File 'lib/datadog/core/remote/configuration/content.rb', line 49

def length
  @length ||= @data.size
end