Module: Reporting
- Defined in:
- lib/mumuki/classroom/models/reporting.rb
Class Method Summary collapse
- .aggregate(collection, query, paginated_params, query_params, projection) ⇒ Object
- .build_pipeline(collection, query, paginated_params, query_params, projection) ⇒ Object
- .pipeline(query, sorting, ordering, searching, projection) ⇒ Object
Class Method Details
.aggregate(collection, query, paginated_params, query_params, projection) ⇒ Object
10 11 12 13 |
# File 'lib/mumuki/classroom/models/reporting.rb', line 10 def self.aggregate(collection, query, paginated_params, query_params, projection) pipeline = build_pipeline(collection, query, paginated_params, query_params, projection) collection.collection.aggregate pipeline end |
.build_pipeline(collection, query, paginated_params, query_params, projection) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/mumuki/classroom/models/reporting.rb', line 3 def self.build_pipeline(collection, query, paginated_params, query_params, projection) ordering = "#{Criteria.name}::#{paginated_params[:order_by].to_s.camelize}".constantize sorting = "#{Sorting.name}::#{collection.name.demodulize}::By#{paginated_params[:sort_by].to_s.camelize}".constantize searching = Searching.filter_for(collection, query_params) pipeline query, sorting, ordering, searching, projection end |
.pipeline(query, sorting, ordering, searching, projection) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/mumuki/classroom/models/reporting.rb', line 15 def self.pipeline(query, sorting, ordering, searching, projection) main_pipeline = [] main_pipeline << {'$match': query} main_pipeline.concat searching.pipeline main_pipeline.concat sorting.pipeline main_pipeline << {'$sort': sorting.order_by(ordering)} main_pipeline << {'$project': projection} end |