Class: Datadog::Core::Remote::Configuration::Repository

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

Overview

Repository

Defined Under Namespace

Modules: Change Classes: ChangeSet, State, Transaction

Constant Summary collapse

UNVERIFIED_ROOT_VERSION =
1
INITIAL_TARGETS_VERSION =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRepository

Returns a new instance of Repository.



21
22
23
24
25
26
# File 'lib/datadog/core/remote/configuration/repository.rb', line 21

def initialize
  @contents = ContentList.new
  @opaque_backend_state = nil
  @root_version = UNVERIFIED_ROOT_VERSION
  @targets_version = INITIAL_TARGETS_VERSION
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



11
12
13
# File 'lib/datadog/core/remote/configuration/repository.rb', line 11

def contents
  @contents
end

#opaque_backend_stateObject (readonly)

Returns the value of attribute opaque_backend_state.



11
12
13
# File 'lib/datadog/core/remote/configuration/repository.rb', line 11

def opaque_backend_state
  @opaque_backend_state
end

#root_versionObject (readonly)

Returns the value of attribute root_version.



11
12
13
# File 'lib/datadog/core/remote/configuration/repository.rb', line 11

def root_version
  @root_version
end

#targets_versionObject (readonly)

Returns the value of attribute targets_version.



11
12
13
# File 'lib/datadog/core/remote/configuration/repository.rb', line 11

def targets_version
  @targets_version
end

Instance Method Details

#[](path) ⇒ Object



32
33
34
# File 'lib/datadog/core/remote/configuration/repository.rb', line 32

def [](path)
  @contents[path]
end

#commit(transaction) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/datadog/core/remote/configuration/repository.rb', line 44

def commit(transaction)
  previous = contents.dup

  touched = transaction.operations.each_with_object([]) do |op, acc|
    acc << op.apply(self)
  end

  changes = ChangeSet.new

  touched.uniq.each do |path|
    next if path.nil?

    changes.add(path, previous[path], @contents[path])
  end

  changes.freeze
end

#pathsObject



28
29
30
# File 'lib/datadog/core/remote/configuration/repository.rb', line 28

def paths
  @contents.paths
end

#stateObject



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

def state
  State.new(self)
end

#transaction {|_self, transaction| ... } ⇒ Object

Yields:

Yield Parameters:



36
37
38
39
40
41
42
# File 'lib/datadog/core/remote/configuration/repository.rb', line 36

def transaction
  transaction = Transaction.new

  yield(self, transaction)

  commit(transaction)
end