Class: Yoda::Store::Registry::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/yoda/store/registry/index.rb

Defined Under Namespace

Classes: ComposerWrapper

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content: {}, registry_ids: Set.new) ⇒ Index

Returns a new instance of Index.



73
74
75
76
# File 'lib/yoda/store/registry/index.rb', line 73

def initialize(content: {}, registry_ids: Set.new)
  @content = content
  @registry_ids = Set.new(registry_ids)
end

Instance Attribute Details

#contentHash (readonly)

Returns:

  • (Hash)


68
69
70
# File 'lib/yoda/store/registry/index.rb', line 68

def content
  @content
end

#registry_idsSet (readonly)

Returns:

  • (Set)


71
72
73
# File 'lib/yoda/store/registry/index.rb', line 71

def registry_ids
  @registry_ids
end

Instance Method Details

#add(address, registry_id) ⇒ Object

Parameters:

  • address (String, Symbol)
  • registry_id (String, Symbol)


89
90
91
92
93
# File 'lib/yoda/store/registry/index.rb', line 89

def add(address, registry_id)
  content[address.to_sym] ||= Objects::SerializableSet.new
  content[address.to_sym].add(registry_id.to_sym)
  content[address.to_sym].select! { |id| registry_ids.member?(id) }
end

#add_registry(registry) ⇒ Object



106
107
108
109
# File 'lib/yoda/store/registry/index.rb', line 106

def add_registry(registry)
  registry_ids.add(registry.id.to_sym)
  registry.keys.each { |key| add(key, registry.id) }
end

#get(address, registry_ids: nil) ⇒ IdMask

Return ids of registries which store an object with the address.

Parameters:

  • address (String, Symbol)
  • registry_ids (Array<String, Symbol>, IdMask, nil) (defaults to: nil)

Returns:



82
83
84
85
# File 'lib/yoda/store/registry/index.rb', line 82

def get(address, registry_ids: nil)
  raw_content = (content[address.to_sym] ||= Objects::SerializableSet.new)
  registry_ids ? (IdMask.build(registry_ids) & raw_content) : raw_content
end

#keysObject



102
103
104
# File 'lib/yoda/store/registry/index.rb', line 102

def keys
  Set.new(content.keys)
end

#remove(address, registry_id) ⇒ Object

Parameters:

  • address (String, Symbol)
  • registry_id (String, Symbol)


97
98
99
100
# File 'lib/yoda/store/registry/index.rb', line 97

def remove(address, registry_id)
  content[address.to_sym] ||= Objects::SerializableSet.new
  content[address.to_sym].delete(registry_id.to_sym)
end

#remove_registry(registry) ⇒ Object



111
112
113
# File 'lib/yoda/store/registry/index.rb', line 111

def remove_registry(registry)
  registry_ids.delete(registry.id.to_sym)
end

#wrap(composer) ⇒ Object



115
116
117
# File 'lib/yoda/store/registry/index.rb', line 115

def wrap(composer)
  ComposerWrapper.new(composer: composer, index: self)
end