Class: Suma::SchemaIndex
- Inherits:
-
Object
- Object
- Suma::SchemaIndex
- Defined in:
- lib/suma/schema_index.rb
Overview
Pre-built index for O(1) schema and element lookup. Build once from a parsed repo, then query by name.
Instance Method Summary collapse
- #find_element(schema_name, element_name) ⇒ Object
- #find_schema(name) ⇒ Object
-
#initialize(repo) ⇒ SchemaIndex
constructor
A new instance of SchemaIndex.
Constructor Details
#initialize(repo) ⇒ SchemaIndex
Returns a new instance of SchemaIndex.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/suma/schema_index.rb', line 9 def initialize(repo) @schemas_by_name = {} @elements_by_schema = {} repo.schemas.each do |schema| key = schema.id.downcase @schemas_by_name[key] = schema @elements_by_schema[key] = build_element_index(schema) end end |
Instance Method Details
#find_element(schema_name, element_name) ⇒ Object
24 25 26 27 |
# File 'lib/suma/schema_index.rb', line 24 def find_element(schema_name, element_name) elements = @elements_by_schema[schema_name.downcase] elements&.[](element_name.downcase) end |
#find_schema(name) ⇒ Object
20 21 22 |
# File 'lib/suma/schema_index.rb', line 20 def find_schema(name) @schemas_by_name[name.downcase] end |