Class: Yoda::Store::Objects::PatchSet
- Inherits:
-
Object
- Object
- Yoda::Store::Objects::PatchSet
- Defined in:
- lib/yoda/store/objects/patch_set.rb
Overview
PatchSet manages patch updates and patch outdates. Besides, this class provides api to modify objects by using owning patches.
Instance Attribute Summary collapse
- #address_index ⇒ { Symbol => Array<Symbol> } readonly
- #patches ⇒ { Symbol => Patch } readonly
Instance Method Summary collapse
- #delete(id) ⇒ Object
- #find(address) ⇒ Addressable?
- #has_key?(address) ⇒ true, false
-
#initialize ⇒ PatchSet
constructor
A new instance of PatchSet.
- #keys ⇒ Array<Symbol>
- #patch(object) ⇒ Addressable
- #register(patch) ⇒ void
Constructor Details
#initialize ⇒ PatchSet
Returns a new instance of PatchSet.
13 14 15 16 |
# File 'lib/yoda/store/objects/patch_set.rb', line 13 def initialize @patches = Hash.new @address_index = Hash.new end |
Instance Attribute Details
#address_index ⇒ { Symbol => Array<Symbol> } (readonly)
8 9 10 |
# File 'lib/yoda/store/objects/patch_set.rb', line 8 def address_index @address_index end |
#patches ⇒ { Symbol => Patch } (readonly)
11 12 13 |
# File 'lib/yoda/store/objects/patch_set.rb', line 11 def patches @patches end |
Instance Method Details
#delete(id) ⇒ Object
26 27 28 |
# File 'lib/yoda/store/objects/patch_set.rb', line 26 def delete(id) patches.delete(id.to_sym) end |
#find(address) ⇒ Addressable?
40 41 42 43 44 45 46 47 48 |
# File 'lib/yoda/store/objects/patch_set.rb', line 40 def find(address) check_outdated_index(address.to_sym) if (patch_ids = address_index[address.to_sym] || []).empty? nil else objects = patch_ids.map { |id| patches[id].find(address.to_sym) } Merger.new(objects).merged_instance end end |
#has_key?(address) ⇒ true, false
57 58 59 60 |
# File 'lib/yoda/store/objects/patch_set.rb', line 57 def has_key?(address) check_outdated_index(address.to_sym) address_index[address.to_sym] && !address_index[address.to_sym].empty? end |
#keys ⇒ Array<Symbol>
51 52 53 |
# File 'lib/yoda/store/objects/patch_set.rb', line 51 def keys address_index.keys end |
#patch(object) ⇒ Addressable
32 33 34 35 36 |
# File 'lib/yoda/store/objects/patch_set.rb', line 32 def patch(object) check_outdated_index(object.address.to_sym) objects_in_patch = (address_index[object.address.to_sym] || []).map { |patch_id| patches[patch_id].find(object.address.to_sym) } Merger.new([object, *objects_in_patch]).merged_instance end |
#register(patch) ⇒ void
This method returns an undefined value.
20 21 22 23 |
# File 'lib/yoda/store/objects/patch_set.rb', line 20 def register(patch) register_to_index(patch) patches[patch.id.to_sym] = patch end |