Class: Yoda::Store::Registry::LibraryRegistrySet

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

Constant Summary collapse

STATUS_KEY =
'%library_status'
PERSISTABLE_LIBRARY_STORE_INDEX_KEY =
'%persistable_library_store_index'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project:, adapter:, on_change: nil) ⇒ LibraryRegistrySet

Returns a new instance of LibraryRegistrySet.

Parameters:



21
22
23
24
25
26
# File 'lib/yoda/store/registry/library_registry_set.rb', line 21

def initialize(project:, adapter:, on_change: nil)
  fail TypeError, adapter unless adapter.is_a?(Adapters::Base)
  @project = project
  @adapter = adapter
  @on_change = on_change
end

Instance Attribute Details

#on_changeProc? (readonly)

Returns:

  • (Proc, nil)


16
17
18
# File 'lib/yoda/store/registry/library_registry_set.rb', line 16

def on_change
  @on_change
end

#projectProject (readonly)

Returns:



9
10
11
# File 'lib/yoda/store/registry/library_registry_set.rb', line 9

def project
  @project
end

Instance Method Details

#add(library) ⇒ Object

Parameters:

  • library (Library::Core, Library::Std, Library::Gem)


61
62
63
64
65
66
# File 'lib/yoda/store/registry/library_registry_set.rb', line 61

def add(library)
  library = library.with_project_connection(project: project)
  add_library_registry(library.registry)
  status.add_library(library)
  save
end

#modify(add:, remove:) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/yoda/store/registry/library_registry_set.rb', line 35

def modify(add:, remove:)
  add = add.map { |library| library.with_project_connection(project: project) }
  remove = remove.map { |library| library.with_project_connection(project: project) }

  remove.each do |library|
    if registry = library.registry
      persistable_library_store.remove_registry(registry)
      volatile_library_store.remove_registry(registry)
      status.remove_library(library)
    end
  end
  add.each do |library|
    if registry = library.registry
      if registry.persistable?
        persistable_library_store.add_registry(registry)
      else
        volatile_library_store.add_registry(registry)
      end
      status.add_library(library)
    end
  end
  on_change&.call
  save
end

#registryRegistry::Composer

Returns:



29
30
31
# File 'lib/yoda/store/registry/library_registry_set.rb', line 29

def registry
  Registry::Composer.new(id: :libraries, registries: [persistable_library_store, volatile_library_store])
end

#remove(library) ⇒ Object

Parameters:

  • library (Library::Core, Library::Std, Library::Gem)


69
70
71
72
73
74
# File 'lib/yoda/store/registry/library_registry_set.rb', line 69

def remove(library)
  library = library.with_project_connection(project: project)
  remove_library_registry(library.registry)
  status.remove_library(library)
  save
end

#saveObject



81
82
83
84
# File 'lib/yoda/store/registry/library_registry_set.rb', line 81

def save
  persistable_library_store_index_content.save
  adapter.put(STATUS_KEY, status)
end

#statusObjects::LibrariesStatus::Connected



77
78
79
# File 'lib/yoda/store/registry/library_registry_set.rb', line 77

def status
  @status ||= (adapter.get(STATUS_KEY) || Objects::LibrariesStatus.new).with_project_connection(project: project)
end