Class: Geet::Utils::AttributesSelectionManager
- Inherits:
-
Object
- Object
- Geet::Utils::AttributesSelectionManager
- 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
Class Attribute Summary collapse
-
.serialize_requests ⇒ Object
Returns the value of attribute serialize_requests.
Instance Method Summary collapse
- #add_attribute(repository_call, description, pattern, selection_type, name_method: nil, &pre_selection_hook) ⇒ Object
-
#initialize(repository, out: output) ⇒ AttributesSelectionManager
constructor
Initialize the instance, and starts the background threads.
-
#select_attributes ⇒ Object
Select and return the attributes, in the same order they’ve been added.
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_requests ⇒ Object
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
33 34 35 36 37 38 39 |
# File 'lib/geet/utils/attributes_selection_manager.rb', line 33 def add_attribute(repository_call, description, pattern, selection_type, name_method: nil, &pre_selection_hook) raise "Unrecognized selection type #{selection_type.inspect}" if ![:single, :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_attributes ⇒ Object
Select and return the attributes, in the same order they’ve been added.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/geet/utils/attributes_selection_manager.rb', line 43 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 :single select_entry(description, entries, pattern, name_method) when :multiple select_entries(description, entries, pattern, name_method) end end end |