Class: Geet::Utils::AttributesSelectionManager
- Inherits:
-
Object
- Object
- Geet::Utils::AttributesSelectionManager
- Includes:
- Shared::Constants
- 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::Constants
Shared::Constants::MANUAL_LIST_SELECTION_FLAG
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.
21 22 23 24 25 |
# File 'lib/geet/utils/attributes_selection_manager.rb', line 21 def initialize(repository, out: output) @repository = repository @out = out @selections_data = [] end |
Instance Method Details
#add_attribute(repository_call, description, pattern, selection_type, name_method: nil, &pre_selection_hook) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/geet/utils/attributes_selection_manager.rb', line 27 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.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/geet/utils/attributes_selection_manager.rb', line 37 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 |