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
34 35 36 37 38 39 40 41 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 34 def initialize(repository) @repository = repository @conditions = [] @scope = nil @order = nil @limit = nil @includes = [] end |
Instance Method Details
#all ⇒ Array
Alias for execute
169 170 171 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 169 def all execute end |
#any? ⇒ Boolean
Check if any results exist
205 206 207 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 205 def any? execute.any? end |
#classes ⇒ QueryBuilder
Start a class query
48 49 50 51 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 48 def classes @scope = :classes self end |
#count ⇒ Integer
Count the number of results
196 197 198 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 196 def count execute.size end |
#empty? ⇒ Boolean
Check if no results exist
214 215 216 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 214 def empty? execute.empty? end |
#execute ⇒ Array
Execute the query and return all results
155 156 157 158 159 160 161 162 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 155 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
178 179 180 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 178 def first limit(1).execute.first end |
#in_package(package_path, recursive: false) ⇒ QueryBuilder
Filter by package membership
107 108 109 110 111 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 107 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)
145 146 147 148 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 145 def includes(*relations) @includes.concat(relations) self end |
#last ⇒ Object?
Get the last result
187 188 189 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 187 def last execute.last end |
#limit(count) ⇒ QueryBuilder
Limit the number of results
134 135 136 137 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 134 def limit(count) @limit = count self end |
#order_by(field, direction: :asc) ⇒ QueryBuilder
Order results by a field
123 124 125 126 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 123 def order_by(field, direction: :asc) @order = Order.new(field, direction) self end |
#packages ⇒ QueryBuilder
Start a package query
58 59 60 61 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 58 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.
78 79 80 81 82 83 84 85 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 78 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
93 94 95 |
# File 'lib/lutaml/uml_repository/query_dsl/query_builder.rb', line 93 def with_stereotype(stereotype) where(stereotype: stereotype) end |