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, Shared::Selection::SELECTION_MULTIPLE, Shared::Selection::SELECTION_SINGLE, Shared::Selection::SKIP_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
selection_type: SELECTION_SINGLE or SELECTION_MULTIPLE.
-
#initialize(repository, out: $stdout) ⇒ 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: $stdout) ⇒ 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: $stdout) @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
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_attributes ⇒ Object
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 |