Class: Expressir::Model::Indexes::EntityIndex
- Inherits:
-
Object
- Object
- Expressir::Model::Indexes::EntityIndex
- Defined in:
- lib/expressir/model/indexes/entity_index.rb
Overview
Index for fast entity lookup across schemas Maintains indexes by qualified name and by schema for efficient querying
Instance Attribute Summary collapse
-
#by_qualified_name ⇒ Object
readonly
Returns the value of attribute by_qualified_name.
-
#by_schema ⇒ Object
readonly
Returns the value of attribute by_schema.
Instance Method Summary collapse
-
#build(schemas) ⇒ void
Build indexes from schemas.
-
#count ⇒ Integer
Count total entities.
-
#empty? ⇒ Boolean
Check if index is empty.
-
#find(qualified_name) ⇒ Declarations::Entity?
Find entity by qualified name.
-
#initialize(schemas = []) ⇒ EntityIndex
constructor
Initialize a new entity index.
-
#list(schema: nil) ⇒ Array<Declarations::Entity>
List all entities.
-
#schema_entities(schema) ⇒ Hash<String, Declarations::Entity>
Get entities for a specific schema.
Constructor Details
#initialize(schemas = []) ⇒ EntityIndex
Initialize a new entity index
13 14 15 16 17 |
# File 'lib/expressir/model/indexes/entity_index.rb', line 13 def initialize(schemas = []) @by_schema = {} @by_qualified_name = {} build(schemas) unless schemas.empty? end |
Instance Attribute Details
#by_qualified_name ⇒ Object (readonly)
Returns the value of attribute by_qualified_name.
9 10 11 |
# File 'lib/expressir/model/indexes/entity_index.rb', line 9 def by_qualified_name @by_qualified_name end |
#by_schema ⇒ Object (readonly)
Returns the value of attribute by_schema.
9 10 11 |
# File 'lib/expressir/model/indexes/entity_index.rb', line 9 def by_schema @by_schema end |
Instance Method Details
#build(schemas) ⇒ void
This method returns an undefined value.
Build indexes from schemas
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/expressir/model/indexes/entity_index.rb', line 22 def build(schemas) @by_schema = {} @by_qualified_name = {} schemas.each do |schema| schema_id = schema.id.safe_downcase @by_schema[schema_id] = {} next unless schema.entities schema.entities.each do |entity| entity_id = entity.id.safe_downcase qualified_name = "#{schema_id}.#{entity_id}" @by_schema[schema_id][entity_id] = entity @by_qualified_name[qualified_name] = entity end end end |
#count ⇒ Integer
Count total entities
90 91 92 |
# File 'lib/expressir/model/indexes/entity_index.rb', line 90 def count @by_qualified_name.size end |
#empty? ⇒ Boolean
Check if index is empty
84 85 86 |
# File 'lib/expressir/model/indexes/entity_index.rb', line 84 def empty? @by_qualified_name.empty? end |
#find(qualified_name) ⇒ Declarations::Entity?
Find entity by qualified name
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/expressir/model/indexes/entity_index.rb', line 45 def find(qualified_name) return nil if qualified_name.nil? || qualified_name.empty? normalized_name = qualified_name.safe_downcase # Try qualified name first entity = @by_qualified_name[normalized_name] return entity if entity # Try as simple name across all schemas schema_name, entity_name = normalized_name.split(".", 2) if entity_name.nil? # Search all schemas for simple name @by_schema.each_value do |entities| entity = entities[schema_name] return entity if entity end else # Look in specific schema schema_entities = @by_schema[schema_name] return schema_entities[entity_name] if schema_entities end nil end |
#list(schema: nil) ⇒ Array<Declarations::Entity>
List all entities
74 75 76 77 78 79 80 |
# File 'lib/expressir/model/indexes/entity_index.rb', line 74 def list(schema: nil) if schema @by_schema[schema.safe_downcase]&.values || [] else @by_qualified_name.values end end |
#schema_entities(schema) ⇒ Hash<String, Declarations::Entity>
Get entities for a specific schema
97 98 99 |
# File 'lib/expressir/model/indexes/entity_index.rb', line 97 def schema_entities(schema) @by_schema[schema.safe_downcase] || {} end |