Class: Yoda::Store::Registry
- Inherits:
-
Object
- Object
- Yoda::Store::Registry
- 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
- #add_patch(patch) ⇒ Object
-
#compress_and_save ⇒ Object
Store patch set data to the database.
- #find(path) ⇒ Objects::Base?
- #has_key?(path) ⇒ true, false
-
#initialize(adapter = nil) ⇒ Registry
constructor
A new instance of Registry.
- #project_status ⇒ Objects::ProjectStatus?
- #save_project_status(new_project_status) ⇒ Object
Constructor Details
Instance Attribute Details
#adapter ⇒ Adapters::LmdbAdapter?
10 11 12 |
# File 'lib/yoda/store/registry.rb', line 10 def adapter @adapter end |
#patch_set ⇒ Objects::PatchSet (readonly)
16 17 18 |
# File 'lib/yoda/store/registry.rb', line 16 def patch_set @patch_set end |
Instance Method Details
#add_patch(patch) ⇒ Object
46 47 48 |
# File 'lib/yoda/store/registry.rb', line 46 def add_patch(patch) patch_set.register(patch) end |
#compress_and_save ⇒ Object
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?
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
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_status ⇒ Objects::ProjectStatus?
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
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 |