Class: Yoda::Store::Objects::PatchSet

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializePatchSet

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)

Returns:

  • ({ Symbol => Array<Symbol> })


8
9
10
# File 'lib/yoda/store/objects/patch_set.rb', line 8

def address_index
  @address_index
end

#patches{ Symbol => Patch } (readonly)

Returns:



11
12
13
# File 'lib/yoda/store/objects/patch_set.rb', line 11

def patches
  @patches
end

Instance Method Details

#delete(id) ⇒ Object

Parameters:

  • id (String, Symbol)


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?

Parameters:

  • address (String, Symbol)

Returns:



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

Parameters:

  • address (String, Symbol)

Returns:

  • (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

#keysArray<Symbol>

Returns:

  • (Array<Symbol>)


51
52
53
# File 'lib/yoda/store/objects/patch_set.rb', line 51

def keys
  address_index.keys
end

#patch(object) ⇒ Addressable

Parameters:

Returns:



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.

Parameters:



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