Class: Yoda::Store::Registry

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/store/registry.rb

Constant Summary collapse

REGISTRY_VERSION =
Note:

This number must be updated when breaking change is added.

1
PROJECT_STATUS_KEY =
'%project_status'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(adapter = nil) ⇒ Registry

Returns a new instance of Registry.



20
21
22
23
# File 'lib/yoda/store/registry.rb', line 20

def initialize(adapter = nil)
  @patch_set = Objects::PatchSet.new
  @adapter = adapter
end

Instance Attribute Details

#adapterAdapters::LmdbAdapter?

Returns:



10
11
12
# File 'lib/yoda/store/registry.rb', line 10

def adapter
  @adapter
end

#patch_setObjects::PatchSet (readonly)

Returns:



16
17
18
# File 'lib/yoda/store/registry.rb', line 16

def patch_set
  @patch_set
end

Instance Method Details

#add_patch(patch) ⇒ Object

Parameters:

  • patch (Patch)


46
47
48
# File 'lib/yoda/store/registry.rb', line 46

def add_patch(patch)
  patch_set.register(patch)
end

#compress_and_saveObject

Store patch set data to the database. old data in the database are discarded.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/yoda/store/registry.rb', line 58

def compress_and_save
  return unless adapter
  el_keys = patch_set.keys
  progress = Instrument::Progress.new(el_keys.length) { |length:, index:| Instrument.instance.registry_dump(index: index, length: length) }

  data = Enumerator.new do |yielder|
    el_keys.each { |key| yielder << [key, patch_set.find(key)] }
  end

  adapter.batch_write(data, progress)
  adapter.sync
  Logger.info "saved #{el_keys.length} keys."
  @patch_set = Objects::PatchSet.new
end

#find(path) ⇒ Objects::Base?

Parameters:

  • path (String)

Returns:



37
38
39
40
41
42
43
# File 'lib/yoda/store/registry.rb', line 37

def find(path)
  if adapter&.exist?(path)
    patch_set.patch(adapter.get(path))
  else
    patch_set.find(path)
  end
end

#has_key?(path) ⇒ true, false

Parameters:

  • path (String)

Returns:

  • (true, false)


52
53
54
# File 'lib/yoda/store/registry.rb', line 52

def has_key?(path)
  adapter&.exists?(path) || patch_set.has_key?(path)
end

#project_statusObjects::ProjectStatus?

Returns:



26
27
28
# File 'lib/yoda/store/registry.rb', line 26

def project_status
  adapter&.exist?(PROJECT_STATUS_KEY) && adapter.get(PROJECT_STATUS_KEY)
end

#save_project_status(new_project_status) ⇒ Object

Parameters:



31
32
33
# File 'lib/yoda/store/registry.rb', line 31

def save_project_status(new_project_status)
  adapter.put(PROJECT_STATUS_KEY, new_project_status)
end