Class: Yoda::Store::Objects::Patch

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

Defined Under Namespace

Classes: ParentModifier

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, contents = nil) ⇒ Patch

Returns a new instance of Patch.

Parameters:



13
14
15
16
# File 'lib/yoda/store/objects/patch.rb', line 13

def initialize(id, contents = nil)
  @id = id
  @registry = (contents || []).map { |content| [content.address.to_sym, content] }.to_h
end

Instance Attribute Details

#idObject (readonly)

Parameters:

  • id (String)


6
7
8
# File 'lib/yoda/store/objects/patch.rb', line 6

def id
  @id
end

#registryObject (readonly)

Parameters:



9
10
11
# File 'lib/yoda/store/objects/patch.rb', line 9

def registry
  @registry
end

Instance Method Details

#find(address) ⇒ Addressable? Also known as: get

Parameters:

  • address (String, Symbol)

Returns:



20
21
22
# File 'lib/yoda/store/objects/patch.rb', line 20

def find(address, **)
  @registry[address.to_sym]
end

#has_key?(address) ⇒ true, false

Parameters:

  • address (String, Symbol)

Returns:

  • (true, false)


27
28
29
# File 'lib/yoda/store/objects/patch.rb', line 27

def has_key?(address)
  @registry.has_key?(address.to_sym)
end

#keysArray<Symbol>

Returns:

  • (Array<Symbol>)


32
33
34
# File 'lib/yoda/store/objects/patch.rb', line 32

def keys
  @registry.keys
end

#register(addressable) ⇒ void

This method returns an undefined value.

Parameters:



38
39
40
41
42
43
44
45
46
# File 'lib/yoda/store/objects/patch.rb', line 38

def register(addressable)
  parent_modifier.add_address_to_parent(addressable)

  if el = @registry[addressable.address.to_sym]
    @registry[addressable.address.to_sym] = el.merge(addressable)
  else
    @registry[addressable.address.to_sym] = addressable
  end
end