Class: Geet::Utils::AttributesSelectionManager

Inherits:
Object
  • Object
show all
Includes:
Shared::Selection
Defined in:
lib/geet/utils/attributes_selection_manager.rb

Overview

Manages the retrieval and selection of attributes.

Selecting an attribute happens in two steps: retrieval and selection.

With this structure, the retrieval happens in parallel, cutting the time considerably when multiple attributes are required (typically, three).

Constant Summary

Constants included from Shared::Selection

Shared::Selection::MANUAL_LIST_SELECTION_FLAG, Shared::Selection::SELECTION_MULTIPLE, Shared::Selection::SELECTION_SINGLE, Shared::Selection::SKIP_LIST_SELECTION_FLAG

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, out: output) ⇒ AttributesSelectionManager

Initialize the instance, and starts the background threads.



27
28
29
30
31
# File 'lib/geet/utils/attributes_selection_manager.rb', line 27

def initialize(repository, out: output)
  @repository = repository
  @out = out
  @selections_data = []
end

Class Attribute Details

.serialize_requestsObject

Returns the value of attribute serialize_requests.



22
23
24
# File 'lib/geet/utils/attributes_selection_manager.rb', line 22

def serialize_requests
  @serialize_requests
end

Instance Method Details

#add_attribute(repository_call, description, pattern, selection_type, name_method: nil, &pre_selection_hook) ⇒ Object

selection_type: SELECTION_SINGLE or SELECTION_MULTIPLE



35
36
37
38
39
40
41
# File 'lib/geet/utils/attributes_selection_manager.rb', line 35

def add_attribute(repository_call, description, pattern, selection_type, name_method: nil, &pre_selection_hook)
  raise "Unrecognized selection type #{selection_type.inspect}" if ![SELECTION_SINGLE, SELECTION_MULTIPLE].include?(selection_type)

  finder_thread = find_attribute_entries(repository_call)

  @selections_data << [finder_thread, description, pattern, selection_type, name_method, pre_selection_hook]
end

#select_attributesObject

Select and return the attributes, in the same order they’ve been added.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/geet/utils/attributes_selection_manager.rb', line 45

def select_attributes
  @selections_data.map do |finder_thread, description, pattern, selection_type, name_method, pre_selection_hook|
    entries = finder_thread.value

    entries = pre_selection_hook.(entries) if pre_selection_hook

    case selection_type
    when SELECTION_SINGLE
      select_entry(description, entries, pattern, name_method)
    when SELECTION_MULTIPLE
      select_entries(description, entries, pattern, name_method)
    end
  end
end