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.

Defined Under Namespace

Classes: AddressIndex

Instance Method Summary collapse

Constructor Details

#initializePatchSet

Returns a new instance of PatchSet.



47
48
49
50
# File 'lib/yoda/store/objects/patch_set.rb', line 47

def initialize
  @patches = Hash.new
  @address_index = AddressIndex.new
end

Instance Method Details

#delete(id) ⇒ Object

Parameters:

  • id (String, Symbol)


60
61
62
63
64
65
# File 'lib/yoda/store/objects/patch_set.rb', line 60

def delete(id)
  if patch = patches[id.to_sym]
    address_index.delete(patch)
  end
  patches.delete(id.to_sym)
end

#find(address) ⇒ Addressable?

Parameters:

  • address (String, Symbol)

Returns:



76
77
78
79
80
81
82
# File 'lib/yoda/store/objects/patch_set.rb', line 76

def find(address)
  if (patches = get_patches(address)).empty?
    nil
  else
    Merger.new(patches).merged_instance
  end
end

#has_key?(address) ⇒ true, false

Parameters:

  • address (String, Symbol)

Returns:

  • (true, false)


91
92
93
# File 'lib/yoda/store/objects/patch_set.rb', line 91

def has_key?(address)
  !address_index.get(address.to_sym).empty?
end

#keysArray<Symbol>

Returns:

  • (Array<Symbol>)


85
86
87
# File 'lib/yoda/store/objects/patch_set.rb', line 85

def keys
  address_index.keys.to_a
end

#patch(object) ⇒ Addressable

Parameters:

Returns:



69
70
71
72
# File 'lib/yoda/store/objects/patch_set.rb', line 69

def patch(object)
  objects_in_patch = get_patches(object.address)
  Merger.new([object, *objects_in_patch]).merged_instance
end

#register(patch) ⇒ void

This method returns an undefined value.

Parameters:



54
55
56
57
# File 'lib/yoda/store/objects/patch_set.rb', line 54

def register(patch)
  address_index.register(patch)
  patches[patch.id.to_sym] = patch
end