Class: Geet::Utils::AttributesSelectionManager

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
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: $stdout) ⇒ AttributesSelectionManager

Returns a new instance of AttributesSelectionManager.



29
30
31
32
33
# File 'lib/geet/utils/attributes_selection_manager.rb', line 29

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

Class Attribute Details

.serialize_requestsObject

Returns the value of attribute serialize_requests.



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

def serialize_requests
  @serialize_requests
end

Instance Method Details

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



48
49
50
51
52
53
54
# File 'lib/geet/utils/attributes_selection_manager.rb', line 48

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



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/geet/utils/attributes_selection_manager.rb', line 59

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