Class: Autoselect::Level
- Inherits:
-
Object
- Object
- Autoselect::Level
- Defined in:
- lib/autoselect/level.rb
Overview
lib/autoselect/level.rb
Base class for all autoselect levels. Each level is a named, independent search strategy. Levels do not fork; they are executed sequentially by the Autoselect base class when their predecessor returns empty results (the fuse mechanic).
Rendering responsibility:
Internal levels use the default record_* methods, which delegate to
per-model helpers in app/helpers/ (e.g. taxon_name_autoselect_tag).
External levels override record_* directly — they must not rely on the
helper pattern because their records are POJOs, not AR instances.
Direct Known Subclasses
Autoselect::Levels::Smart, Otu::Levels::CatalogueOfLife, Otu::Levels::Fast, TaxonName::Levels::CatalogueOfLife, TaxonName::Levels::Fast
Constant Summary collapse
- DEFAULT_FUSE_MS =
600- EXTERNAL_FUSE_MS =
2000- MINIMUM_RESULTS =
escalate when result count < this value
1
Instance Method Summary collapse
-
#call(term:, operator: nil, project_id: nil, user_id: nil, **kwargs) ⇒ Array
Execute the level search.
-
#description ⇒ String
Description shown in help overlay.
-
#external? ⇒ Boolean
True when this level calls outside the database.
-
#fuse_ms ⇒ Integer
Milliseconds for the fuse animation before auto-escalating.
-
#key ⇒ Symbol
Unique identifier for this level, e.g.
-
#label ⇒ String
Human-readable label.
-
#metadata ⇒ Hash
The metadata representation included in config responses.
-
#minimum_results ⇒ Integer
Minimum results to suppress escalation.
-
#model_key ⇒ Object
private
Derives the snake_case model name from the level's class namespace.
-
#record_info(record) ⇒ Object
Array of disambiguation strings shown right-justified in the dropdown row.
-
#record_info_html(record) ⇒ Object
HTML string joining record_info with .
-
#record_label(record) ⇒ Object
Plain-text label shown in the input after selection (no HTML).
-
#record_label_html(record) ⇒ Object
HTML label shown left-justified in the dropdown row.
Instance Method Details
#call(term:, operator: nil, project_id: nil, user_id: nil, **kwargs) ⇒ Array
Execute the level search.
57 58 59 |
# File 'lib/autoselect/level.rb', line 57 def call(term:, operator: nil, project_id: nil, user_id: nil, **kwargs) raise NotImplementedError, "#{self.class} must implement #call" end |
#description ⇒ String
Returns description shown in help overlay.
31 32 33 |
# File 'lib/autoselect/level.rb', line 31 def description raise NotImplementedError, "#{self.class} must implement #description" end |
#external? ⇒ Boolean
Returns true when this level calls outside the database.
36 37 38 |
# File 'lib/autoselect/level.rb', line 36 def external? false end |
#fuse_ms ⇒ Integer
Returns milliseconds for the fuse animation before auto-escalating.
41 42 43 |
# File 'lib/autoselect/level.rb', line 41 def fuse_ms external? ? EXTERNAL_FUSE_MS : DEFAULT_FUSE_MS end |
#key ⇒ Symbol
Returns unique identifier for this level, e.g. :fast, :smart.
21 22 23 |
# File 'lib/autoselect/level.rb', line 21 def key raise NotImplementedError, "#{self.class} must implement #key" end |
#label ⇒ String
Returns human-readable label.
26 27 28 |
# File 'lib/autoselect/level.rb', line 26 def label raise NotImplementedError, "#{self.class} must implement #label" end |
#metadata ⇒ Hash
Returns the metadata representation included in config responses.
62 63 64 65 66 67 68 69 70 |
# File 'lib/autoselect/level.rb', line 62 def { key: key.to_s, label:, description:, external: external?, fuse_ms: } end |
#minimum_results ⇒ Integer
Returns minimum results to suppress escalation.
46 47 48 |
# File 'lib/autoselect/level.rb', line 46 def minimum_results MINIMUM_RESULTS end |
#model_key ⇒ Object (private)
Derives the snake_case model name from the level's class namespace. Autoselect::TaxonName::Levels::Fast → 'taxon_name'
111 112 113 |
# File 'lib/autoselect/level.rb', line 111 def model_key self.class.name.split('::')[-3].underscore end |
#record_info(record) ⇒ Object
Array of disambiguation strings shown right-justified in the dropdown row.
Delegates to
95 96 97 98 99 100 |
# File 'lib/autoselect/level.rb', line 95 def record_info(record) h = ApplicationController.helpers helper = "#{model_key}_autoselect_info" return h.send(helper, record) if h.respond_to?(helper) [] end |
#record_info_html(record) ⇒ Object
HTML string joining record_info with
103 104 105 |
# File 'lib/autoselect/level.rb', line 103 def record_info_html(record) record_info(record).compact.join(' ') end |
#record_label(record) ⇒ Object
Plain-text label shown in the input after selection (no HTML).
Delegates to label_for_
75 76 77 78 79 80 |
# File 'lib/autoselect/level.rb', line 75 def record_label(record) h = ApplicationController.helpers helper = "label_for_#{model_key}" return h.send(helper, record).to_s if h.respond_to?(helper) record.to_s end |
#record_label_html(record) ⇒ Object
HTML label shown left-justified in the dropdown row.
Delegates to
85 86 87 88 89 90 |
# File 'lib/autoselect/level.rb', line 85 def record_label_html(record) h = ApplicationController.helpers helper = "#{model_key}_autoselect_tag" return h.send(helper, record).to_s if h.respond_to?(helper) record_label(record) end |