Class: Lutaml::UmlRepository::QueryDSL::QueryBuilder
- Inherits:
-
Object
- Object
- Lutaml::UmlRepository::QueryDSL::QueryBuilder
- Defined in:
- lib/lutaml/uml_repository/query_dsl/query_builder.rb
Overview
Fluent query builder for advanced queries against UML repositories
Provides a domain-specific language for building complex queries with method chaining, lazy evaluation, and composable filters.
Instance Method Summary collapse
-
#all ⇒ Array
Alias for execute.
-
#any? ⇒ Boolean
Check if any results exist.
-
#classes ⇒ QueryBuilder
Start a class query.
-
#count ⇒ Integer
Count the number of results.
-
#empty? ⇒ Boolean
Check if no results exist.
-
#execute ⇒ Array
Execute the query and return all results.
-
#first ⇒ Object?
Get the first result.
-
#in_package(package_path, recursive: false) ⇒ QueryBuilder
Filter by package membership.
-
#includes(*relations) ⇒ QueryBuilder
Specify related data to include (placeholder for future enhancement).
-
#initialize(repository) ⇒ QueryBuilder
constructor
Initialize a new query builder.
-
#last ⇒ Object?
Get the last result.
-
#limit(count) ⇒ QueryBuilder
Limit the number of results.
-
#order_by(field, direction: :asc) ⇒ QueryBuilder
Order results by a field.
-
#packages ⇒ QueryBuilder
Start a package query.
-
#where(conditions = nil, &block) ⇒ QueryBuilder
Add a condition to the query.
-
#with_stereotype(stereotype) ⇒ QueryBuilder
Filter by stereotype.
Constructor Details
#initialize(repository) ⇒ QueryBuilder
Initialize a new query builder
28 29 30 31 32 33 34 35 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 28 def initialize(repository) @repository = repository @conditions = [] @scope = nil @order = nil @limit = nil @includes = [] end |
Instance Method Details
#all ⇒ Array
Alias for execute
163 164 165 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 163 def all execute end |
#any? ⇒ Boolean
Check if any results exist
199 200 201 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 199 def any? execute.any? end |
#classes ⇒ QueryBuilder
Start a class query
42 43 44 45 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 42 def classes @scope = :classes self end |
#count ⇒ Integer
Count the number of results
190 191 192 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 190 def count execute.size end |
#empty? ⇒ Boolean
Check if no results exist
208 209 210 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 208 def empty? execute.empty? end |
#execute ⇒ Array
Execute the query and return all results
149 150 151 152 153 154 155 156 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 149 def execute results = fetch_base_results results = apply_conditions(results) results = apply_order(results) if @order results = apply_limit(results) if @limit results = apply_includes(results) if @includes.any? results end |
#first ⇒ Object?
Get the first result
172 173 174 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 172 def first limit(1).execute.first end |
#in_package(package_path, recursive: false) ⇒ QueryBuilder
Filter by package membership
101 102 103 104 105 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 101 def in_package(package_path, recursive: false) @conditions << Conditions::PackageCondition.new(package_path, recursive: recursive) self end |
#includes(*relations) ⇒ QueryBuilder
Specify related data to include (placeholder for future enhancement)
139 140 141 142 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 139 def includes(*relations) @includes.concat(relations) self end |
#last ⇒ Object?
Get the last result
181 182 183 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 181 def last execute.last end |
#limit(count) ⇒ QueryBuilder
Limit the number of results
128 129 130 131 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 128 def limit(count) @limit = count self end |
#order_by(field, direction: :asc) ⇒ QueryBuilder
Order results by a field
117 118 119 120 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 117 def order_by(field, direction: :asc) @order = Order.new(field, direction) self end |
#packages ⇒ QueryBuilder
Start a package query
52 53 54 55 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 52 def packages @scope = :packages self end |
#where(conditions = nil, &block) ⇒ QueryBuilder
Add a condition to the query
Supports both hash-based and block-based conditions.
72 73 74 75 76 77 78 79 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 72 def where(conditions = nil, &block) if conditions @conditions << Conditions::HashCondition.new(conditions) elsif block @conditions << Conditions::BlockCondition.new(&block) end self end |
#with_stereotype(stereotype) ⇒ QueryBuilder
Filter by stereotype
87 88 89 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 87 def with_stereotype(stereotype) where(stereotype: stereotype) end |